]> Git — Sourcephile - sourcephile-nix.git/blob - flake.nix
tor: preparation
[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-GxTZvaQrUxxV8vd7DT42k0xEXMQt2mAgEdiY3fsA8Gs=";
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/fix-ld-nix.diff
53 #nixpkgs/patches/fix-ld-nix-apparmor.diff
54 ];
55 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
56 nixpkgs = originPkgs.applyPatches {
57 name = "nixpkgs-patched";
58 src = inputs.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 inputs; }; in
70 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
71 extraArgs = {
72 inherit machineName inputs;
73 machines = inputs.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 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
82 inputs.self.shortRev or "dirty"}";
83 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
84 # Let 'nixos-version --json' know about the Git revision of this flake.
85 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
86 /*
87 system.configurationRevision =
88 if inputs.self ? rev
89 then inputs.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 // 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 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 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
128 ssh '${target}' \
129 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
130 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
131 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
132 # Send the rootKey
133 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
134 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
135 ssh '${target}' \
136 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
137
138 # Send the rootKey's passphrase
139 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
140 ssh '${target}' \
141 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
142 }
143 # Send the SSH key of the initrd
144 gpg --decrypt '${config.security.gnupg.store}/${initrdKey}.gpg' |
145 ssh '${target}' \
146 install -D -m 400 -o root -g root /dev/stdin /root/${initrdKey}
147 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
148 ${lib.escapeShellArgs nixCopyFlags} ${system}
149 ssh '${target}' \
150 nix-env --profile '${profile}' --set '${system}' '&&' \
151 '${profile}'/bin/switch-to-configuration switch
152 '').outPath;
153 }) inputs.self.nixosConfigurations;
154 }
155 );
156 }