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