]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
nginx: covid19: fix access_log
[sourcephile-nix.git] / shell.nix
1 let
2 nixpkgs_channel = builtins.getEnv "nixpkgs_channel";
3 originNixpkgs = import (.config/nixpkgs-channel + ("/" + nixpkgs_channel + ".nix"));
4 originPkgs = import originNixpkgs {
5 config = {}; # Make the config pure, ignoring user's config.
6 overlays = [];
7 };
8 remoteNixpkgsPatches = [
9 /*
10 { meta.description = "nsd : use types.lines where appropriate";
11 url = "https://github.com/NixOS/nixpkgs/pull/78968.diff";
12 sha256 = "11bqq1g1ax6i7xghihyhklmqpsq3njalardp6nvzphkjgxrypb47";
13 }
14 { meta.description = "shorewall: init at 5.2.3.3";
15 url = "https://github.com/NixOS/nixpkgs/pull/46131.diff";
16 sha256 = "0mfzlcr23ni5spnwksmmls50sw10alqbr5j6hjrwp9i30z0419yx";
17 }
18 */
19 { meta.description = "Dovecot plugin for Full Text Search (FTS) with Xapian";
20 url = "https://github.com/NixOS/nixpkgs/pull/78780.diff";
21 sha256 = "15ix8kwisjcgf4n7x7vlh223rb3206lcd5b13wbcvld07rzinjkc";
22 }
23 /* Disabled because it triggers the local build of too many reverse-dependencies
24 { meta.description = "openldap: enable sha2 and pbkdf2 modules";
25 url = "https://github.com/NixOS/nixpkgs/pull/79286.diff";
26 sha256 = "0y255x74qksqy7fm4bdwlknhm3s55vgfgbv4dd7580p4lcavya0m";
27 }
28 */
29 /*
30 { meta.description = "Replace simp-le with lego and support DNS-01 challenge";
31 url = "https://github.com/NixOS/nixpkgs/pull/77578.diff";
32 sha256 = "15zs2146zh54jg1gywrcwyqxpx7izc35vlakk3cvrlqwwsvlr2rf";
33 }
34 */
35 { meta.description = "dstat: fix pluginpath";
36 url = "https://github.com/NixOS/nixpkgs/pull/80151.diff";
37 sha256 = "0jjw2gvp7b7v2n2m2d6yj0gw711j6p9lyjf5ywp2y9ql6905qf4b";
38 }
39 /*
40 { meta.description = "shorewall: fix warnings due to types.loaOf being deprecated";
41 url = "https://github.com/NixOS/nixpkgs/pull/80154.diff";
42 sha256 = "0b216m1rib3jl6s3r5cbkd5h1bfhppikg4cz9ayr1fspsflr3bci";
43 }
44 { meta.description = "shorewall: fix RestartTriggers";
45 url = "https://github.com/NixOS/nixpkgs/pull/81774.diff";
46 sha256 = "14drpym2mq9gq505psjzqq23gv0wkbwrrvh438h5jirzcym3467a";
47 }
48 */
49 { meta.description = "syncoid: fix PATH to let it use sudo";
50 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
51 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
52 }
53 { meta.description = "sanoid: fix sanoid.conf generation";
54 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
55 sha256 = "1prmlw7kxj076vn52hkhx3jzxrvz84kbhsc7z2z55p5nqhi6pi36";
56 }
57 ];
58 localNixpkgsPatches = [
59 patches/direnv.diff
60 ];
61 nixpkgs = originPkgs.applyPatches {
62 name = "nixpkgs-patched";
63 src = originNixpkgs;
64 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
65 postPatch = ''
66 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
67 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
68 sort | sha256sum | cut -c -7)
69 echo "+patch-$patch" >.version-suffix
70 '';
71 };
72 pkgs = import nixpkgs {
73 config = {}; # Make the config pure, ignoring user's config.
74 overlays = import ./overlays.nix;
75 };
76
77 lib = pkgs.lib;
78 nixos = pkgs.nixos {};
79 # Configuration of shell/modules/
80 configuration = {config, ...}: {
81 imports = [
82 ];
83 nix = {
84 nixConf = ''
85 auto-optimise-store = true
86 '';
87 };
88 nix-plugins = {
89 enable = true;
90 };
91 gnupg = {
92 enable = true;
93 gnupgHome = toString ../sec/gnupg;
94 keys = import shell/openpgp.nix;
95 gpgExtraConf = ''
96 # julm@sourcephile.fr
97 trusted-key 0xB2450D97085B7B8C
98 '';
99 };
100 openssl = {
101 enable = true;
102 opensslHome = toString ../sec/openssl;
103 certificates = import shell/x509.nix;
104 };
105 openssh = {
106 # WARNING: nixops uses its own ssh, not this one.
107 enable = true;
108 sshConf = ''
109 Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
110 Compression no
111 #CompressionLevel 4
112 ControlMaster auto
113 ControlPath ${builtins.toString ../sec/ssh}/ssh-%h-%p-%r.socket
114 HashKnownHosts no
115 #SSAPIAuthentication no
116 SendEnv LANG LC_*
117 StrictHostKeyChecking yes
118 UserKnownHostsFile ${builtins.toString ../sec/ssh/known_hosts}
119 '';
120 };
121 virtualbox = {
122 enable = true;
123 };
124 };
125
126 # Using modules enables to separate specific configurations
127 # from reusable code in shell/modules.nix and shell/modules/
128 # which may find its way in another git repository one day.
129 modules =
130 (import shell/modules.nix {
131 inherit pkgs lib;
132 modules = [ configuration ];
133 }).config;
134
135 # Utility to query the Nix files like nixops show-option
136 # but without requiring a nixops database, and not limited to config entries.
137 pwd = toString (./. + "");
138 sourcephile-nix-get = pkgs.writeShellScriptBin "sourcephile-nix-get" ''
139 nix-instantiate --read-write-mode \
140 --arg networkExprs "[${pwd}/servers.nix ${pwd}/servers/production.nix]" \
141 --arg args '{}' --argstr "uuid" whatever \
142 --argstr deploymentName production "<nixops/eval-machine-info.nix>" \
143 --eval-only --strict --arg checkConfigurationOptions false -A "$@"
144 '';
145 sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-tmp" ''
146 # Cleanup "../sec/tmp/"
147 # This is done when entering the nix-shell
148 # because direnv already hooks trap EXIT.
149 cd "${pwd}"
150 test ! -e sec/tmp || {
151 find sec/tmp -type f -exec shred -fu {} +
152 rm -rf sec/tmp
153 }
154 '';
155 in
156 pkgs.mkShell {
157 name = "sourcephile-nix";
158 src = null;
159 #preferLocalBuild = true;
160 #allowSubstitutes = false;
161 buildInputs = modules.nix-shell.buildInputs ++ [
162 sourcephile-nix-get
163 sourcephile-shred-tmp
164 nixos.nixos-generate-config
165 nixos.nixos-install
166 nixos.nixos-enter
167 #pkgs.binutils
168 pkgs.coreutils
169 pkgs.cryptsetup
170 pkgs.curl
171 #pkgs.direnv
172 pkgs.dnsutils
173 #pkgs.dropbear
174 pkgs.e2fsprogs
175 pkgs.git
176 pkgs.glibcLocales
177 pkgs.gnumake
178 pkgs.gnupg
179 pkgs.htop
180 #pkgs.inetutils
181 pkgs.ipcalc
182 #pkgs.iputils
183 pkgs.less
184 pkgs.libfaketime
185 pkgs.ldns
186 #pkgs.ldns.examples
187 #pkgs.mailutils
188 pkgs.man
189 pkgs.mdadm
190 pkgs.gptfdisk
191 pkgs.ncdu
192 pkgs.ncurses
193 pkgs.nixops
194 #pkgs.openssl
195 pkgs.pass
196 pkgs.procps
197 pkgs.rsync
198 #pkgs.rxvt_unicode.terminfo
199 #pkgs.sqlite
200 pkgs.sqlite
201 #pkgs.sudo
202 pkgs.tig
203 pkgs.time
204 #pkgs.tmux
205 pkgs.tree
206 pkgs.utillinux
207 #pkgs.vim
208 #pkgs.virtualbox
209 pkgs.which
210 pkgs.xdg_utils
211 pkgs.zfs
212 pkgs.fio
213 pkgs.strace
214 pkgs.utillinux
215 #pkgs.zfstools
216 ];
217 #enableParallelBuilding = true;
218 shellHook = ''
219 echo >&2 "nix: running shellHook"
220
221 # Nix
222 PATH=$NIX_SHELL_PATH:$PATH
223 export NIX_PATH="nixpkgs=${toString pkgs.path}:nixpkgs-overlays="$PWD"/overlays:nixops=${toString pkgs.nixops}/share/nix/nixops"
224
225 # Since the .envrc calls this shellHook
226 # the EXIT trap cannot be freely used
227 # because it's already used by direnv,
228 # hence shred at startup, which is not ideal.
229 sourcephile-shred-tmp
230
231 ${modules.nix-shell.shellHook}
232
233 # password-store
234 export PASSWORD_STORE_DIR="$PWD"/../sec/pass
235
236 # gpg
237 export GPG_TTY=$(tty)
238 gpg-connect-agent updatestartuptty /bye >/dev/null
239
240 # nixops
241 #export NIXOPS_DEPLOYMENT="staging"
242 export MERMET_DEPLOYMENT=production
243 export LOSURDO_DEPLOYMENT=production
244 export NIXOPS_STATE="$PWD"/../sec/nixops/state.nixops
245 NIXOPS_OPTS+=" --show-trace"
246 export NIXOPS_OPTS
247
248 # disnix
249 #export DISNIXOS_USE_NIXOPS=1
250 #export DISNIX_CLIENT_INTERFACE=disnix-nixops-client
251 #export DISNIX_PROFILE=default
252 #export DISNIX_TARGET_PROPERTY=hostname
253 #export DYSNOMIA_STATEDIR="$PWD"/../sec/dysnomia
254 '';
255 }