]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
transmission: update PR#96655
[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/1efdcde428a4d91297ed0dd63584218ac2cdd898";
4 #inputs.nixpkgs.url = "flake:nixpkgs";
5 inputs.flake-utils.url = "github:numtide/flake-utils";
6 inputs.shell = { type = "path"; path = "./shell"; flake = false; };
7 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
8 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
9 outputs = inputs: let
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 = "nixos/security.gnupg: provisioning GnuPG-protected secrets through the Nix store";
28 url = "https://github.com/NixOS/nixpkgs/pull/93659.diff";
29 sha256 = "3im5nSrlM32DQUeq0Yp1MHkUcQyLdCGbxfJjgcc9e78=";
30 }
31 { meta.description = "nixos/croc: init";
32 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
33 sha256 = "sha256-hzs5Z9cYCo6aNFfylB37W+1neejV4/kVyM1QmqVhVww=";
34 }
35 { meta.description = "dovecot_fts_xapian: 1.3.1 -> 1.3.3";
36 url = "https://github.com/NixOS/nixpkgs/pull/94938.diff";
37 sha256 = "10bjwcwpvq7nnqdpz0n7c61kb3b27v1abyc80pki7d13jmzzjc04";
38 }
39 { meta.description = "transmission: use freeformType on settings";
40 url = "https://github.com/NixOS/nixpkgs/pull/96655.diff";
41 sha256 = "sha256-lRKe8WnGPc8ojaD9W8ZS+NVMhIoGOCOj9njhqQhzaCM";
42 }
43 { meta.description = "tor: improve type-checking and hardening";
44 url = "https://github.com/NixOS/nixpkgs/pull/97740.diff";
45 sha256 = "sha256-ojmDxbGtfsvrUCtjkR7ZynayEGNDLwYl2Ea6yLOQpIk=";
46 }
47 /*
48 { meta.description = "nixos/postfix: add sandbox";
49 url = "https://github.com/NixOS/nixpkgs/pull/93305.diff";
50 sha256 = "sha256-KmoaPj8G4kRlwkBKo/giyST8xQfnjX3OJhh68NKNaRI=";
51 }
52 { meta.description = "nixos/rspamd: add sandbox";
53 url = "https://github.com/NixOS/nixpkgs/pull/93293.diff";
54 sha256 = "sha256-7OfBzJPeGVhHf4ziYLwOpqaYbElCsjLkT4Y/bbCOPx0=";
55 }
56 */
57 { meta.description = "nixos/syncoid: split in multiple systemd services";
58 url = "https://github.com/NixOS/nixpkgs/pull/98455.diff";
59 sha256 = "sha256-ukZd0ti3Rh9EVKhjXEdhvIvpekz9bvbeWqLskrkcJkE=";
60 }
61 { meta.description = "zerobin: update to v1.0.5";
62 url = "https://github.com/NixOS/nixpkgs/pull/98734.diff";
63 sha256 = "sha256-mEFvzR0ymwR7V3bJBnr9fR3GxA1jDfXZXQzo+jc5Nxc=";
64 }
65 /*
66 { meta.description = "apparmor";
67 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
68 sha256 = "sha256-JzS6/42AS9f0XUuC8ybw1tR8lpFwOC59BNqYN4mmeVI=";
69 }
70 */
71 ];
72 localNixpkgsPatches = [
73 nixpkgs/patches/apparmor.diff
74 #nixpkgs/patches/zerobin.diff
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 machines = builtins.mapAttrs (machineName: machineConfig:
94 let cfg = import machineConfig { inherit inputs; }; in
95 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
96 extraArgs = {
97 inherit machineName inputs;
98 machines = inputs.self.nixosConfigurations;
99 } // (cfg.extraArgs or {});
100 modules = cfg.modules ++ [({pkgs, ...}: {
101 nix.registry.nixpkgs.flake = nixpkgs;
102 nix.package = pkgs.nixFlakes;
103 nix.extraOptions = "experimental-features = nix-command flakes";
104 nixpkgs.overlays = import nixpkgs/overlays.nix;
105 system.nixos.versionSuffix = ".${
106 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
107 inputs.self.shortRev or "dirty"}";
108 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
109 # Let 'nixos-version --json' know about the Git revision of this flake.
110 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
111 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
112 /*
113 system.configurationRevision =
114 if inputs.self ? rev
115 then inputs.self.rev
116 else throw "Refusing to build from a dirty Git tree!";
117 */
118 })];
119 }));
120 in
121 {
122 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
123 nixosConfigurations = machines {
124 losurdo = machines/losurdo.nix;
125 mermet = machines/mermet.nix;
126 };
127 }
128 // inputs.flake-utils.lib.eachDefaultSystem (system:
129 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
130 let
131 pkgs = import nixpkgs {
132 inherit system;
133 overlays = import nixpkgs/overlays.nix;
134 };
135 in {
136 legacyPackages = pkgs;
137 devShell = import ./shell.nix { inherit inputs pkgs; };
138 apps = builtins.mapAttrs (machineName: { config, ... }: let
139 system = config.system.build.toplevel;
140 keygrip = builtins.getAttr machineName {
141 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
142 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
143 };
144 target = "root@${config.networking.hostName}.${config.networking.domain}";
145 nixCopyFlags = ["--substitute-on-destination"];
146 profile = "/nix/var/nix/profiles/system";
147 in rec {
148 # Example: nix run .#losurdo.switch
149 "switch" = {
150 type = "app";
151 program = (pkgs.writeShellScript "switch" ''
152 set -eux
153 set -o pipefail
154 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
155 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
156 ${lib.escapeShellArgs nixCopyFlags} ${system}
157 ${sendkeys.program}
158 # Send the SSH key of the initrd
159 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
160 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
161 # Send the Wireguard key of the initrd
162 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
163 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
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 set -o pipefail
175 ssh '${target}' \
176 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
177 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
178 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
179 # Send the GnuPG root key
180 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
181 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
182 ssh '${target}' \
183 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
184
185 # Send the GnuPG root key's passphrase
186 gpg --decrypt '${config.security.gnupg.store}/root/key.pass.gpg' |
187 ssh '${target}' \
188 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
189 }
190 '').outPath;
191 };
192 }) inputs.self.nixosConfigurations;}
193 );
194 }