]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
nix: update to latest nixpkgs-unstable
[sourcephile-nix.git] / flake.nix
1 {
2 inputs.nixpkgs.url = "github:NixOS/nixpkgs/3c0e3697520cbe7d9eb3a64bfd87de840bf4aa77";
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 = "transmission: use freeformType on settings";
43 url = "https://github.com/NixOS/nixpkgs/pull/96655.diff";
44 sha256 = "sha256-5TRjz57xKcQuTUkEZ2cBwH6nCXxMfKcAHAogc/gMcjg=";
45 }
46 ];
47 localNixpkgsPatches = [
48 #nixpkgs/patches/apparmor.diff
49 #nixpkgs/patches/fix-ld-nix.diff
50 #nixpkgs/patches/fix-ld-nix-apparmor.diff
51 ];
52 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
53 nixpkgs = originPkgs.applyPatches {
54 name = "nixpkgs-patched";
55 src = inputs.nixpkgs;
56 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
57 postPatch = ''
58 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
59 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
60 sort | sha256sum | cut -c -7)
61 echo "+patch-$patch" >.version-suffix
62 '';
63 };
64 lib = originPkgs.lib;
65 initrdKey = "initrd/ssh.key";
66 machines = builtins.mapAttrs (machineName: machineConfig:
67 let cfg = import machineConfig { inherit inputs; }; in
68 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
69 extraArgs = {
70 inherit machineName inputs;
71 machines = inputs.self.nixosConfigurations;
72 } // (cfg.extraArgs or {});
73 modules = cfg.modules ++ [({pkgs, ...}: {
74 nix.registry.nixpkgs.flake = nixpkgs;
75 nix.package = pkgs.nixFlakes;
76 nix.extraOptions = "experimental-features = nix-command flakes";
77 nixpkgs.overlays = import nixpkgs/overlays.nix;
78 system.nixos.versionSuffix = ".${
79 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
80 inputs.self.shortRev or "dirty"}";
81 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
82 # Let 'nixos-version --json' know about the Git revision of this flake.
83 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
84 boot.initrd.network.ssh.hostKeys = [ "/root/${initrdKey}" ];
85 /*
86 system.configurationRevision =
87 if inputs.self ? rev
88 then inputs.self.rev
89 else throw "Refusing to build from a dirty Git tree!";
90 */
91 })];
92 }));
93 in
94 {
95 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
96 nixosConfigurations = machines {
97 losurdo = machines/losurdo.nix;
98 mermet = machines/mermet.nix;
99 };
100 }
101 // inputs.flake-utils.lib.eachDefaultSystem (system:
102 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
103 let
104 pkgs = import nixpkgs {
105 inherit system;
106 config = {};
107 overlays = import nixpkgs/overlays.nix;
108 #overlays = import (inputs.self + "/nixpkgs/overlays.nix");
109 };
110 in {
111 devShell = import ./shell.nix { inherit inputs pkgs; };
112 apps = builtins.mapAttrs (machineName: { config, ... }: {
113 type = "app";
114 program = (let
115 system = config.system.build.toplevel;
116 rootKey = "root/key";
117 keygrip = builtins.getAttr machineName {
118 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
119 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
120 };
121 target = "root@${config.networking.hostName}.${config.networking.domain}";
122 nixCopyFlags = ["--substitute-on-destination"];
123 profile = "/nix/var/nix/profiles/system";
124 in pkgs.writeShellScript "install" ''
125 set -eux
126 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
127 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
128 ${lib.escapeShellArgs nixCopyFlags} ${system}
129 ssh '${target}' \
130 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
131 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
132 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
133 # Send the rootKey
134 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
135 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
136 ssh '${target}' \
137 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
138
139 # Send the rootKey's passphrase
140 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
141 ssh '${target}' \
142 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
143 }
144 # Send the SSH key of the initrd
145 gpg --decrypt '${config.security.gnupg.store}/${initrdKey}.gpg' |
146 ssh '${target}' \
147 install -D -m 400 -o root -g root /dev/stdin /root/${initrdKey}
148 ssh '${target}' \
149 nix-env --profile '${profile}' --set '${system}' '&&' \
150 '${profile}'/bin/switch-to-configuration switch
151 '').outPath;
152 }) inputs.self.nixosConfigurations;
153 }
154 );
155 }