2 description = "julm's Nix configurations for hosts (NixOS) and homes (home-manager)";
6 "https://nix-community.cachix.org"
8 extra-trusted-public-keys = [
9 "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
15 doom-emacs.flake = false;
16 doom-emacs.url = "github:hlissner/doom-emacs";
17 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
18 git-hooks.url = "github:cachix/git-hooks.nix";
19 home-manager.inputs.nixpkgs.follows = "nixpkgs";
20 home-manager.url = "github:nix-community/home-manager/release-24.11";
21 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
22 nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
24 url = "github:nix-community/lanzaboote/v0.4.2";
25 inputs.nixpkgs.follows = "nixpkgs";
32 remoteNixpkgsPatches = import nixpkgs/patches.nix;
33 localNixpkgsPatches = [
35 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
36 nixpkgsPath = originPkgs.applyPatches {
37 name = "nixpkgs-patched";
38 src = inputs.nixpkgs.outPath;
39 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
41 patch=$(printf '%s\n' ${
42 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
44 sort | sha256sum | cut -c -7)
45 echo "-patch-$patch" >.version-suffix
48 profile = "/nix/var/nix/profiles/system";
49 inherit (inputs.nixpkgs) lib;
52 import nixpkgs/overlays.nix
55 #nixosSystem = lib.nixosSystem;
56 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
59 lib.genAttrs lib.systems.flakeExposed (
63 #pkgs = inputs.nixpkgs.legacyPackages.${system};
64 pkgs = import nixpkgsPath {
66 overlays = overlays system;
96 (fileFilter (file: lib.any file.hasExt exts) ./domains)
97 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
98 (fileFilter (file: lib.any file.hasExt exts) ./homes)
99 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
100 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
101 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
102 (fileFilter (file: lib.any file.hasExt exts) ./users)
108 # nix -L build .#hello
109 packages = forAllSystems ({ pkgs, ... }: pkgs);
111 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
112 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
113 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
114 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
115 nixosConfigurations =
117 (builtins.attrNames (
118 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
125 # Required to avoid infinite recursion
126 # when `inputs` is used in `imports`.
131 (import (self + "/hosts/${hostName}.nix"))
132 inputs.lanzaboote.nixosModules.lanzaboote
138 hosts = nixosConfigurations;
139 host = nixosConfigurations.${hostName}._module.args;
141 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
142 nixpkgs.config.permittedInsecurePackages = [
143 # Still needed for chatty
144 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
145 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
148 nixpkgs.config.allowUnfreePredicate =
150 builtins.elem (lib.getName pkg) [
162 inputs.home-manager.nixosModules.home-manager
164 home-manager.useGlobalPkgs = true;
165 home-manager.useUserPackages = true;
166 home-manager.verbose = true;
167 #home-manager.force = true;
168 home-manager.backupFileExtension = "old";
169 home-manager.extraSpecialArgs = {
170 inherit hostName inputs;
177 # nix -L develop or direnv allow
178 devShells = forAllSystems (
179 { pkgs, system, ... }:
181 default = pkgs.callPackage (self + "/shell.nix") {
188 inherit (checks.${system}.git-hooks-check) shellHook;
193 # nix -L run .#oignon.switch
194 apps = forAllSystems (
195 { pkgs, system, ... }:
201 inherit (config.system) build;
202 scriptApp = scriptName: ps: script: {
205 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
206 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
213 # Example: nix run .#aubergine.switch
214 "switch" = scriptApp "switch" [ ] ''
217 chmod -R g-rwx,o-rwx **/*.gpg
218 trap 'git reset **/*.gpg' EXIT
219 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
221 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
222 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
224 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
226 if ssh ${config.install.target} set -x ';' \
227 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
228 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
229 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
239 ${profile}/bin/switch-to-configuration switch
242 ${build.toplevel}/bin/switch-to-configuration test
244 ssh ${config.install.target} -o ControlPath=none set -x ';' \
245 systemctl stop nixos-fallback.service ';' \
246 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
247 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
248 nix-env --delete-generations 7d --profile ${profile}
251 echo WARNING: switch-to-configuration was not registered at boot
253 ssh ${config.install.target} -o ControlPath=none set -x ';' \
254 systemctl stop nixos-fallback.service
259 ) nixosConfigurations
263 checks = forAllSystems (
265 git-hooks-check = inputs.git-hooks.lib.${system}.run {
268 nixfmt-rfc-style.enable = true;