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