]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
nix: add tests.nix
[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 = "1h45qhbragp5ky6xix198qhadj1j7gd3qswa135mnmw1ijfczyry";
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 #patches/fts_xapian.diff
29 ];
30 nixpkgs = originPkgs.applyPatches {
31 name = "nixpkgs-patched";
32 src = originNixpkgs;
33 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
34 postPatch = ''
35 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
36 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
37 sort | sha256sum | cut -c -7)
38 echo "+patch-$patch" >.version-suffix
39 '';
40 };
41 pkgs = import nixpkgs {
42 config = {}; # Make the config pure, ignoring user's config.
43 overlays = import ./overlays.nix;
44 };
45
46 lib = pkgs.lib;
47 nixos = pkgs.nixos {};
48 # Configuration of shell/modules/
49 configuration = {config, ...}: {
50 imports = [
51 ];
52 nix = {
53 nixConf = ''
54 auto-optimise-store = true
55 '';
56 };
57 nix-plugins = {
58 enable = true;
59 };
60 gnupg = {
61 enable = true;
62 gnupgHome = toString ../sec/gnupg;
63 keys = import shell/openpgp.nix;
64 gpgExtraConf = ''
65 # julm@sourcephile.fr
66 trusted-key 0xB2450D97085B7B8C
67 '';
68 };
69 openssl = {
70 enable = true;
71 opensslHome = toString ../sec/openssl;
72 certificates = import shell/x509.nix;
73 };
74 openssh = {
75 # WARNING: nixops uses its own ssh, not this one.
76 enable = true;
77 sshConf = ''
78 Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
79 Compression no
80 #CompressionLevel 4
81 ControlMaster auto
82 ControlPath ${builtins.toString ../sec/ssh}/ssh-%h-%p-%r.socket
83 HashKnownHosts no
84 #SSAPIAuthentication no
85 SendEnv LANG LC_*
86 StrictHostKeyChecking yes
87 UserKnownHostsFile ${builtins.toString ../sec/ssh/known_hosts}
88 '';
89 };
90 virtualbox = {
91 enable = true;
92 };
93 };
94
95 # Using modules enables to separate specific configurations
96 # from reusable code in shell/modules.nix and shell/modules/
97 # which may find its way in another git repository one day.
98 modules =
99 (import shell/modules.nix {
100 inherit pkgs lib;
101 modules = [ configuration ];
102 }).config;
103
104 # Utility to query the Nix files like nixops show-option
105 # but without requiring a nixops database, and not limited to config entries.
106 pwd = toString (./. + "");
107 sourcephile-nix-get = pkgs.writeShellScriptBin "sourcephile-nix-get" ''
108 nix-instantiate --read-write-mode \
109 --arg networkExprs "[${pwd}/servers.nix ${pwd}/servers/production.nix]" \
110 --arg args '{}' --argstr "uuid" whatever \
111 --argstr deploymentName production "<nixops/eval-machine-info.nix>" \
112 --eval-only --strict --arg checkConfigurationOptions false -A "$@"
113 '';
114 sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-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.nix: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 }