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