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