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