2 # Pin down nixpkgs from github, instead of using global, system or user registries.
3 inputs.nixpkgs.url = "github:NixOS/nixpkgs/5cf90a60e5ddf68fbfc04d643970136bf00ba315";
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.doom-emacs.follows = "julm-nix/doom-emacs";
12 inputs.nix-doom-emacs.follows = "julm-nix/nix-doom-emacs";
13 inputs.nix-doom-emacs.inputs.doom-emacs.follows = "julm-nix/doom-emacs";
14 inputs.emacs-overlay.follows = "julm-nix/emacs-overlay";
15 #inputs.shell = { type = "path"; path = "./shell"; flake = false; };
16 #inputs.secrets = { type = "path"; path = "./sec"; flake = false; };
17 #inputs.pass = { type = "path"; path = "./pass"; flake = false; };
18 inputs.shell.url = "path:./shell";
19 inputs.shell.flake = false;
20 inputs.secrets.type = "path";
21 inputs.secrets.path = "/home/julm/work/sourcephile/nix/sec";
22 inputs.secrets.flake = false;
23 inputs.pass.type = "path";
24 inputs.pass.path = "/home/julm/work/sourcephile/nix/pass";
25 inputs.pass.flake = false;
28 remoteNixpkgsPatches = import nixpkgs/patches.nix;
29 localNixpkgsPatches = [
30 nixpkgs/patches/sourcehut.diff
31 nixpkgs/patches/systemd-coredump.diff
33 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
34 nixpkgsPath = originPkgs.applyPatches {
35 name = "nixpkgs-patched";
37 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
39 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
40 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
41 sort | sha256sum | cut -c -7)
42 echo "+patch-$patch" >.version-suffix
46 hosts = builtins.mapAttrs (hostName: hostConfig:
47 let cfg = import hostConfig { inherit inputs hostName nixpkgsPath; }; in
48 import (nixpkgsPath + "/nixos/lib/eval-config.nix") (lib.recursiveUpdate cfg {
50 inherit hostName inputs;
51 private = "/root/private"; # Kept out of /nix/store
53 modules = cfg.modules ++ [
55 config._module.args = {
56 hosts = inputs.self.nixosConfigurations;
57 host = inputs.self.nixosConfigurations.${hostName}._module.args;
60 inputs.home-manager.nixosModules.home-manager
62 home-manager.useGlobalPkgs = true;
63 home-manager.useUserPackages = true;
64 home-manager.verbose = true;
65 home-manager.backupFileExtension = null;
66 home-manager.extraSpecialArgs = {
67 inherit hostName inputs;
71 nix.package = pkgs.nixUnstable;
73 import nixpkgs/overlays.nix ++
74 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
75 system.nixos.versionSuffix = ".${
76 lib.substring 0 8 (inputs.self.lastModifiedDate or inputs.self.lastModified)}.${
77 inputs.self.shortRev or "dirty"}";
78 system.nixos.revision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
79 # Let 'nixos-version --json' know about the Git revision of this flake.
80 system.configurationRevision = lib.mkIf (inputs.self ? rev) inputs.self.rev;
81 security.gnupg.agent.enable = true;
82 security.gnupg.store = inputs.pass + "/hosts/${hostName}";
84 system.configurationRevision =
87 else throw "Refusing to build from a dirty Git tree!";
89 programs.ssh.knownHosts = {
91 hostNames = [ "carotte" "carotte.sourcephile.fr" ];
92 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKnnS0w9zm5KuWwlfJu+qEXC0asESQySPp76szyMTE3J";
95 hostNames = [ "mermet" "mermet.sourcephile.fr" ];
96 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFvKN2sIpH782MFjaOpcty1Hs/T/TPNJpXI08H3O3oxl";
99 hostNames = [ "losurdo" "losurdo.sourcephile.fr" ];
100 publicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHJkAq1T0Dxozt4RPylvWrUmeuejiG+n/owb3ucnWP9F";
108 # Example: nix -L build .#nixosConfigurations.losurdo.config.system.build.toplevel
109 # Example: nix -L build .#nixosConfigurations.losurdo.config.boot.kernelPackages.kernel.configfile
110 # Example: nix -L build .#nixosConfigurations.losurdo.pkgs.hello
111 # Example: nix eval .#nixosConfigurations.losurdo.config.networking.hostName
112 nixosConfigurations = hosts {
113 carotte = hosts/carotte.nix;
114 losurdo = hosts/losurdo.nix;
115 mermet = hosts/mermet.nix;
117 #nixosModule = import nixos/modules.nix;
119 // inputs.flake-utils.lib.eachDefaultSystem (system:
120 #let pkgs = inputs.nixpkgs.legacyPackages.${system}; in
122 pkgs = import nixpkgsPath {
125 import nixpkgs/overlays.nix ++
126 import (inputs.julm-nix + "/nixpkgs/overlays.nix");
129 legacyPackages = pkgs;
130 devShell = import ./shell.nix { inherit inputs pkgs; };
131 apps = builtins.mapAttrs (hostName: { config, ... }: let
132 build = config.system.build;
133 target = "\"\${TARGET:-root@${config.networking.hostName}.${config.networking.domain}}\"";
134 profile = "/nix/var/nix/profiles/system";
136 # Example: nix run .#losurdo.switch
139 program = (pkgs.writeShellScript "switch" (''
142 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
143 nix copy --to ssh://${target} --substitute-on-destination ${build.toplevel}
145 '' + lib.optionalString config.boot.initrd.network.ssh.enable ''
146 # Send the SSH key of the initrd
147 gpg --decrypt '${config.security.gnupg.store}/initrd/ssh.key.gpg' |
148 ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/ssh.key
149 # Send the Wireguard key of the initrd
150 gpg --decrypt '${config.security.gnupg.store}/wireguard/wg-intra/privateKey.gpg' |
151 ssh ${target} install -D -m 400 -o root -g root /dev/stdin /root/initrd/wg-intra.key
154 nix-env --profile '${profile}' --set '${build.toplevel}' '&&' \
155 '${profile}'/bin/switch-to-configuration switch
159 # Example: nix run .#carotte.install-sd
162 program = (pkgs.writeShellScript "install-sd" ''
163 export PATH="$PATH:${with pkgs; lib.makeBinPath [coreutils zstd]}"
166 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.sdImage}
167 unzstd --stdout ${build.sdImage}/sd-image/*.img.zst |
168 sudo -k dd conv=notrunc oflag=direct,sync status=progress of="''${1:-/dev/mmcblk0}"
171 # Example: nix run .#losurdo.sendkeys
174 #program = config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys";
175 program = (pkgs.writeShellScript "sendkeys" ''
177 ${pkgs.bash}/bin/bash -eux ${config.security.gnupg.agent.sendKeys + "/bin/gnupg-agent-sendKeys"}
180 }) inputs.self.nixosConfigurations;}