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