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