2 # Pin down nixpkgs from github, instead of using global, system or user registries.
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs/c47fcb70c6885d6df869934280ebeb715ca7e6fd";
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+https://git.hut.sourcephile.fr/~julm/julm-nix?ref=main";
8 inputs.julm-nix.url = "git+file:///home/julm/work/sourcephile/nix/julm-nix?ref=main";
9 inputs.julm-nix.inputs.flake-utils.follows = "flake-utils";
10 inputs.julm-nix.inputs.nixpkgs.follows = "nixpkgs";
11 inputs.nix-doom-emacs.follows = "julm-nix/nix-doom-emacs";
12 inputs.emacs-overlay.follows = "julm-nix/emacs-overlay";
13 #inputs.shell = { type = "path"; path = "./shell"; flake = false; };
14 #inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
15 #inputs.pass = { type = "path"; path = "./pass"; flake = false; };
16 inputs.shell.url = "path:./shell";
17 inputs.shell.flake = false;
18 inputs.secrets.type = "path";
19 inputs.secrets.path = "/home/julm/work/sourcephile/nix/sec";
20 inputs.secrets.flake = false;
21 inputs.pass.type = "path";
22 inputs.pass.path = "/home/julm/work/sourcephile/nix/pass";
23 inputs.pass.flake = false;
25 remoteNixpkgsPatches = import nixpkgs/patches.nix;
26 localNixpkgsPatches = [
27 nixpkgs/patches/sourcehut.diff
29 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
30 nixpkgs = originPkgs.applyPatches {
31 name = "nixpkgs-patched";
33 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
35 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
36 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
37 sort | sha256sum | cut -c -7)
38 echo "+patch-$patch" >.version-suffix
42 hosts = builtins.mapAttrs (hostName: hostConfig:
43 let cfg = import hostConfig { inherit inputs hostName; }; in
44 import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
46 inherit hostName inputs;
47 private = "/root/private"; # Kept out of /nix/store
50 hosts = inputs.self.nixosConfigurations;
51 host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
52 } // (cfg.extraArgs or {});
53 modules = cfg.modules ++ [
54 inputs.home-manager.nixosModules.home-manager
56 home-manager.useGlobalPkgs = true;
57 home-manager.useUserPackages = true;
58 home-manager.verbose = true;
59 home-manager.backupFileExtension = null;
60 home-manager.extraSpecialArgs = {
65 nix.package = pkgs.nixUnstable;
67 import nixpkgs/overlays.nix ++
68 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
69 system.nixos.versionSuffix = ".${
70 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
71 inputs.self.shortRev or "dirty"}";
72 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
73 # Let 'nixos-version --json' know about the Git revision of this flake.
74 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
75 security.gnupg.agent.enable = true;
76 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
78 system.configurationRevision =
81 else throw "Refusing to build from a dirty Git tree!";
83 programs.ssh.knownHosts = {
85 hostNames = [ "carotte" "carotte.sourcephile.fr" ];
86 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
89 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
90 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
93 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
94 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
102 # Example: nix -L build .#nixosConfigurations.losurdo.config.system.build.toplevel
103 # Example: nix -L build .#nixosConfigurations.losurdo.config.boot.kernelPackages.kernel.configfile
104 # Example: nix -L build .#nixosConfigurations.losurdo.pkgs.hello
105 # Example: nix eval .#nixosConfigurations.losurdo.config.networking.hostName
106 nixosConfigurations = hosts {
107 carotte = hosts/carotte.nix;
108 losurdo = hosts/losurdo.nix;
109 mermet = hosts/mermet.nix;
111 #nixosModule = import nixos/modules.nix;
113 // inputs.flake-utils.lib.eachDefaultSystem (system:
114 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
116 pkgs = import nixpkgs {
119 import nixpkgs/overlays.nix ++
120 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
123 legacyPackages = pkgs;
124 devShell = import ./shell.nix { inherit inputs pkgs; };
125 apps = builtins.mapAttrs (hostName: { config, ... }: let
126 build = config.system.build;
127 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
128 profile = "/nix/var/nix/profiles/system";
130 # Example: nix run .#losurdo.switch
133 program = (pkgs.writeShellScript "switch" (''
136 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
137 nix copy --to ssh://${target} --substitute-on-destination ${build.toplevel}
139 '' + lib.optionalString config.boot.initrd.network.ssh.enable ''
140 # Send the SSH key of the initrd
141 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
142 ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
143 # Send the Wireguard key of the initrd
144 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
145 ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
148 nix-env --profile '${profile}' --set '${build.toplevel}' '&&' \
149 '${profile}'/bin/switch-to-configuration switch
153 # Example: nix run .#carotte.install-sd
156 program = (pkgs.writeShellScript "install-sd" ''
157 export PATH="$PATH:${with pkgs; lib.makeBinPath [coreutils zstd]}"
160 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
161 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
162 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
165 # Example: nix run .#losurdo.sendkeys
168 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
169 program = (pkgs.writeShellScript "sendkeys" ''
171 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
174 }) inputs.self.nixosConfigurations;}