]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nftables: retake at ICMPv6 and other stuffs
[sourcephile-nix.git] / flake.nix
1 {
2 inputs.nixpkgs.url = "github:NixOS/nixpkgs/e3e39aa84e9d8c381d9f420f08a57eccb6e0a285";
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 = inputs: let
8 # sha256 = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
9 remoteNixpkgsPatches = [
10 { meta.description = "dstat: fix pluginpath";
11 url = "https://github.com/NixOS/nixpkgs/pull/80151.diff";
12 sha256 = "0jjw2gvp7b7v2n2m2d6yj0gw711j6p9lyjf5ywp2y9ql6905qf4b";
13 }
14 { meta.description = "syncoid: fix PATH to let it use sudo";
15 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
16 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
17 }
18 { meta.description = "sanoid: fix sanoid.conf generation";
19 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
20 sha256 = "Sy9wPmL+Lfl7hMEeXYOEMk3KlfdL21aL92v6MiGajds=";
21 }
22 { meta.description = "nixos/public-inbox: init";
23 url = "https://github.com/NixOS/nixpkgs/pull/77450.diff";
24 sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd";
25 }
26 { meta.description = "apparmor: fix and improve the service";
27 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
28 sha256 = "sha256-JzS6/42AS9f0XUuC8ybw1tR8lpFwOC59BNqYN4mmeVI=";
29 }
30 { meta.description = "nixos/security.gnupg: provisioning GnuPG-protected secrets through the Nix store";
31 url = "https://github.com/NixOS/nixpkgs/pull/93659.diff";
32 sha256 = "3im5nSrlM32DQUeq0Yp1MHkUcQyLdCGbxfJjgcc9e78=";
33 }
34 { meta.description = "nixos/croc: init";
35 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
36 sha256 = "sha256-hzs5Z9cYCo6aNFfylB37W+1neejV4/kVyM1QmqVhVww=";
37 }
38 { meta.description = "dovecot_fts_xapian: 1.3.1 -> 1.3.3";
39 url = "https://github.com/NixOS/nixpkgs/pull/94938.diff";
40 sha256 = "10bjwcwpvq7nnqdpz0n7c61kb3b27v1abyc80pki7d13jmzzjc04";
41 }
42 { meta.description = "nixos-install: add support for flakes";
43 url = "https://github.com/NixOS/nixpkgs/pull/95194.diff";
44 sha256 = "sha256-7EsqWguUWC4CQCMV0ZKQmjlsuLnQuR2/gI7Z/8sM8ww=";
45 }
46 { meta.description = "transmission: use freeformType on settings";
47 url = "https://github.com/NixOS/nixpkgs/pull/96655.diff";
48 sha256 = "sha256-5TRjz57xKcQuTUkEZ2cBwH6nCXxMfKcAHAogc/gMcjg=";
49 }
50 ];
51 localNixpkgsPatches = [
52 #nixpkgs/patches/apparmor.diff
53 #nixpkgs/patches/fix-ld-nix.diff
54 #nixpkgs/patches/fix-ld-nix-apparmor.diff
55 ];
56 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
57 nixpkgs = originPkgs.applyPatches {
58 name = "nixpkgs-patched";
59 src = inputs.nixpkgs;
60 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
61 postPatch = ''
62 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
63 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
64 sort | sha256sum | cut -c -7)
65 echo "+patch-$patch" >.version-suffix
66 '';
67 };
68 lib = originPkgs.lib;
69 initrdKey = "initrd/ssh.key";
70 machines = builtins.mapAttrs (machineName: machineConfig:
71 let cfg = import machineConfig { inherit inputs; }; in
72 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
73 extraArgs = {
74 inherit machineName inputs;
75 machines = inputs.self.nixosConfigurations;
76 } // (cfg.extraArgs or {});
77 modules = cfg.modules ++ [({pkgs, ...}: {
78 nix.registry.nixpkgs.flake = nixpkgs;
79 nix.package = pkgs.nixFlakes;
80 nix.extraOptions = "experimental-features = nix-command flakes";
81 nixpkgs.overlays = import nixpkgs/overlays.nix;
82 system.nixos.versionSuffix = ".${
83 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
84 inputs.self.shortRev or "dirty"}";
85 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
86 # Let 'nixos-version --json' know about the Git revision of this flake.
87 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
88 boot.initrd.network.ssh.hostKeys = [ "/root/${initrdKey}" ];
89 /*
90 system.configurationRevision =
91 if inputs.self ? rev
92 then inputs.self.rev
93 else throw "Refusing to build from a dirty Git tree!";
94 */
95 })];
96 }));
97 in
98 {
99 nixosConfigurations = machines {
100 losurdo = machines/losurdo.nix;
101 mermet = machines/mermet.nix;
102 };
103 }
104 // inputs.flake-utils.lib.eachDefaultSystem (system:
105 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
106 let
107 pkgs = import nixpkgs {
108 inherit system;
109 config = {};
110 overlays = import nixpkgs/overlays.nix;
111 #overlays = import (inputs.self + "/nixpkgs/overlays.nix");
112 };
113 in {
114 devShell = import ./shell.nix { inherit inputs pkgs; };
115 apps = builtins.mapAttrs (machineName: { config, ... }: {
116 type = "app";
117 program = (let
118 system = config.system.build.toplevel;
119 rootKey = "root/key";
120 keygrip = builtins.getAttr machineName {
121 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
122 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
123 };
124 target = "root@${config.networking.hostName}.${config.networking.domain}";
125 nixCopyFlags = ["--substitute-on-destination"];
126 profile = "/nix/var/nix/profiles/system";
127 in pkgs.writeShellScript "install" ''
128 set -eux
129 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
130 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
131 ${lib.escapeShellArgs nixCopyFlags} ${system}
132 ssh '${target}' \
133 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
134 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
135 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
136 # Send the rootKey
137 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
138 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
139 ssh '${target}' \
140 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
141
142 # Send the rootKey's passphrase
143 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
144 ssh '${target}' \
145 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
146 }
147 # Send the SSH key of the initrd
148 gpg --decrypt '${config.security.gnupg.store}/${initrdKey}.gpg' |
149 ssh '${target}' \
150 install -D -m 400 -o root -g root /dev/stdin /root/${initrdKey}
151 ssh '${target}' \
152 nix-env --profile '${profile}' --set '${system}' '&&' \
153 '${profile}'/bin/switch-to-configuration switch
154 '').outPath;
155 }) inputs.self.nixosConfigurations;
156 }
157 );
158 }