]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
losurdo: remove dependency on nix-plugins
[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 { meta.description = "transmission: apply RFC0042 and harden the service";
27 url = "https://github.com/NixOS/nixpkgs/pull/92106.diff";
28 sha256 = "0d3dd511h7fw0k5q0k6wp7hcwkk7xikfwracp68f1y7hn4jj0pn0";
29 }
30 { meta.description = "apparmor: fix and improve the service";
31 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
32 sha256 = "1yhs0459r7mxdzl70l67yzbj6i67ps2znaca852hd1gffi650bkr";
33 }
34 { meta.description = "nixos/security.gnupg: provisioning GnuPG-protected secrets through the Nix store";
35 url = "https://github.com/NixOS/nixpkgs/pull/93659.diff";
36 sha256 = "08pmka7ryz2gbyc8by40p31ky7s3dqxlj90dnw7fmlgb4pb3pkn0";
37 }
38 { meta.description = "nixos/croc: init";
39 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
40 sha256 = "0fv3lpj244hvxyixxv4akrr70jv5wwbhb3kmbmd2yskx59a71rch";
41 }
42 { meta.description = "prosody-modules: update to revision 2dcbc01c9931";
43 url = "https://github.com/NixOS/nixpkgs/pull/94916.diff";
44 sha256 = "1cpdv5bd3837qh54yd0n6vvbfpn0p0cshkic5q0lv60lmm9raqk4";
45 }
46 { meta.description = "nixos/biboumi: init";
47 url = "https://github.com/NixOS/nixpkgs/pull/94917.diff";
48 sha256 = "1rjmmkx1pm08qi0d0bg6lr60jh8w1ifa8n4gnms4k6wka233yk0z";
49 }
50 { meta.description = "dovecot_fts_xapian: 1.3.1 -> 1.3.3";
51 url = "https://github.com/NixOS/nixpkgs/pull/94938.diff";
52 sha256 = "10bjwcwpvq7nnqdpz0n7c61kb3b27v1abyc80pki7d13jmzzjc04";
53 }
54 ];
55 localNixpkgsPatches = [
56 nixpkgs/patches/installer.ssh-nixos.diff
57 nixpkgs/patches/fix-flushBeforeStage2.diff
58 ];
59 # Build nixpkgs with some patches.
60 nixpkgs = originPkgs.applyPatches {
61 name = "nixpkgs-patched";
62 src = originNixpkgs;
63 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
64 postPatch = ''
65 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
66 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
67 sort | sha256sum | cut -c -7)
68 echo "+patch-$patch" >.version-suffix
69 '';
70 };
71 # Final pkgs with custom overlays.
72 pkgs = import nixpkgs {
73 config = {}; # Make the config pure, ignoring user's config.
74 overlays = import nixpkgs/overlays.nix;
75 };
76
77 # Configuration of shell/modules/
78 # to expand shellHook and buildInputs of this shell.nix
79 shellConfig = {config, ...}: {
80 imports = [
81 shell/gnupg.nix
82 ];
83 nix = {
84 nixConf = ''
85 auto-optimise-store = true
86 '';
87 };
88 gnupg = {
89 enable = true;
90 gnupgHome = toString ../sec/gnupg;
91 gpgExtraConf = ''
92 # julm@sourcephile.fr
93 trusted-key 0xB2450D97085B7B8C
94 '';
95 gpgAgentExtraConf = ''
96 #pretend-request-origin remote
97 #extra-socket ${toString ./.}/S.gpg-agent.extra
98 #log-file ${toString ./.}/gpg-agent.log
99 #no-grab
100 #debug-level expert
101 #allow-loopback-pinentry
102 '';
103 };
104 openssl = {
105 enable = true;
106 opensslHome = toString ../sec/openssl;
107 certificates = import shell/x509.nix;
108 };
109 openssh = {
110 enable = true;
111 sshConf = ''
112 Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
113 Compression no
114 #CompressionLevel 4
115 ControlMaster auto
116 ControlPath ${toString ../sec/ssh}/ssh-%h-%p-%r.socket
117 HashKnownHosts no
118 #SSAPIAuthentication no
119 SendEnv LANG LC_*
120 StrictHostKeyChecking yes
121 UserKnownHostsFile ${toString ../sec/ssh/known_hosts}
122 '';
123 };
124 virtualbox = {
125 enable = false;
126 };
127 };
128
129 # Using modules enables to separate specific configurations
130 # from reusable code in shell/modules.nix and shell/modules/
131 # which may find its way in another git repository one day.
132 shell = (pkgs.lib.evalModules {
133 modules = [ shellConfig ] ++ map import (pkgs.lib.findFiles ".*\\.nix" shell/modules);
134 args = { inherit pkgs; };
135 }).config;
136
137 pwd = toString (./. + "");
138 sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-tmp" ''
139 # This is done when entering the nix-shell
140 # because direnv already hooks trap EXIT.
141 cd "${pwd}"
142 test ! -e sec/tmp || {
143 find sec/tmp -type f -exec shred -fu {} +
144 rm -rf sec/tmp
145 }
146 '';
147 in
148 pkgs.mkShell {
149 name = "sourcephile-nix";
150 src = null;
151 #preferLocalBuild = true;
152 #allowSubstitutes = false;
153 buildInputs = shell.nix-shell.buildInputs ++ [
154 sourcephile-shred-tmp
155 (pkgs.nixos []).nixos-generate-config
156 (pkgs.nixos []).nixos-install
157 (pkgs.nixos []).nixos-enter
158 #pkgs.binutils
159 pkgs.coreutils
160 pkgs.cryptsetup
161 pkgs.curl
162 #pkgs.direnv
163 pkgs.dnsutils
164 #pkgs.dropbear
165 pkgs.e2fsprogs
166 pkgs.git
167 pkgs.glibcLocales
168 pkgs.gnumake
169 pkgs.gnupg
170 pkgs.htop
171 #pkgs.inetutils
172 pkgs.ipcalc
173 #pkgs.iputils
174 pkgs.less
175 pkgs.libfaketime
176 pkgs.ldns
177 #pkgs.ldns.examples
178 #pkgs.mailutils
179 pkgs.man
180 pkgs.mdadm
181 pkgs.gptfdisk
182 pkgs.ncdu
183 pkgs.ncurses
184 #pkgs.nixops
185 #pkgs.openssl
186 pkgs.pass
187 pkgs.procps
188 pkgs.rsync
189 #pkgs.rxvt_unicode.terminfo
190 #pkgs.sqlite
191 pkgs.sqlite
192 #pkgs.sudo
193 pkgs.tig
194 pkgs.time
195 #pkgs.tmux
196 pkgs.tree
197 pkgs.utillinux
198 #pkgs.vim
199 #pkgs.virtualbox
200 pkgs.which
201 pkgs.xdg_utils
202 pkgs.zfs
203 pkgs.fio
204 pkgs.strace
205 pkgs.utillinux
206 #pkgs.zfstools
207 pkgs.linuxPackages.perf
208 #pkgs.go2nix
209 pkgs.wireguard
210 pkgs.stun
211 pkgs.mkpasswd
212 ];
213 #enableParallelBuilding = true;
214 shellHook = ''
215 echo >&2 "nix: running shellHook"
216
217 # password-store
218 export PASSWORD_STORE_DIR="$PWD"/../sec/pass
219
220 # Nix
221 PATH=$NIX_SHELL_PATH:$PATH
222 export NIX_PATH="${pkgs.lib.concatStringsSep ":" [
223 "machines=$PWD/machines.nix"
224 #"pass=$PASSWORD_STORE_DIR"
225 "nixpkgs=${toString pkgs.path}"
226 "nixpkgs-overlays=$PWD/nixpkgs/overlays.nix"
227 ]}"
228
229 # Since the .envrc calls this shellHook
230 # the EXIT trap cannot be freely used
231 # because it's already used by direnv,
232 # hence shred at startup, which is not ideal.
233 sourcephile-shred-tmp
234
235 ${shell.nix-shell.shellHook}
236
237 # gpg
238 export GPG_TTY=$(tty)
239 gpg-connect-agent updatestartuptty /bye >/dev/null
240 '';
241 }