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.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/apparmor.diff
18 #nixpkgs/patches/ifcopenshell.diff
19 #nixpkgs/patches/public-inbox.diff
20 #nixpkgs/patches/zerobin.diff
21 #nixpkgs/patches/gitolite.diff
22 #nixpkgs/patches/tor.diff
23 #nixpkgs/patches/freeciv.diff
24 #nixpkgs/patches/fix-ld-nix.diff
25 #nixpkgs/patches/fix-ld-nix-apparmor.diff
27 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
28 nixpkgs = originPkgs.applyPatches {
29 name = "nixpkgs-patched";
31 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
33 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
34 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
35 sort | sha256sum | cut -c -7)
36 echo "+patch-$patch" >.version-suffix
40 hosts = builtins.mapAttrs (hostName: hostConfig:
41 let cfg = import hostConfig { inherit inputs; }; in
42 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
44 inherit hostName inputs;
45 hosts = inputs.self.nixosConfigurations;
46 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
47 } // (cfg.extraArgs or {});
48 modules = cfg.modules ++ [
49 inputs.home-manager.nixosModules.home-manager
51 home-manager.useGlobalPkgs = true;
52 home-manager.useUserPackages = true;
55 nix.registry.nixpkgs.flake = nixpkgs;
56 nix.package = pkgs.nixUnstable;
57 nix.extraOptions = "experimental-features = nix-command flakes";
59 import nixpkgs/overlays.nix ++
60 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
61 system.nixos.versionSuffix = ".${
62 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
63 inputs.self.shortRev or "dirty"}";
64 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
65 # Let 'nixos-version --json' know about the Git revision of this flake.
66 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
67 boot.initrd.network.ssh.hostKeys = [ "/root/initrd/ssh.key" ];
68 security.gnupg.agent.enable = true;
69 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
71 system.configurationRevision =
74 else throw "Refusing to build from a dirty Git tree!";
76 programs.ssh.knownHosts = {
78 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
79 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
82 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
83 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
91 # nix -L build .#nixosConfigurations.${hostName}.config.system.build.toplevel
92 nixosConfigurations = hosts {
93 losurdo = hosts/losurdo.nix;
94 mermet = hosts/mermet.nix;
96 #nixosModule = import nixos/modules.nix;
98 // inputs.flake-utils.lib.eachDefaultSystem (system:
99 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
101 pkgs = import nixpkgs {
104 import nixpkgs/overlays.nix ++
105 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
108 legacyPackages = pkgs;
109 devShell = import ./shell.nix { inherit inputs pkgs; };
110 apps = builtins.mapAttrs (hostName: { config, ... }: let
111 system = config.system.build.toplevel;
112 target = "root@${config.networking.hostName}.${config.networking.domain}";
113 profile = "/nix/var/nix/profiles/system";
115 # Example: nix run .#losurdo.switch
118 program = (pkgs.writeShellScript "switch" ''
121 nix-store --add-root hosts/${hostName}.root --indirect --realise ${system}
122 nix copy --to ssh://'${target}' --substitute-on-destination ${system}
124 # Send the SSH key of the initrd
125 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
126 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
127 # Send the Wireguard key of the initrd
128 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
129 ssh '${target}' install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
131 nix-env --profile '${profile}' --set '${system}' '&&' \
132 '${profile}'/bin/switch-to-configuration switch
135 # Example: nix run .#losurdo.sendkeys
138 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
139 program = (pkgs.writeShellScript "sendkeys" ''
141 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
144 }) inputs.self.nixosConfigurations;}