]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nix: move to flake.nix
[sourcephile-nix.git] / flake.nix
1 {
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; };
7 outputs = flakes: let
8 remoteNixpkgsPatches = [
9 { meta.description = "dstat: fix pluginpath";
10 url = "https://github.com/NixOS/nixpkgs/pull/80151.diff";
11 sha256 = "0jjw2gvp7b7v2n2m2d6yj0gw711j6p9lyjf5ywp2y9ql6905qf4b";
12 }
13 { meta.description = "syncoid: fix PATH to let it use sudo";
14 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
15 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
16 }
17 { meta.description = "sanoid: fix sanoid.conf generation";
18 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
19 sha256 = "0lj4krmmbz82zpmbacw0qj2ywsx895bq4d1psjn753ymh7jjqj8k";
20 }
21 { meta.description = "nixos/public-inbox: init";
22 url = "https://github.com/NixOS/nixpkgs/pull/77450.diff";
23 sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd";
24 }
25 { meta.description = "transmission: apply RFC0042 and harden the service";
26 url = "https://github.com/NixOS/nixpkgs/pull/92106.diff";
27 sha256 = "0d3dd511h7fw0k5q0k6wp7hcwkk7xikfwracp68f1y7hn4jj0pn0";
28 }
29 { meta.description = "apparmor: fix and improve the service";
30 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
31 sha256 = "ZZw7S9w1ysAygd9YRgqEUJJrQnVCllipgPGaW2SNSpI=";
32 }
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=";
36 }
37 { meta.description = "nixos/croc: init";
38 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
39 sha256 = "0fv3lpj244hvxyixxv4akrr70jv5wwbhb3kmbmd2yskx59a71rch";
40 }
41 { meta.description = "prosody-modules: update to revision 2dcbc01c9931";
42 url = "https://github.com/NixOS/nixpkgs/pull/94916.diff";
43 sha256 = "1cpdv5bd3837qh54yd0n6vvbfpn0p0cshkic5q0lv60lmm9raqk4";
44 }
45 { meta.description = "nixos/biboumi: init";
46 url = "https://github.com/NixOS/nixpkgs/pull/94917.diff";
47 sha256 = "1rjmmkx1pm08qi0d0bg6lr60jh8w1ifa8n4gnms4k6wka233yk0z";
48 }
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";
52 }
53 { meta.description = "initrd-network: fix flushBeforeStage2";
54 url = "https://github.com/NixOS/nixpkgs/pull/94531.diff";
55 sha256 = "8GWWiGOSGgpyRwmBf0Ie/rzBGrWAjZVKry4R7F8xoBs=";
56 }
57 { meta.description = "nixos-install: add support for flakes";
58 url = "https://github.com/NixOS/nixpkgs/pull/95194.diff";
59 sha256 = "Fk3AFiY7uRx+8qqX4WvusMYGJ02Xd4PyzLVY5Hzx8gQ=";
60 }
61 ];
62 localNixpkgsPatches = [
63 #nixpkgs/patches/security.gnupg.diff
64 ];
65 originPkgs = flakes.nixpkgs.legacyPackages."x86_64-linux";
66 nixpkgsPath = originPkgs.applyPatches {
67 name = "nixpkgs-patched";
68 src = flakes.nixpkgs;
69 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
70 postPatch = ''
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
75 '';
76 };
77 lib = originPkgs.lib;
78 machines = builtins.mapAttrs (machineName: machineConfig:
79 let cfg = import machineConfig { inherit flakes; }; in
80 import (nixpkgsPath + "/nixos/lib/eval-config.nix") (cfg // {
81 extraArgs = {
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;
92 nix.extraOptions = ''
93 experimental-features = nix-command flakes
94 '';
95 # Let 'nixos-version --json' know about the Git revision of this flake.
96 system.configurationRevision = lib.mkIf (flakes.self ? rev) flakes.self.rev;
97 /*
98 system.configurationRevision =
99 if flakes.self ? rev
100 then flakes.self.rev
101 else throw "Refusing to build from a dirty Git tree!";
102 */
103 })];
104 }));
105 in
106 {
107 nixosConfigurations = machines {
108 losurdo = machines/losurdo.nix;
109 mermet = machines/mermet.nix;
110 };
111 }
112 // flakes.flake-utils.lib.eachDefaultSystem (system:
113 #let pkgs = flakes.nixpkgs.legacyPackages.${system}; in
114 let
115 pkgs = import nixpkgsPath {
116 inherit system;
117 config = {}; # Make the config pure, ignoring user's config.
118 overlays = import nixpkgs/overlays.nix;
119 #overlays = import (flakes.self + "/nixpkgs/overlays.nix");
120 };
121 in {
122 devShell = import ./shell.nix { inherit flakes pkgs; };
123 apps = builtins.mapAttrs (machineName: { config, ... }: {
124 type = "app";
125 program = (let
126 system = config.system.build.toplevel;
127 rootKey = "root/key";
128 keygrip = builtins.getAttr machineName {
129 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
130 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
131 };
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" ''
136 set -eux
137 ssh '${target}' \
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 .*" || {
141 # Send the rootKey
142 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
143 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
144 ssh '${target}' \
145 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
146
147 # Send the rootKey's passphrase
148 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
149 ssh '${target}' \
150 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
151 }
152 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
153 ${lib.escapeShellArgs nixCopyFlags} ${system}
154 ssh '${target}' \
155 nix-env --profile '${profile}' --set '${system}' '&&' \
156 '${profile}'/bin/switch-to-configuration switch
157 '').outPath;
158 }) flakes.self.nixosConfigurations;
159 }
160 );
161 }