]> Git — Sourcephile - sourcephile-nix.git/blob - shell.nix
nix: servers.nix -> machines.nix
[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 #/home/julm/src/nix/nixpkgs/wip.patch
39 nixpkgs/patches/wip.diff
40 ];
41 # Build nixpkgs with some patches.
42 nixpkgs = originPkgs.applyPatches {
43 name = "nixpkgs-patched";
44 src = originNixpkgs;
45 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
46 postPatch = ''
47 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
48 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
49 sort | sha256sum | cut -c -7)
50 echo "+patch-$patch" >.version-suffix
51 '';
52 };
53 # Final pkgs with custom overlays.
54 pkgs = import nixpkgs {
55 config = {}; # Make the config pure, ignoring user's config.
56 overlays = import nixpkgs/overlays.nix;
57 };
58
59 lib = pkgs.lib;
60 nixos = pkgs.nixos {};
61 # Configuration of shell/modules/
62 # to expand shellHook and buildInputs of this shell.nix
63 configuration = {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 };
83 openssl = {
84 enable = true;
85 opensslHome = toString ../sec/openssl;
86 certificates = import shell/x509.nix;
87 };
88 openssh = {
89 enable = true;
90 sshConf = ''
91 Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr
92 Compression no
93 #CompressionLevel 4
94 ControlMaster auto
95 ControlPath ${toString ../sec/ssh}/ssh-%h-%p-%r.socket
96 HashKnownHosts no
97 #SSAPIAuthentication no
98 SendEnv LANG LC_*
99 StrictHostKeyChecking yes
100 UserKnownHostsFile ${toString ../sec/ssh/known_hosts}
101 '';
102 };
103 virtualbox = {
104 enable = false;
105 };
106 };
107
108 # Using modules enables to separate specific configurations
109 # from reusable code in shell/modules.nix and shell/modules/
110 # which may find its way in another git repository one day.
111 modules =
112 (import shell/modules.nix {
113 inherit pkgs lib;
114 modules = [ configuration ];
115 }).config;
116
117 pwd = toString (./. + "");
118 sourcephile-shred-tmp = pkgs.writeShellScriptBin "sourcephile-shred-tmp" ''
119 # This is done when entering the nix-shell
120 # because direnv already hooks trap EXIT.
121 cd "${pwd}"
122 test ! -e sec/tmp || {
123 find sec/tmp -type f -exec shred -fu {} +
124 rm -rf sec/tmp
125 }
126 '';
127 in
128 pkgs.mkShell {
129 name = "sourcephile-nix";
130 src = null;
131 #preferLocalBuild = true;
132 #allowSubstitutes = false;
133 buildInputs = modules.nix-shell.buildInputs ++ [
134 sourcephile-shred-tmp
135 nixos.nixos-generate-config
136 nixos.nixos-install
137 nixos.nixos-enter
138 #pkgs.binutils
139 pkgs.coreutils
140 pkgs.cryptsetup
141 pkgs.curl
142 #pkgs.direnv
143 pkgs.dnsutils
144 #pkgs.dropbear
145 pkgs.e2fsprogs
146 pkgs.git
147 pkgs.glibcLocales
148 pkgs.gnumake
149 pkgs.gnupg
150 pkgs.htop
151 #pkgs.inetutils
152 pkgs.ipcalc
153 #pkgs.iputils
154 pkgs.less
155 pkgs.libfaketime
156 pkgs.ldns
157 #pkgs.ldns.examples
158 #pkgs.mailutils
159 pkgs.man
160 pkgs.mdadm
161 pkgs.gptfdisk
162 pkgs.ncdu
163 pkgs.ncurses
164 #pkgs.nixops
165 #pkgs.openssl
166 pkgs.pass
167 pkgs.procps
168 pkgs.rsync
169 #pkgs.rxvt_unicode.terminfo
170 #pkgs.sqlite
171 pkgs.sqlite
172 #pkgs.sudo
173 pkgs.tig
174 pkgs.time
175 #pkgs.tmux
176 pkgs.tree
177 pkgs.utillinux
178 #pkgs.vim
179 #pkgs.virtualbox
180 pkgs.which
181 pkgs.xdg_utils
182 pkgs.zfs
183 pkgs.fio
184 pkgs.strace
185 pkgs.utillinux
186 #pkgs.zfstools
187 ];
188 #enableParallelBuilding = true;
189 shellHook = ''
190 echo >&2 "nix: running shellHook"
191
192 # password-store
193 export PASSWORD_STORE_DIR="$PWD"/../sec/pass
194
195 # Nix
196 PATH=$NIX_SHELL_PATH:$PATH
197 export NIX_PATH="${lib.concatStringsSep ":" [
198 "machines=$PWD/machines.nix"
199 #"pass=$PASSWORD_STORE_DIR"
200 "nixpkgs=${toString pkgs.path}"
201 "nixpkgs-overlays=$PWD/nixpkgs/overlays.nix"
202 ]}"
203
204 # Since the .envrc calls this shellHook
205 # the EXIT trap cannot be freely used
206 # because it's already used by direnv,
207 # hence shred at startup, which is not ideal.
208 sourcephile-shred-tmp
209
210 ${modules.nix-shell.shellHook}
211
212 # gpg
213 export GPG_TTY=$(tty)
214 gpg-connect-agent updatestartuptty /bye >/dev/null
215 '';
216 }