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; };
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";
14 { meta.description = "syncoid: fix PATH to let it use sudo";
15 url = "https://github.com/NixOS/nixpkgs/pull/83901.diff";
16 sha256 = "0q2dicmvl3h3hb9xdd870n5hf6lac489p000c7f1r6k70sh2id4l";
18 { meta.description = "sanoid: fix sanoid.conf generation";
19 url = "https://github.com/NixOS/nixpkgs/pull/83904.diff";
20 sha256 = "Sy9wPmL+Lfl7hMEeXYOEMk3KlfdL21aL92v6MiGajds=";
22 { meta.description = "nixos/public-inbox: init";
23 url = "https://github.com/NixOS/nixpkgs/pull/77450.diff";
24 sha256 = "13ikg7chpbf6rrg5sngbdb95q3awhdgl4g8vci42xmqyf208hzzd";
26 { meta.description = "apparmor: fix and improve the service";
27 url = "https://github.com/NixOS/nixpkgs/pull/93457.diff";
28 sha256 = "sha256-GxTZvaQrUxxV8vd7DT42k0xEXMQt2mAgEdiY3fsA8Gs=";
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=";
34 { meta.description = "nixos/croc: init";
35 url = "https://github.com/NixOS/nixpkgs/pull/93629.diff";
36 sha256 = "sha256-hzs5Z9cYCo6aNFfylB37W+1neejV4/kVyM1QmqVhVww=";
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";
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=";
46 { meta.description = "transmission: use freeformType on settings";
47 url = "https://github.com/NixOS/nixpkgs/pull/96655.diff";
48 sha256 = "sha256-5TRjz57xKcQuTUkEZ2cBwH6nCXxMfKcAHAogc/gMcjg=";
51 localNixpkgsPatches = [
52 #nixpkgs/patches/fix-ld-nix.diff
53 #nixpkgs/patches/fix-ld-nix-apparmor.diff
55 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
56 nixpkgs = originPkgs.applyPatches {
57 name = "nixpkgs-patched";
59 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
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
68 machines = builtins.mapAttrs (machineName: machineConfig:
69 let cfg = import machineConfig { inherit inputs; }; in
70 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
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;
87 system.configurationRevision =
90 else throw "Refusing to build from a dirty Git tree!";
96 nixosConfigurations = machines {
97 losurdo = machines/losurdo.nix;
98 mermet = machines/mermet.nix;
101 // inputs.flake-utils.lib.eachDefaultSystem (system:
102 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
104 pkgs = import nixpkgs {
107 overlays = import nixpkgs/overlays.nix;
108 #overlays = import (inputs.self + "/nixpkgs/overlays.nix");
111 devShell = import ./shell.nix { inherit inputs pkgs; };
112 apps = builtins.mapAttrs (machineName: { config, ... }: {
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";
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" ''
127 nix-store --add-root machines/${machineName}.root --indirect --realise ${system}
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 .*" || {
133 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
134 gpg --batch --pinentry-mode loopback --passphrase-fd 0 --export-secret-subkeys @root@${machineName} |
136 gpg --no-autostart --homedir /var/lib/gnupg --no-autostart --batch --pinentry-mode loopback --import
138 # Send the rootKey's passphrase
139 gpg --decrypt '${config.security.gnupg.store}/${rootKey}.pass.gpg' |
141 gpg-preset-passphrase --homedir /var/lib/gnupg --preset ${keygrip}
143 # Send the SSH key of the initrd
144 gpg --decrypt '${config.security.gnupg.store}/${initrdKey}.gpg' |
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}
150 nix-env --profile '${profile}' --set '${system}' '&&' \
151 '${profile}'/bin/switch-to-configuration switch
153 }) inputs.self.nixosConfigurations;