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; };
10 remoteNixpkgsPatches = [
12 { meta.description = "syncoid: fix PATH to let it use sudo";
13 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
14 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
17 { meta.description = "sanoid: fix sanoid.conf generation";
18 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
19 sha256 = "sha256-Wze1a7y0f22dgz+w0JZC4rL1B1Esfmi1msF8Rvil6f0=";
21 { meta.description = "nixos/security.gnupg: provisioning GnuPG-protected secrets through the Nix store";
22 url = "https://github.com/NixOS/nixpkgs/pull/93659.diff";
23 sha256 = "3im5nSrlM32DQUeq0Yp1MHkUcQyLdCGbxfJjgcc9e78=";
25 { meta.description = "nixos/croc: init";
26 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
27 sha256 = "sha256-BxKjjeiuwjvNKrs2u+igdNu5aZhhDJkNjzUl7B5c99M=";
29 { meta.description = "dovecot_fts_xapian: 1.3.1 -> 1.3.3";
30 url = "https://github.com/NixOS/nixpkgs/pull/94938.diff";
31 sha256 = "10bjwcwpvq7nnqdpz0n7c61kb3b27v1abyc80pki7d13jmzzjc04";
33 { meta.description = "transmission: use freeformType on settings";
34 url = "https://github.com/NixOS/nixpkgs/pull/96655.diff";
35 sha256 = "sha256-lRKe8WnGPc8ojaD9W8ZS+NVMhIoGOCOj9njhqQhzaCM";
37 { meta.description = "tor: improve type-checking and hardening";
38 url = "https://github.com/NixOS/nixpkgs/pull/97740.diff";
39 sha256 = "sha256-ojmDxbGtfsvrUCtjkR7ZynayEGNDLwYl2Ea6yLOQpIk=";
42 { meta.description = "nixos/postfix: add sandbox";
43 url = "https://github.com/NixOS/nixpkgs/pull/93305.diff";
44 sha256 = "sha256-KmoaPj8G4kRlwkBKo/giyST8xQfnjX3OJhh68NKNaRI=";
46 { meta.description = "nixos/rspamd: add sandbox";
47 url = "https://github.com/NixOS/nixpkgs/pull/93293.diff";
48 sha256 = "sha256-7OfBzJPeGVhHf4ziYLwOpqaYbElCsjLkT4Y/bbCOPx0=";
51 { meta.description = "nixos/syncoid: split in multiple systemd services";
52 url = "https://github.com/NixOS/nixpkgs/pull/98455.diff";
53 sha256 = "sha256-vmPzvjwAOSWqfizgDk3l6FrMD2OsG+8UpIkQvOUcXNI=";
55 { meta.description = "zerobin: update to v1.0.5";
56 url = "https://github.com/NixOS/nixpkgs/pull/98734.diff";
57 sha256 = "sha256-mEFvzR0ymwR7V3bJBnr9fR3GxA1jDfXZXQzo+jc5Nxc=";
60 { meta.description = "apparmor";
61 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
62 sha256 = "sha256-JzS6/42AS9f0XUuC8ybw1tR8lpFwOC59BNqYN4mmeVI=";
65 { meta.description = "Update public-inbox to 1.6.0 and add systemd services";
66 url = "https://github.com/NixOS/nixpkgs/pull/104457.diff";
67 sha256 = "187fwjw922w6xcwdjnk6r6q4jbmk542vq3qci2z95q026w4l2p7f";
69 { meta.description = "Add freeciv service";
70 url = "https://github.com/NixOS/nixpkgs/pull/104460.diff";
71 sha256 = "sha256-HU6+Pq6WqVKdpnoRBU9FUneunZGc2q+STPAQR5kUS5o=";
74 localNixpkgsPatches = [
75 nixpkgs/patches/apparmor.diff
76 #nixpkgs/patches/public-inbox.diff
77 #nixpkgs/patches/zerobin.diff
78 #nixpkgs/patches/gitolite.diff
79 #nixpkgs/patches/tor.diff
80 #nixpkgs/patches/fix-ld-nix.diff
81 #nixpkgs/patches/fix-ld-nix-apparmor.diff
83 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
84 nixpkgs = originPkgs.applyPatches {
85 name = "nixpkgs-patched";
87 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
89 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
90 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
91 sort | sha256sum | cut -c -7)
92 echo "+patch-$patch" >.version-suffix
96 machines = builtins.mapAttrs (machineName: machineConfig:
97 let cfg = import machineConfig { inherit inputs; }; in
98 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
100 inherit machineName inputs;
101 machines = inputs.self.nixosConfigurations;
102 } // (cfg.extraArgs or {});
103 modules = cfg.modules ++ [({pkgs, ...}: {
104 nix.registry.nixpkgs.flake = nixpkgs;
105 nix.package = pkgs.nixFlakes;
106 nix.extraOptions = "experimental-features = nix-command flakes";
107 nixpkgs.overlays = import nixpkgs/overlays.nix;
108 system.nixos.versionSuffix = ".${
109 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
110 inputs.self.shortRev or "dirty"}";
111 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
112 # Let 'nixos-version --json' know about the Git revision of this flake.
113 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
114 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
115 security.gnupg.store = inputs.pass + "/machines/${machineName}";
117 system.configurationRevision =
120 else throw "Refusing to build from a dirty Git tree!";
122 programs.ssh.knownHosts = {
124 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
125 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
128 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
129 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
136 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
137 nixosConfigurations = machines {
138 losurdo = machines/losurdo.nix;
139 mermet = machines/mermet.nix;
142 // inputs.flake-utils.lib.eachDefaultSystem (system:
143 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
145 pkgs = import nixpkgs {
147 overlays = import nixpkgs/overlays.nix;
150 legacyPackages = pkgs;
151 devShell = import ./shell.nix { inherit inputs pkgs; };
152 apps = builtins.mapAttrs (machineName: { config, ... }: let
153 system = config.system.build.toplevel;
154 keygrip = builtins.getAttr machineName {
155 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
156 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
158 target = "root@${config.networking.hostName}.${config.networking.domain}";
159 profile = "/nix/var/nix/profiles/system";
161 # Example: nix run .#losurdo.switch
164 program = (pkgs.writeShellScript "switch" ''
167 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
168 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
170 # Send the SSH key of the initrd
171 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
172 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
173 # Send the Wireguard key of the initrd
174 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
175 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
177 nix-env --profile '${profile}' --set '${system}' '&&' \
178 '${profile}'/bin/switch-to-configuration switch
181 # Example: nix run .#losurdo.sendkeys
184 program = (pkgs.writeShellScript "sendkeys" ''
188 gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
189 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
190 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
191 # Send the GnuPG root key
192 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
193 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
195 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
197 # Send the GnuPG root key's passphrase
198 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
200 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
204 }) inputs.self.nixosConfigurations;}