]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
wireguard: setup intranet
[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.gnupg.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 gpgAgentExtraConf = ''
83 #pretend-request-origin remote
84 #extra-socket ${toString ./.}/S.gpg-agent.extra
85 #log-file ${toString ./.}/gpg-agent.log
86 #no-grab
87 #debug-level expert
88 #allow-loopback-pinentry
89 '';
90 };
91 openssl = {
92 enable = true;
93 opensslHome = toString ../sec/openssl;
94 certificates = import shell/x509.nix;
95 };
96 openssh = {
97 enable = true;
98 sshConf = ''
99 Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
100 Compression no
101 #CompressionLevel 4
102 ControlMaster auto
103 ControlPath ${toString ../sec/ssh}/ssh-%h-%p-%r.socket
104 HashKnownHosts no
105 #SSAPIAuthentication no
106 SendEnv LANG LC_*
107 StrictHostKeyChecking yes
108 UserKnownHostsFile ${toString ../sec/ssh/known_hosts}
109 '';
110 };
111 virtualbox = {
112 enable = false;
113 };
114 };
115
116 # Using modules enables to separate specific configurations
117 # from reusable code in shell/modules.nix and shell/modules/
118 # which may find its way in another git repository one day.
119 shell = (pkgs.lib.evalModules {
120 modules = [ shellConfig ] ++ map import (pkgs.lib.findFiles ".*\\.nix" shell/modules);
121 args = { inherit pkgs; };
122 }).config;
123
124 pwd = toString (./. + "");
125 sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-tmp" ''
126 # This is done when entering the nix-shell
127 # because direnv already hooks trap EXIT.
128 cd "${pwd}"
129 test ! -e sec/tmp || {
130 find sec/tmp -type f -exec shred -fu {} +
131 rm -rf sec/tmp
132 }
133 '';
134 in
135 pkgs.mkShell {
136 name = "sourcephile-nix";
137 src = null;
138 #preferLocalBuild = true;
139 #allowSubstitutes = false;
140 buildInputs = shell.nix-shell.buildInputs ++ [
141 sourcephile-shred-tmp
142 (pkgs.nixos []).nixos-generate-config
143 (pkgs.nixos []).nixos-install
144 (pkgs.nixos []).nixos-enter
145 #pkgs.binutils
146 pkgs.coreutils
147 pkgs.cryptsetup
148 pkgs.curl
149 #pkgs.direnv
150 pkgs.dnsutils
151 #pkgs.dropbear
152 pkgs.e2fsprogs
153 pkgs.git
154 pkgs.glibcLocales
155 pkgs.gnumake
156 pkgs.gnupg
157 pkgs.htop
158 #pkgs.inetutils
159 pkgs.ipcalc
160 #pkgs.iputils
161 pkgs.less
162 pkgs.libfaketime
163 pkgs.ldns
164 #pkgs.ldns.examples
165 #pkgs.mailutils
166 pkgs.man
167 pkgs.mdadm
168 pkgs.gptfdisk
169 pkgs.ncdu
170 pkgs.ncurses
171 #pkgs.nixops
172 #pkgs.openssl
173 pkgs.pass
174 pkgs.procps
175 pkgs.rsync
176 #pkgs.rxvt_unicode.terminfo
177 #pkgs.sqlite
178 pkgs.sqlite
179 #pkgs.sudo
180 pkgs.tig
181 pkgs.time
182 #pkgs.tmux
183 pkgs.tree
184 pkgs.utillinux
185 #pkgs.vim
186 #pkgs.virtualbox
187 pkgs.which
188 pkgs.xdg_utils
189 pkgs.zfs
190 pkgs.fio
191 pkgs.strace
192 pkgs.utillinux
193 #pkgs.zfstools
194 pkgs.linuxPackages.perf
195 #pkgs.go2nix
196 pkgs.wireguard
197 ];
198 #enableParallelBuilding = true;
199 shellHook = ''
200 echo >&2 "nix: running shellHook"
201
202 # password-store
203 export PASSWORD_STORE_DIR="$PWD"/../sec/pass
204
205 # Nix
206 PATH=$NIX_SHELL_PATH:$PATH
207 export NIX_PATH="${pkgs.lib.concatStringsSep ":" [
208 "machines=$PWD/machines.nix"
209 #"pass=$PASSWORD_STORE_DIR"
210 "nixpkgs=${toString pkgs.path}"
211 "nixpkgs-overlays=$PWD/nixpkgs/overlays.nix"
212 ]}"
213
214 # Since the .envrc calls this shellHook
215 # the EXIT trap cannot be freely used
216 # because it's already used by direnv,
217 # hence shred at startup, which is not ideal.
218 sourcephile-shred-tmp
219
220 ${shell.nix-shell.shellHook}
221
222 # gpg
223 export GPG_TTY=$(tty)
224 gpg-connect-agent updatestartuptty /bye >/dev/null
225 '';
226 }