]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
networking: change losurdo's IPv6 to addr_gen_mode=1
[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-84rjqjOGVBxuJbdv47eA7IU20g8YrW754D2Jh1uW5iw=";
72 }
73 ];
74 localNixpkgsPatches = [
75 #nixpkgs/patches/gitolite.diff
76 #nixpkgs/patches/tor.diff
77 #nixpkgs/patches/fix-ld-nix.diff
78 #nixpkgs/patches/fix-ld-nix-apparmor.diff
79 ];
80 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
81 nixpkgs = originPkgs.applyPatches {
82 name = "nixpkgs-patched";
83 src = inputs.nixpkgs;
84 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
85 postPatch = ''
86 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
87 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
88 sort | sha256sum | cut -c -7)
89 echo "+patch-$patch" >.version-suffix
90 '';
91 };
92 lib = originPkgs.lib;
93 initrdKey = "initrd/ssh.key";
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/${initrdKey}" ];
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 })];
120 }));
121 in
122 {
123 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
124 nixosConfigurations = machines {
125 losurdo = machines/losurdo.nix;
126 mermet = machines/mermet.nix;
127 };
128 }
129 // inputs.flake-utils.lib.eachDefaultSystem (system:
130 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
131 let
132 pkgs = import nixpkgs {
133 inherit system;
134 config = {};
135 overlays = import nixpkgs/overlays.nix;
136 #overlays = import (inputs.self + "/nixpkgs/overlays.nix");
137 };
138 in {
139 devShell = import ./shell.nix { inherit inputs pkgs; };
140 apps = builtins.mapAttrs (machineName: { config, ... }: let
141 system = config.system.build.toplevel;
142 rootKey = "root/key";
143 keygrip = builtins.getAttr machineName {
144 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
145 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
146 };
147 target = "root@${config.networking.hostName}.${config.networking.domain}";
148 nixCopyFlags = ["--substitute-on-destination"];
149 profile = "/nix/var/nix/profiles/system";
150 in rec {
151 # Example: nix run .#losurdo.switch
152 "switch" = {
153 type = "app";
154 program = (pkgs.writeShellScript "switch" ''
155 set -eux
156 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
157 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
158 ${lib.escapeShellArgs nixCopyFlags} ${system}
159 ${sendkeys.program}
160 # Send the SSH key of the initrd
161 gpg --decrypt '${config.security.gnupg.store}/${initrdKey}.gpg' |
162 ssh '${target}' \
163 install -D -m 400 -o root -g root /dev/stdin /root/${initrdKey}
164 ssh '${target}' \
165 nix-env --profile '${profile}' --set '${system}' '&&' \
166 '${profile}'/bin/switch-to-configuration switch
167 '').outPath;
168 };
169 # Example: nix run .#losurdo.sendkeys
170 "sendkeys" = {
171 type = "app";
172 program = (pkgs.writeShellScript "sendkeys" ''
173 set -eux
174 ssh '${target}' \
175 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
176 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
177 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
178 # Send the rootKey
179 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
180 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
181 ssh '${target}' \
182 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
183
184 # Send the rootKey's passphrase
185 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
186 ssh '${target}' \
187 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
188 }
189 '').outPath;
190 };
191 }) inputs.self.nixosConfigurations;}
192 );
193 }