2 inputs.nixpkgs.url = "github:NixOS/nixpkgs/1085c056376041af71e8f1cf72c1ed4a4db01dc6";
3 inputs.flake-utils.url = "github:numtide/flake-utils";
4 inputs.shell = { type = "path"; path = "./shell"; flake = false; };
5 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
6 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
8 remoteNixpkgsPatches = [
9 { meta.description = "dstat: fix pluginpath";
10 url = "https://github.com/NixOS/nixpkgs/pull/80151.diff";
11 sha256 = "0jjw2gvp7b7v2n2m2d6yj0gw711j6p9lyjf5ywp2y9ql6905qf4b";
13 { meta.description = "syncoid: fix PATH to let it use sudo";
14 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
15 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
17 { meta.description = "sanoid: fix sanoid.conf generation";
18 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
19 sha256 = "0lj4krmmbz82zpmbacw0qj2ywsx895bq4d1psjn753ymh7jjqj8k";
21 { meta.description = "nixos/public-inbox: init";
22 url = "https://github.com/NixOS/nixpkgs/pull/77450.diff";
23 sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd";
25 { meta.description = "transmission: apply RFC0042 and harden the service";
26 url = "https://github.com/NixOS/nixpkgs/pull/92106.diff";
27 sha256 = "0d3dd511h7fw0k5q0k6wp7hcwkk7xikfwracp68f1y7hn4jj0pn0";
29 { meta.description = "apparmor: fix and improve the service";
30 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
31 sha256 = "ZZw7S9w1ysAygd9YRgqEUJJrQnVCllipgPGaW2SNSpI=";
33 { meta.description = "nixos/security.gnupg: provisioning GnuPG-protected secrets through the Nix store";
34 url = "https://github.com/NixOS/nixpkgs/pull/93659.diff";
35 sha256 = "EdofXZ5WspuhKv9K63cbMKWzYPOKWBWVmAG6yRN3gNk=";
37 { meta.description = "nixos/croc: init";
38 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
39 sha256 = "0fv3lpj244hvxyixxv4akrr70jv5wwbhb3kmbmd2yskx59a71rch";
41 { meta.description = "prosody-modules: update to revision 2dcbc01c9931";
42 url = "https://github.com/NixOS/nixpkgs/pull/94916.diff";
43 sha256 = "1cpdv5bd3837qh54yd0n6vvbfpn0p0cshkic5q0lv60lmm9raqk4";
45 { meta.description = "nixos/biboumi: init";
46 url = "https://github.com/NixOS/nixpkgs/pull/94917.diff";
47 sha256 = "1rjmmkx1pm08qi0d0bg6lr60jh8w1ifa8n4gnms4k6wka233yk0z";
49 { meta.description = "dovecot_fts_xapian: 1.3.1 -> 1.3.3";
50 url = "https://github.com/NixOS/nixpkgs/pull/94938.diff";
51 sha256 = "10bjwcwpvq7nnqdpz0n7c61kb3b27v1abyc80pki7d13jmzzjc04";
53 { meta.description = "initrd-network: fix flushBeforeStage2";
54 url = "https://github.com/NixOS/nixpkgs/pull/94531.diff";
55 sha256 = "8GWWiGOSGgpyRwmBf0Ie/rzBGrWAjZVKry4R7F8xoBs=";
57 { meta.description = "nixos-install: add support for flakes";
58 url = "https://github.com/NixOS/nixpkgs/pull/95194.diff";
59 sha256 = "Fk3AFiY7uRx+8qqX4WvusMYGJ02Xd4PyzLVY5Hzx8gQ=";
62 localNixpkgsPatches = [
63 #nixpkgs/patches/security.gnupg.diff
65 originPkgs = flakes.nixpkgs.legacyPackages."x86_64-linux";
66 nixpkgsPath = originPkgs.applyPatches {
67 name = "nixpkgs-patched";
69 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
71 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
72 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
73 sort | sha256sum | cut -c -7)
74 echo "+patch-$patch" >.version-suffix
78 machines = builtins.mapAttrs (machineName: machineConfig:
79 let cfg = import machineConfig { inherit flakes; }; in
80 import (nixpkgsPath + "/nixos/lib/eval-config.nix") (cfg // {
82 inherit machineName flakes;
83 machines = flakes.self.nixosConfigurations;
84 } // (cfg.extraArgs or {});
85 modules = cfg.modules ++ [({pkgs, ...}: {
86 system.nixos.versionSuffix = ".${
87 lib.substring 0 8 (flakes.self.lastModifiedDate or flakes.self.lastModified)}.${
88 flakes.self.shortRev or "dirty"}";
89 system.nixos.revision = lib.mkIf (flakes.self ? rev) flakes.self.rev;
90 nix.registry.nixpkgs.flake = nixpkgsPath;
91 nix.package = pkgs.nixFlakes;
93 experimental-features = nix-command flakes
95 # Let 'nixos-version --json' know about the Git revision of this flake.
96 system.configurationRevision = lib.mkIf (flakes.self ? rev) flakes.self.rev;
98 system.configurationRevision =
101 else throw "Refusing to build from a dirty Git tree!";
107 nixosConfigurations = machines {
108 losurdo = machines/losurdo.nix;
109 mermet = machines/mermet.nix;
112 // flakes.flake-utils.lib.eachDefaultSystem (system:
113 #let pkgs = flakes.nixpkgs.legacyPackages.${system}; in
115 pkgs = import nixpkgsPath {
117 config = {}; # Make the config pure, ignoring user's config.
118 overlays = import nixpkgs/overlays.nix;
119 #overlays = import (flakes.self + "/nixpkgs/overlays.nix");
122 devShell = import ./shell.nix { inherit flakes pkgs; };
123 apps = builtins.mapAttrs (machineName: { config, ... }: {
126 system = config.system.build.toplevel;
127 rootKey = "root/key";
128 keygrip = builtins.getAttr machineName {
129 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
130 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
132 target = "root@${config.networking.hostName}.${config.networking.domain}";
133 nixCopyFlags = ["--substitute-on-destination"];
134 profile = "/nix/var/nix/profiles/system";
135 in pkgs.writeShellScript "install" ''
138 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
139 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
140 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
142 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
143 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
145 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
147 # Send the rootKey's passphrase
148 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
150 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
152 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
153 ${lib.escapeShellArgs nixCopyFlags} ${system}
155 nix-env --profile '${profile}' --set '${system}' '&&' \
156 '${profile}'/bin/switch-to-configuration switch
158 }) flakes.self.nixosConfigurations;