]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
nix: simplify the sending root's OpenPGP key
[sourcephile-nix.git] / shell.nix
1 let
2 nixpkgs_channel = builtins.getEnv "nixpkgs_channel";
3 # Bootstraping Nixpkgs to get tools to patch it.
4 originNixpkgs = import (.config/nixpkgs-channel + ("/${nixpkgs_channel}.nix"));
5 originPkgs = import originNixpkgs {
6 config = {}; # Make the config pure, ignoring user's config.
7 overlays = [];
8 };
9 remoteNixpkgsPatches = [
10 { meta.description = "dstat: fix pluginpath";
11 url = "https://github.com/NixOS/nixpkgs/pull/80151.diff";
12 sha256 = "0jjw2gvp7b7v2n2m2d6yj0gw711j6p9lyjf5ywp2y9ql6905qf4b";
13 }
14 { meta.description = "syncoid: fix PATH to let it use sudo";
15 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
16 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
17 }
18 { meta.description = "sanoid: fix sanoid.conf generation";
19 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
20 sha256 = "0lj4krmmbz82zpmbacw0qj2ywsx895bq4d1psjn753ymh7jjqj8k";
21 }
22 { meta.description = "nixos/public-inbox: init";
23 url = "https://github.com/NixOS/nixpkgs/pull/77450.diff";
24 sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd";
25 }
26 /*
27 { meta.description = "transmission: apply RFC0042 and harden the service";
28 url = "https://github.com/NixOS/nixpkgs/pull/92106.diff";
29 sha256 = "0h1105qy0wrirvi9fk5d00qsjvm745196vb7wgr648d56rm17vv1";
30 }
31 { meta.description = "apparmor: fix and improve the service";
32 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
33 sha256 = "0y1kvsnm8xiplbm4w4cadmfkr452vipswkz3kwyyikknh06vj3mn";
34 }
35 */
36 ];
37 localNixpkgsPatches = [
38 nixpkgs/patches/transmission+apparmor.diff
39 nixpkgs/patches/installer.ssh-nixos.diff
40 nixpkgs/patches/security.pass.diff
41 nixpkgs/patches/services.croc.diff
42 ];
43 # Build nixpkgs with some patches.
44 nixpkgs = originPkgs.applyPatches {
45 name = "nixpkgs-patched";
46 src = originNixpkgs;
47 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
48 postPatch = ''
49 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
50 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
51 sort | sha256sum | cut -c -7)
52 echo "+patch-$patch" >.version-suffix
53 '';
54 };
55 # Final pkgs with custom overlays.
56 pkgs = import nixpkgs {
57 config = {}; # Make the config pure, ignoring user's config.
58 overlays = import nixpkgs/overlays.nix;
59 };
60
61 # Configuration of shell/modules/
62 # to expand shellHook and buildInputs of this shell.nix
63 shellConfig = {config, ...}: {
64 imports = [
65 shell/gnupg.nix
66 ];
67 nix = {
68 nixConf = ''
69 auto-optimise-store = true
70 '';
71 };
72 nix-plugins = {
73 enable = true;
74 };
75 gnupg = {
76 enable = true;
77 gnupgHome = toString ../sec/gnupg;
78 gpgExtraConf = ''
79 # julm@sourcephile.fr
80 trusted-key 0xB2450D97085B7B8C
81 '';
82 };
83 openssl = {
84 enable = true;
85 opensslHome = toString ../sec/openssl;
86 certificates = import shell/x509.nix;
87 };
88 openssh = {
89 enable = true;
90 sshConf = ''
91 Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
92 Compression no
93 #CompressionLevel 4
94 ControlMaster auto
95 ControlPath ${toString ../sec/ssh}/ssh-%h-%p-%r.socket
96 HashKnownHosts no
97 #SSAPIAuthentication no
98 SendEnv LANG LC_*
99 StrictHostKeyChecking yes
100 UserKnownHostsFile ${toString ../sec/ssh/known_hosts}
101 '';
102 };
103 virtualbox = {
104 enable = false;
105 };
106 };
107
108 # Using modules enables to separate specific configurations
109 # from reusable code in shell/modules.nix and shell/modules/
110 # which may find its way in another git repository one day.
111 shell = (pkgs.lib.evalModules {
112 modules = [ shellConfig ] ++ map import (pkgs.lib.findFiles ".*\\.nix" shell/modules);
113 args = { inherit pkgs; };
114 }).config;
115
116 pwd = toString (./. + "");
117 sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-tmp" ''
118 # This is done when entering the nix-shell
119 # because direnv already hooks trap EXIT.
120 cd "${pwd}"
121 test ! -e sec/tmp || {
122 find sec/tmp -type f -exec shred -fu {} +
123 rm -rf sec/tmp
124 }
125 '';
126 in
127 pkgs.mkShell {
128 name = "sourcephile-nix";
129 src = null;
130 #preferLocalBuild = true;
131 #allowSubstitutes = false;
132 buildInputs = shell.nix-shell.buildInputs ++ [
133 sourcephile-shred-tmp
134 (pkgs.nixos []).nixos-generate-config
135 (pkgs.nixos []).nixos-install
136 (pkgs.nixos []).nixos-enter
137 #pkgs.binutils
138 pkgs.coreutils
139 pkgs.cryptsetup
140 pkgs.curl
141 #pkgs.direnv
142 pkgs.dnsutils
143 #pkgs.dropbear
144 pkgs.e2fsprogs
145 pkgs.git
146 pkgs.glibcLocales
147 pkgs.gnumake
148 pkgs.gnupg
149 pkgs.htop
150 #pkgs.inetutils
151 pkgs.ipcalc
152 #pkgs.iputils
153 pkgs.less
154 pkgs.libfaketime
155 pkgs.ldns
156 #pkgs.ldns.examples
157 #pkgs.mailutils
158 pkgs.man
159 pkgs.mdadm
160 pkgs.gptfdisk
161 pkgs.ncdu
162 pkgs.ncurses
163 #pkgs.nixops
164 #pkgs.openssl
165 pkgs.pass
166 pkgs.procps
167 pkgs.rsync
168 #pkgs.rxvt_unicode.terminfo
169 #pkgs.sqlite
170 pkgs.sqlite
171 #pkgs.sudo
172 pkgs.tig
173 pkgs.time
174 #pkgs.tmux
175 pkgs.tree
176 pkgs.utillinux
177 #pkgs.vim
178 #pkgs.virtualbox
179 pkgs.which
180 pkgs.xdg_utils
181 pkgs.zfs
182 pkgs.fio
183 pkgs.strace
184 pkgs.utillinux
185 #pkgs.zfstools
186 pkgs.linuxPackages.perf
187 ];
188 #enableParallelBuilding = true;
189 shellHook = ''
190 echo >&2 "nix: running shellHook"
191
192 # password-store
193 export PASSWORD_STORE_DIR="$PWD"/../sec/pass
194
195 # Nix
196 PATH=$NIX_SHELL_PATH:$PATH
197 export NIX_PATH="${pkgs.lib.concatStringsSep ":" [
198 "machines=$PWD/machines.nix"
199 #"pass=$PASSWORD_STORE_DIR"
200 "nixpkgs=${toString pkgs.path}"
201 "nixpkgs-overlays=$PWD/nixpkgs/overlays.nix"
202 ]}"
203
204 # Since the .envrc calls this shellHook
205 # the EXIT trap cannot be freely used
206 # because it's already used by direnv,
207 # hence shred at startup, which is not ideal.
208 sourcephile-shred-tmp
209
210 ${shell.nix-shell.shellHook}
211
212 # gpg
213 export GPG_TTY=$(tty)
214 gpg-connect-agent updatestartuptty /bye >/dev/null
215 '';
216 }