]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
zerobin: update to v1.0.5
[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-ukZd0ti3Rh9EVKhjXEdhvIvpekz9bvbeWqLskrkcJkE=";
72 }
73 { meta.description = "zerobin: update to v1.0.5";
74 url = "https://github.com/NixOS/nixpkgs/pull/98734.diff";
75 sha256 = "sha256-fjXmTp1rmqLWqFSMxlyBYPbrvO3Nqw37khRyql706WY=";
76 }
77 ];
78 localNixpkgsPatches = [
79 #nixpkgs/patches/gitolite.diff
80 #nixpkgs/patches/tor.diff
81 #nixpkgs/patches/fix-ld-nix.diff
82 #nixpkgs/patches/fix-ld-nix-apparmor.diff
83 ];
84 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
85 nixpkgs = originPkgs.applyPatches {
86 name = "nixpkgs-patched";
87 src = inputs.nixpkgs;
88 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
89 postPatch = ''
90 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
91 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
92 sort | sha256sum | cut -c -7)
93 echo "+patch-$patch" >.version-suffix
94 '';
95 };
96 lib = originPkgs.lib;
97 machines = builtins.mapAttrs (machineName: machineConfig:
98 let cfg = import machineConfig { inherit inputs; }; in
99 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
100 extraArgs = {
101 inherit machineName inputs;
102 machines = inputs.self.nixosConfigurations;
103 } // (cfg.extraArgs or {});
104 modules = cfg.modules ++ [({pkgs, ...}: {
105 nix.registry.nixpkgs.flake = nixpkgs;
106 nix.package = pkgs.nixFlakes;
107 nix.extraOptions = "experimental-features = nix-command flakes";
108 nixpkgs.overlays = import nixpkgs/overlays.nix;
109 system.nixos.versionSuffix = ".${
110 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
111 inputs.self.shortRev or "dirty"}";
112 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
113 # Let 'nixos-version --json' know about the Git revision of this flake.
114 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
115 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
116 /*
117 system.configurationRevision =
118 if inputs.self ? rev
119 then inputs.self.rev
120 else throw "Refusing to build from a dirty Git tree!";
121 */
122 })];
123 }));
124 in
125 {
126 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
127 nixosConfigurations = machines {
128 losurdo = machines/losurdo.nix;
129 mermet = machines/mermet.nix;
130 };
131 }
132 // inputs.flake-utils.lib.eachDefaultSystem (system:
133 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
134 let
135 pkgs = import nixpkgs {
136 inherit system;
137 config = {};
138 overlays = import nixpkgs/overlays.nix;
139 #overlays = import (inputs.self + "/nixpkgs/overlays.nix");
140 };
141 in {
142 devShell = import ./shell.nix { inherit inputs pkgs; };
143 apps = builtins.mapAttrs (machineName: { config, ... }: let
144 system = config.system.build.toplevel;
145 keygrip = builtins.getAttr machineName {
146 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
147 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
148 };
149 target = "root@${config.networking.hostName}.${config.networking.domain}";
150 nixCopyFlags = ["--substitute-on-destination"];
151 profile = "/nix/var/nix/profiles/system";
152 in rec {
153 # Example: nix run .#losurdo.switch
154 "switch" = {
155 type = "app";
156 program = (pkgs.writeShellScript "switch" ''
157 set -eux
158 set -o pipefail
159 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
160 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
161 ${lib.escapeShellArgs nixCopyFlags} ${system}
162 ${sendkeys.program}
163 # Send the SSH key of the initrd
164 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
165 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
166 # Send the Wireguard key of the initrd
167 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
168 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
169 ssh '${target}' \
170 nix-env --profile '${profile}' --set '${system}' '&&' \
171 '${profile}'/bin/switch-to-configuration switch
172 '').outPath;
173 };
174 # Example: nix run .#losurdo.sendkeys
175 "sendkeys" = {
176 type = "app";
177 program = (pkgs.writeShellScript "sendkeys" ''
178 set -eux
179 set -o pipefail
180 ssh '${target}' \
181 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
182 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
183 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
184 # Send the GnuPG root key
185 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
186 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
187 ssh '${target}' \
188 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
189
190 # Send the GnuPG root key's passphrase
191 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
192 ssh '${target}' \
193 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
194 }
195 '').outPath;
196 };
197 }) inputs.self.nixosConfigurations;}
198 );
199 }