2 # Pin down nixpkgs from github, instead of using global, system or user registries.
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs/9031057b0e6642e61c74b3e3c97b4e80a8db1dd6";
4 #inputs.nixpkgs.url = "flake:nixpkgs";
5 inputs.flake-utils.url = "github:numtide/flake-utils";
6 inputs.home-manager.url = "github:nix-community/home-manager";
7 inputs.julm-nix.url = "git://git.sourcephile.fr/julm/julm-nix.git";
8 inputs.shell = { type = "path"; path = "./shell"; flake = false; };
9 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
10 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
12 remoteNixpkgsPatches = import nixpkgs/patches.nix;
13 localNixpkgsPatches = [
14 nixpkgs/patches/apparmor.diff
15 #nixpkgs/patches/public-inbox.diff
16 #nixpkgs/patches/zerobin.diff
17 #nixpkgs/patches/gitolite.diff
18 #nixpkgs/patches/tor.diff
19 #nixpkgs/patches/freeciv.diff
20 #nixpkgs/patches/fix-ld-nix.diff
21 #nixpkgs/patches/fix-ld-nix-apparmor.diff
23 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
24 nixpkgs = originPkgs.applyPatches {
25 name = "nixpkgs-patched";
27 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
29 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
30 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
31 sort | sha256sum | cut -c -7)
32 echo "+patch-$patch" >.version-suffix
36 hosts = builtins.mapAttrs (hostName: hostConfig:
37 let cfg = import hostConfig { inherit inputs; }; in
38 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
40 inherit hostName inputs;
41 hosts = inputs.self.nixosConfigurations;
42 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
43 } // (cfg.extraArgs or {});
44 modules = cfg.modules ++ [
45 inputs.home-manager.nixosModules.home-manager
47 home-manager.useGlobalPkgs = true;
48 home-manager.useUserPackages = true;
51 nix.registry.nixpkgs.flake = nixpkgs;
52 nix.package = pkgs.nixUnstable;
53 nix.extraOptions = "experimental-features = nix-command flakes";
55 import nixpkgs/overlays.nix ++
56 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
57 system.nixos.versionSuffix = ".${
58 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
59 inputs.self.shortRev or "dirty"}";
60 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
61 # Let 'nixos-version --json' know about the Git revision of this flake.
62 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
63 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
64 security.gnupg.agent.enable = true;
65 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
67 system.configurationRevision =
70 else throw "Refusing to build from a dirty Git tree!";
72 programs.ssh.knownHosts = {
74 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
75 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
78 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
79 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
87 # nix -L build .#nixosConfigurations.${hostName}.config.system.build.toplevel
88 nixosConfigurations = hosts {
89 losurdo = hosts/losurdo.nix;
90 mermet = hosts/mermet.nix;
92 #nixosModule = import nixos/modules.nix;
94 // inputs.flake-utils.lib.eachDefaultSystem (system:
95 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
97 pkgs = import nixpkgs {
100 import nixpkgs/overlays.nix ++
101 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
104 legacyPackages = pkgs;
105 devShell = import ./shell.nix { inherit inputs pkgs; };
106 apps = builtins.mapAttrs (hostName: { config, ... }: let
107 system = config.system.build.toplevel;
108 target = "root@${config.networking.hostName}.${config.networking.domain}";
109 profile = "/nix/var/nix/profiles/system";
111 # Example: nix run .#losurdo.switch
114 program = (pkgs.writeShellScript "switch" ''
117 nix-store --add-root hosts/${hostName}.root --indirect --realise ${system}
118 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
120 # Send the SSH key of the initrd
121 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
122 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
123 # Send the Wireguard key of the initrd
124 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
125 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
127 nix-env --profile '${profile}' --set '${system}' '&&' \
128 '${profile}'/bin/switch-to-configuration switch
131 # Example: nix run .#losurdo.sendkeys
134 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
135 program = (pkgs.writeShellScript "sendkeys" ''
137 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
140 }) inputs.self.nixosConfigurations;}