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