2 # Pin down nixpkgs from github, instead of using global, system or user registries.
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs/23cd13167a1432550e48734079c2ffeeb441fb96";
4 #inputs.nixpkgs.url = "flake:nixpkgs";
5 inputs.flake-utils.url = "github:numtide/flake-utils";
6 inputs.home-manager.follows = "julm-nix/home-manager";
7 inputs.julm-nix.url = "git://git.sourcephile.fr/julm/julm-nix?ref=master";
8 #inputs.julm-nix.url = "path:julm-nix"; # XXX: this puts the whole folder in the Nix store
9 inputs.julm-nix.inputs.flake-utils.follows = "flake-utils";
10 inputs.julm-nix.inputs.nixpkgs.follows = "nixpkgs";
11 inputs.shell = { type = "path"; path = "./shell"; flake = false; };
12 inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
13 inputs.pass = { type = "path"; path = "./pass"; flake = false; };
15 remoteNixpkgsPatches = import nixpkgs/patches.nix;
16 localNixpkgsPatches = [
17 #nixpkgs/patches/transmission.diff
18 #nixpkgs/patches/apparmor.diff
19 #nixpkgs/patches/ifcopenshell.diff
20 #nixpkgs/patches/public-inbox.diff
21 #nixpkgs/patches/zerobin.diff
22 #nixpkgs/patches/gitolite.diff
23 #nixpkgs/patches/tor.diff
24 #nixpkgs/patches/freeciv.diff
25 #nixpkgs/patches/fix-ld-nix.diff
26 #nixpkgs/patches/fix-ld-nix-apparmor.diff
28 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
29 nixpkgs = originPkgs.applyPatches {
30 name = "nixpkgs-patched";
32 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
34 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
35 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
36 sort | sha256sum | cut -c -7)
37 echo "+patch-$patch" >.version-suffix
41 hosts = builtins.mapAttrs (hostName: hostConfig:
42 let cfg = import hostConfig { inherit inputs; }; in
43 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
45 inherit hostName inputs;
46 hosts = inputs.self.nixosConfigurations;
47 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
48 } // (cfg.extraArgs or {});
49 modules = cfg.modules ++ [
50 inputs.home-manager.nixosModules.home-manager
52 home-manager.useGlobalPkgs = true;
53 home-manager.useUserPackages = true;
56 nix.registry.nixpkgs.flake = nixpkgs;
57 nix.package = pkgs.nixUnstable;
58 nix.extraOptions = "experimental-features = nix-command flakes";
60 import nixpkgs/overlays.nix ++
61 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
62 system.nixos.versionSuffix = ".${
63 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
64 inputs.self.shortRev or "dirty"}";
65 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
66 # Let 'nixos-version --json' know about the Git revision of this flake.
67 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
68 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
69 security.gnupg.agent.enable = true;
70 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
72 system.configurationRevision =
75 else throw "Refusing to build from a dirty Git tree!";
77 programs.ssh.knownHosts = {
79 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
80 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
83 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
84 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
92 # nix -L build .#nixosConfigurations.${hostName}.config.system.build.toplevel
93 nixosConfigurations = hosts {
94 losurdo = hosts/losurdo.nix;
95 mermet = hosts/mermet.nix;
97 #nixosModule = import nixos/modules.nix;
99 // inputs.flake-utils.lib.eachDefaultSystem (system:
100 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
102 pkgs = import nixpkgs {
105 import nixpkgs/overlays.nix ++
106 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
109 legacyPackages = pkgs;
110 devShell = import ./shell.nix { inherit inputs pkgs; };
111 apps = builtins.mapAttrs (hostName: { config, ... }: let
112 system = config.system.build.toplevel;
113 target = "root@${config.networking.hostName}.${config.networking.domain}";
114 profile = "/nix/var/nix/profiles/system";
116 # Example: nix run .#losurdo.switch
119 program = (pkgs.writeShellScript "switch" ''
122 nix-store --add-root hosts/${hostName}.root --indirect --realise ${system}
123 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
125 # Send the SSH key of the initrd
126 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
127 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
128 # Send the Wireguard key of the initrd
129 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
130 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
132 nix-env --profile '${profile}' --set '${system}' '&&' \
133 '${profile}'/bin/switch-to-configuration switch
136 # Example: nix run .#losurdo.sendkeys
139 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
140 program = (pkgs.writeShellScript "sendkeys" ''
142 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
145 }) inputs.self.nixosConfigurations;}