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; };
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";
15 { meta.description = "syncoid: fix PATH to let it use sudo";
16 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
17 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
19 { meta.description = "sanoid: fix sanoid.conf generation";
20 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
21 sha256 = "Sy9wPmL+Lfl7hMEeXYOEMk3KlfdL21aL92v6MiGajds=";
23 { meta.description = "nixos/public-inbox: init";
24 url = "https://github.com/NixOS/nixpkgs/pull/77450.diff";
25 sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd";
27 { meta.description = "apparmor: fix and improve the service";
28 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
29 sha256 = "sha256-JzS6/42AS9f0XUuC8ybw1tR8lpFwOC59BNqYN4mmeVI=";
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=";
35 { meta.description = "nixos/croc: init";
36 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
37 sha256 = "sha256-hzs5Z9cYCo6aNFfylB37W+1neejV4/kVyM1QmqVhVww=";
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";
43 { meta.description = "transmission: use freeformType on settings";
44 url = "https://github.com/NixOS/nixpkgs/pull/96655.diff";
45 sha256 = "sha256-5TRjz57xKcQuTUkEZ2cBwH6nCXxMfKcAHAogc/gMcjg=";
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";
51 { meta.description = "tor: improve type-checking and hardening";
52 url = "https://github.com/NixOS/nixpkgs/pull/97740.diff";
53 sha256 = "sha256-ojmDxbGtfsvrUCtjkR7ZynayEGNDLwYl2Ea6yLOQpIk=";
56 localNixpkgsPatches = [
57 #nixpkgs/patches/tor.diff
58 #nixpkgs/patches/fix-ld-nix.diff
59 #nixpkgs/patches/fix-ld-nix-apparmor.diff
61 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
62 nixpkgs = originPkgs.applyPatches {
63 name = "nixpkgs-patched";
65 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
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
74 initrdKey = "initrd/ssh.key";
75 machines = builtins.mapAttrs (machineName: machineConfig:
76 let cfg = import machineConfig { inherit inputs; }; in
77 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
79 inherit machineName inputs;
80 machines = inputs.self.nixosConfigurations;
81 } // (cfg.extraArgs or {});
82 modules = cfg.modules ++ [({pkgs, ...}: {
83 nix.registry.nixpkgs.flake = nixpkgs;
84 nix.package = pkgs.nixFlakes;
85 nix.extraOptions = "experimental-features = nix-command flakes";
86 nixpkgs.overlays = import nixpkgs/overlays.nix;
87 system.nixos.versionSuffix = ".${
88 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
89 inputs.self.shortRev or "dirty"}";
90 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
91 # Let 'nixos-version --json' know about the Git revision of this flake.
92 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
93 boot.initrd.network.ssh.hostKeys = [ "/root/${initrdKey}" ];
95 system.configurationRevision =
98 else throw "Refusing to build from a dirty Git tree!";
104 # nix -L build .#nixosConfigurations.${machineName}.config.system.build.toplevel
105 nixosConfigurations = machines {
106 losurdo = machines/losurdo.nix;
107 mermet = machines/mermet.nix;
110 // inputs.flake-utils.lib.eachDefaultSystem (system:
111 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
113 pkgs = import nixpkgs {
116 overlays = import nixpkgs/overlays.nix;
117 #overlays = import (inputs.self + "/nixpkgs/overlays.nix");
120 devShell = import ./shell.nix { inherit inputs pkgs; };
121 apps = builtins.mapAttrs (machineName: { config, ... }: {
124 system = config.system.build.toplevel;
125 rootKey = "root/key";
126 keygrip = builtins.getAttr machineName {
127 losurdo = "9AA84E6F6D71F9163C46BF396B141A0806219077";
128 mermet = "89F52A879E0019A966503AFFDE72EEA84CDFA3A7";
130 target = "root@${config.networking.hostName}.${config.networking.domain}";
131 nixCopyFlags = ["--substitute-on-destination"];
132 profile = "/nix/var/nix/profiles/system";
133 in pkgs.writeShellScript "install" ''
135 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
136 ${pkgs.nixFlakes}/bin/nix copy --to ssh://'${target}' \
137 ${lib.escapeShellArgs nixCopyFlags} ${system}
139 ${pkgs.gnupg}/bin/gpg-connect-agent --no-autostart --homedir /var/lib/gnupg "'keyinfo --list'" /bye 2>&1 |
140 grep -qx -e "gpg-connect-agent: no gpg-agent running in this session" \
141 -e "S KEYINFO ${keygrip} . . . 1 .*" || {
143 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
144 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
146 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
148 # Send the rootKey's passphrase
149 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
151 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
153 # Send the SSH key of the initrd
154 gpg --decrypt '${config.security.gnupg.store}/${initrdKey}.gpg' |
156 install -D -m 400 -o root -g root /dev/stdin /root/${initrdKey}
158 nix-env --profile '${profile}' --set '${system}' '&&' \
159 '${profile}'/bin/switch-to-configuration switch
161 }) inputs.self.nixosConfigurations;