]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
nix: fix $patch suffix by including localNixpkgsPatches
[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 = "053md69ryybj27cp0xdfrza48zyzpblk6wvb2m2dbs9hm0gmcwc4";
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 ];
50 localNixpkgsPatches = [
51 patches/direnv.diff
52 ];
53 nixpkgs = originPkgs.stdenv.mkDerivation {
54 name = "nixpkgs-patched";
55 src = originNixpkgs;
56 phases = [ "unpackPhase" "patchPhase" ];
57 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
58 postPatch = ''
59 set -x
60 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
61 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
62 sort | sha256sum | cut -c -7)
63 mv $PWD $out
64 echo "+patch-$patch" >$out/.version-suffix
65 '';
66 };
67 pkgs = import nixpkgs {
68 config = {}; # Make the config pure, ignoring user's config.
69 overlays = import ./overlays.nix;
70 };
71
72 lib = pkgs.lib;
73 nixos = pkgs.nixos {};
74 # Configuration of shell/modules/
75 configuration = {config, ...}: {
76 imports = [
77 ];
78 nix = {
79 nixConf = ''
80 auto-optimise-store = true
81 '';
82 };
83 nix-plugins = {
84 enable = true;
85 };
86 gnupg = {
87 enable = true;
88 gnupgHome = toString ../sec/gnupg;
89 keys = import shell/openpgp.nix;
90 gpgExtraConf = ''
91 # julm@sourcephile.fr
92 trusted-key 0xB2450D97085B7B8C
93 '';
94 };
95 openssl = {
96 enable = true;
97 opensslHome = toString ../sec/openssl;
98 certificates = import shell/x509.nix;
99 };
100 openssh = {
101 # WARNING: nixops uses its own ssh, not this one.
102 enable = true;
103 sshConf = ''
104 Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
105 Compression no
106 #CompressionLevel 4
107 ControlMaster auto
108 ControlPath ${builtins.toString ../sec/ssh}/ssh-%h-%p-%r.socket
109 HashKnownHosts no
110 #SSAPIAuthentication no
111 SendEnv LANG LC_*
112 StrictHostKeyChecking yes
113 UserKnownHostsFile ${builtins.toString ../sec/ssh/known_hosts}
114 '';
115 };
116 virtualbox = {
117 enable = true;
118 };
119 };
120
121 # Using modules enables to separate specific configurations
122 # from reusable code in shell/modules.nix and shell/modules/
123 # which may find its way in another git repository one day.
124 modules =
125 (import shell/modules.nix {
126 inherit pkgs lib;
127 modules = [ configuration ];
128 }).config;
129
130 # Utility to query the Nix files like nixops show-option
131 # but without requiring a nixops database, and not limited to config entries.
132 pwd = toString (./. + "");
133 sourcephile-nix-get = pkgs.writeShellScriptBin "sourcephile-nix-get" ''
134 nix-instantiate --read-write-mode \
135 --arg networkExprs "[${pwd}/servers.nix ${pwd}/servers/production.nix]" \
136 --arg args '{}' --argstr "uuid" whatever \
137 --argstr deploymentName production "<nixops/eval-machine-info.nix>" \
138 --eval-only --strict --arg checkConfigurationOptions false -A "$@"
139 '';
140 sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-tmp" ''
141 # Cleanup "../sec/tmp/"
142 # This is done when entering the nix-shell
143 # because direnv already hooks trap EXIT.
144 cd "${pwd}"
145 test ! -e sec/tmp || {
146 find sec/tmp -type f -exec shred -fu {} +
147 rm -rf sec/tmp
148 }
149 '';
150 in
151 pkgs.mkShell {
152 name = "sourcephile-nix";
153 src = null;
154 #preferLocalBuild = true;
155 #allowSubstitutes = false;
156 buildInputs = modules.nix-shell.buildInputs ++ [
157 sourcephile-nix-get
158 sourcephile-shred-tmp
159 nixos.nixos-generate-config
160 nixos.nixos-install
161 nixos.nixos-enter
162 #pkgs.binutils
163 pkgs.coreutils
164 pkgs.cryptsetup
165 pkgs.curl
166 #pkgs.direnv
167 pkgs.dnsutils
168 #pkgs.dropbear
169 pkgs.e2fsprogs
170 pkgs.git
171 pkgs.glibcLocales
172 pkgs.gnumake
173 pkgs.gnupg
174 pkgs.htop
175 #pkgs.inetutils
176 pkgs.ipcalc
177 #pkgs.iputils
178 pkgs.less
179 pkgs.libfaketime
180 pkgs.ldns
181 #pkgs.ldns.examples
182 #pkgs.mailutils
183 pkgs.man
184 pkgs.mdadm
185 pkgs.gptfdisk
186 pkgs.ncdu
187 pkgs.ncurses
188 pkgs.nixops
189 #pkgs.openssl
190 pkgs.pass
191 pkgs.procps
192 pkgs.rsync
193 #pkgs.rxvt_unicode.terminfo
194 #pkgs.sqlite
195 pkgs.sqlite
196 #pkgs.sudo
197 pkgs.tig
198 pkgs.time
199 #pkgs.tmux
200 pkgs.tree
201 pkgs.utillinux
202 #pkgs.vim
203 #pkgs.virtualbox
204 pkgs.which
205 pkgs.xdg_utils
206 pkgs.zfs
207 pkgs.fio
208 pkgs.strace
209 pkgs.utillinux
210 #pkgs.zfstools
211 ];
212 #enableParallelBuilding = true;
213 shellHook = ''
214 echo >&2 "nix: running shellHook"
215
216 # Nix
217 PATH=$NIX_SHELL_PATH:$PATH
218 export NIX_PATH="nixpkgs=${toString pkgs.path}:nixpkgs-overlays="$PWD"/overlays:nixops=${toString pkgs.nixops}/share/nix/nixops"
219
220 # Since the .envrc calls this shellHook
221 # the EXIT trap cannot be freely used
222 # because it's already used by direnv,
223 # hence shred at startup, which is not ideal.
224 sourcephile-shred-tmp
225
226 ${modules.nix-shell.shellHook}
227
228 # password-store
229 export PASSWORD_STORE_DIR="$PWD"/../sec/pass
230
231 # gpg
232 export GPG_TTY=$(tty)
233 gpg-connect-agent updatestartuptty /bye >/dev/null
234
235 # nixops
236 #export NIXOPS_DEPLOYMENT="staging"
237 export MERMET_DEPLOYMENT=production
238 export LOSURDO_DEPLOYMENT=production
239 export NIXOPS_STATE="$PWD"/../sec/nixops/state.nixops
240 NIXOPS_OPTS+=" --show-trace"
241 export NIXOPS_OPTS
242
243 # disnix
244 #export DISNIXOS_USE_NIXOPS=1
245 #export DISNIX_CLIENT_INTERFACE=disnix-nixops-client
246 #export DISNIX_PROFILE=default
247 #export DISNIX_TARGET_PROPERTY=hostname
248 #export DYSNOMIA_STATEDIR="$PWD"/../sec/dysnomia
249 '';
250 }