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";
28 remoteNixpkgsPatches = import nixpkgs/patches.nix;
29 localNixpkgsPatches = [
31 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
32 nixpkgsPath = originPkgs.applyPatches {
33 name = "nixpkgs-patched";
34 src = inputs.nixpkgs.outPath;
35 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
37 patch=$(printf '%s\n' ${
38 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
40 sort | sha256sum | cut -c -7)
41 echo "-patch-$patch" >.version-suffix
44 profile = "/nix/var/nix/profiles/system";
45 inherit (inputs.nixpkgs) lib;
48 import nixpkgs/overlays.nix
51 #nixosSystem = lib.nixosSystem;
52 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
55 lib.genAttrs lib.systems.flakeExposed (
59 #pkgs = inputs.nixpkgs.legacyPackages.${system};
60 pkgs = import nixpkgsPath {
62 overlays = overlays system;
92 (fileFilter (file: lib.any file.hasExt exts) ./domains)
93 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
94 (fileFilter (file: lib.any file.hasExt exts) ./homes)
95 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
96 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
97 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
98 (fileFilter (file: lib.any file.hasExt exts) ./users)
104 # nix -L build .#hello
105 packages = forAllSystems ({ pkgs, ... }: pkgs);
107 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
108 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
109 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
110 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
111 nixosConfigurations =
113 (builtins.attrNames (
114 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
121 # Required to avoid infinite recursion
122 # when `inputs` is used in `imports`.
127 (import (self + "/hosts/${hostName}.nix"))
133 hosts = nixosConfigurations;
134 host = nixosConfigurations.${hostName}._module.args;
136 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
137 nixpkgs.config.permittedInsecurePackages = [
138 # Still needed for chatty
139 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
140 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
143 nixpkgs.config.allowUnfreePredicate =
145 builtins.elem (lib.getName pkg) [
157 inputs.home-manager.nixosModules.home-manager
159 home-manager.useGlobalPkgs = true;
160 home-manager.useUserPackages = true;
161 home-manager.verbose = true;
162 #home-manager.force = true;
163 home-manager.backupFileExtension = "old";
164 home-manager.extraSpecialArgs = {
165 inherit hostName inputs;
172 # nix -L develop or direnv allow
173 devShells = forAllSystems (
174 { pkgs, system, ... }:
176 default = pkgs.callPackage (self + "/shell.nix") {
183 inherit (checks.${system}.git-hooks-check) shellHook;
188 # nix -L run .#oignon.switch
189 apps = forAllSystems (
190 { pkgs, system, ... }:
196 inherit (config.system) build;
197 scriptApp = scriptName: ps: script: {
200 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
201 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
208 # Example: nix run .#aubergine.switch
209 "switch" = scriptApp "switch" [ ] ''
212 chmod -R g-rwx,o-rwx **/*.gpg
213 trap 'git reset **/*.gpg' EXIT
214 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
216 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
217 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
219 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
221 if ssh ${config.install.target} set -x ';' \
222 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
223 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
224 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
234 ${profile}/bin/switch-to-configuration switch
237 ${build.toplevel}/bin/switch-to-configuration test
239 ssh ${config.install.target} -o ControlPath=none set -x ';' \
240 systemctl stop nixos-fallback.service ';' \
241 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
242 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
243 nix-env --delete-generations 7d --profile ${profile}
246 echo WARNING: switch-to-configuration was not registered at boot
248 ssh ${config.install.target} -o ControlPath=none set -x ';' \
249 systemctl stop nixos-fallback.service
254 ) nixosConfigurations
258 checks = forAllSystems (
260 git-hooks-check = inputs.git-hooks.lib.${system}.run {
263 nixfmt-rfc-style.enable = true;