]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
notmuch: disable broken tests
[sourcephile-nix.git] / flake.nix
1 {
2 # Pin down nixpkgs instead of using global, system or user registries.
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs/3c0e3697520cbe7d9eb3a64bfd87de840bf4aa77";
4 inputs.flake-utils.url = "github:numtide/flake-utils";
5 inputs.shell = { type = "path"; path = "./shell"; flake = false; };
6 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
7 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
8 outputs = inputs: let
9 # sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
10 remoteNixpkgsPatches = [
11 { meta.description = "dstat: fix pluginpath";
12 url = "https://github.com/NixOS/nixpkgs/pull/80151.diff";
13 sha256 = "0jjw2gvp7b7v2n2m2d6yj0gw711j6p9lyjf5ywp2y9ql6905qf4b";
14 }
15 { meta.description = "syncoid: fix PATH to let it use sudo";
16 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
17 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
18 }
19 { meta.description = "sanoid: fix sanoid.conf generation";
20 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
21 sha256 = "Sy9wPmL+Lfl7hMEeXYOEMk3KlfdL21aL92v6MiGajds=";
22 }
23 { meta.description = "nixos/public-inbox: init";
24 url = "https://github.com/NixOS/nixpkgs/pull/77450.diff";
25 sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd";
26 }
27 { meta.description = "apparmor: fix and improve the service";
28 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
29 sha256 = "sha256-JzS6/42AS9f0XUuC8ybw1tR8lpFwOC59BNqYN4mmeVI=";
30 }
31 { meta.description = "nixos/security.gnupg: provisioning GnuPG-protected secrets through the Nix store";
32 url = "https://github.com/NixOS/nixpkgs/pull/93659.diff";
33 sha256 = "3im5nSrlM32DQUeq0Yp1MHkUcQyLdCGbxfJjgcc9e78=";
34 }
35 { meta.description = "nixos/croc: init";
36 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
37 sha256 = "sha256-hzs5Z9cYCo6aNFfylB37W+1neejV4/kVyM1QmqVhVww=";
38 }
39 { meta.description = "dovecot_fts_xapian: 1.3.1 -> 1.3.3";
40 url = "https://github.com/NixOS/nixpkgs/pull/94938.diff";
41 sha256 = "10bjwcwpvq7nnqdpz0n7c61kb3b27v1abyc80pki7d13jmzzjc04";
42 }
43 { meta.description = "transmission: use freeformType on settings";
44 url = "https://github.com/NixOS/nixpkgs/pull/96655.diff";
45 sha256 = "sha256-5TRjz57xKcQuTUkEZ2cBwH6nCXxMfKcAHAogc/gMcjg=";
46 }
47 { meta.description = "prosody: 0.11.5 -> 0.11.6";
48 url = "https://github.com/NixOS/nixpkgs/pull/97739.diff";
49 sha256 = "sha256-wWChwKSRCA3F0+09cyn5w6EJyX4n38s4jYo3io/2QGs";
50 }
51 { meta.description = "tor: improve type-checking and hardening";
52 url = "https://github.com/NixOS/nixpkgs/pull/97740.diff";
53 sha256 = "sha256-ojmDxbGtfsvrUCtjkR7ZynayEGNDLwYl2Ea6yLOQpIk=";
54 }
55 /*
56 { meta.description = "nixos/postfix: add sandbox";
57 url = "https://github.com/NixOS/nixpkgs/pull/93305.diff";
58 sha256 = "sha256-KmoaPj8G4kRlwkBKo/giyST8xQfnjX3OJhh68NKNaRI=";
59 }
60 { meta.description = "nixos/rspamd: add sandbox";
61 url = "https://github.com/NixOS/nixpkgs/pull/93293.diff";
62 sha256 = "sha256-7OfBzJPeGVhHf4ziYLwOpqaYbElCsjLkT4Y/bbCOPx0=";
63 }
64 */
65 { meta.description = "gitolite: fix updating of gitweb access list and description";
66 url = "https://github.com/NixOS/nixpkgs/pull/98262.diff";
67 sha256 = "sha256-wdYcLgNniLcqCbEeTRIAC8M+LOSCzG3OlvgwKZlqceY=";
68 }
69 { meta.description = "nixos/syncoid: split in multiple systemd services";
70 url = "https://github.com/NixOS/nixpkgs/pull/98455.diff";
71 sha256 = "sha256-ukZd0ti3Rh9EVKhjXEdhvIvpekz9bvbeWqLskrkcJkE=";
72 }
73 { meta.description = "zerobin: update to v1.0.5";
74 url = "https://github.com/NixOS/nixpkgs/pull/98734.diff";
75 sha256 = "sha256-G7vqIdxTY9+PZmJPm2vEkeVTp6dT2OnK6V68WJu4oVQ=";
76 }
77 ];
78 localNixpkgsPatches = [
79 #nixpkgs/patches/zerobin.diff
80 #nixpkgs/patches/gitolite.diff
81 #nixpkgs/patches/tor.diff
82 #nixpkgs/patches/fix-ld-nix.diff
83 #nixpkgs/patches/fix-ld-nix-apparmor.diff
84 ];
85 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
86 nixpkgs = originPkgs.applyPatches {
87 name = "nixpkgs-patched";
88 src = inputs.nixpkgs;
89 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
90 postPatch = ''
91 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
92 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
93 sort | sha256sum | cut -c -7)
94 echo "+patch-$patch" >.version-suffix
95 '';
96 };
97 lib = originPkgs.lib;
98 machines = builtins.mapAttrs (machineName: machineConfig:
99 let cfg = import machineConfig { inherit inputs; }; in
100 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
101 extraArgs = {
102 inherit machineName inputs;
103 machines = inputs.self.nixosConfigurations;
104 } // (cfg.extraArgs or {});
105 modules = cfg.modules ++ [({pkgs, ...}: {
106 nix.registry.nixpkgs.flake = nixpkgs;
107 nix.package = pkgs.nixFlakes;
108 nix.extraOptions = "experimental-features = nix-command flakes";
109 nixpkgs.overlays = import nixpkgs/overlays.nix;
110 system.nixos.versionSuffix = ".${
111 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
112 inputs.self.shortRev or "dirty"}";
113 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
114 # Let 'nixos-version --json' know about the Git revision of this flake.
115 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
116 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
117 /*
118 system.configurationRevision =
119 if inputs.self ? rev
120 then inputs.self.rev
121 else throw "Refusing to build from a dirty Git tree!";
122 */
123 })];
124 }));
125 in
126 {
127 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
128 nixosConfigurations = machines {
129 losurdo = machines/losurdo.nix;
130 mermet = machines/mermet.nix;
131 };
132 }
133 // inputs.flake-utils.lib.eachDefaultSystem (system:
134 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
135 let
136 pkgs = import nixpkgs {
137 inherit system;
138 config = {};
139 overlays = import nixpkgs/overlays.nix;
140 };
141 in {
142 legacyPackages = pkgs;
143 devShell = import ./shell.nix { inherit inputs pkgs; };
144 apps = builtins.mapAttrs (machineName: { config, ... }: let
145 system = config.system.build.toplevel;
146 keygrip = builtins.getAttr machineName {
147 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
148 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
149 };
150 target = "root@${config.networking.hostName}.${config.networking.domain}";
151 nixCopyFlags = ["--substitute-on-destination"];
152 profile = "/nix/var/nix/profiles/system";
153 in rec {
154 # Example: nix run .#losurdo.switch
155 "switch" = {
156 type = "app";
157 program = (pkgs.writeShellScript "switch" ''
158 set -eux
159 set -o pipefail
160 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
161 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
162 ${lib.escapeShellArgs nixCopyFlags} ${system}
163 ${sendkeys.program}
164 # Send the SSH key of the initrd
165 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
166 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
167 # Send the Wireguard key of the initrd
168 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
169 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
170 ssh '${target}' \
171 nix-env --profile '${profile}' --set '${system}' '&&' \
172 '${profile}'/bin/switch-to-configuration switch
173 '').outPath;
174 };
175 # Example: nix run .#losurdo.sendkeys
176 "sendkeys" = {
177 type = "app";
178 program = (pkgs.writeShellScript "sendkeys" ''
179 set -eux
180 set -o pipefail
181 ssh '${target}' \
182 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
183 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
184 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
185 # Send the GnuPG root key
186 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
187 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
188 ssh '${target}' \
189 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
190
191 # Send the GnuPG root key's passphrase
192 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
193 ssh '${target}' \
194 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
195 }
196 '').outPath;
197 };
198 }) inputs.self.nixosConfigurations;}
199 );
200 }