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 home-manager.inputs.nixpkgs.follows = "nixpkgs";
18 home-manager.url = "github:nix-community/home-manager/release-24.11";
19 nix-formatter-pack.inputs.nixpkgs.follows = "nixpkgs";
20 nix-formatter-pack.url = "github:Gerschtli/nix-formatter-pack";
21 nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
22 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
23 git-hooks.inputs.nixpkgs-stable.follows = "nixpkgs";
24 git-hooks.url = "github:cachix/git-hooks.nix";
25 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
31 remoteNixpkgsPatches = import nixpkgs/patches.nix;
32 localNixpkgsPatches = [
34 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
35 nixpkgsPath = originPkgs.applyPatches {
36 name = "nixpkgs-patched";
37 src = inputs.nixpkgs.outPath;
38 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
40 patch=$(printf '%s\n' ${
41 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
43 sort | sha256sum | cut -c -7)
44 echo "-patch-$patch" >.version-suffix
47 profile = "/nix/var/nix/profiles/system";
48 inherit (inputs.nixpkgs) lib;
51 import nixpkgs/overlays.nix
54 #nixosSystem = lib.nixosSystem;
55 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
58 lib.genAttrs lib.systems.flakeExposed (
62 #pkgs = inputs.nixpkgs.legacyPackages.${system};
63 pkgs = import nixpkgsPath {
65 overlays = overlays system;
94 (fileFilter (file: lib.any file.hasExt exts) ./domains)
95 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
96 (fileFilter (file: lib.any file.hasExt exts) ./homes)
97 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
98 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
99 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
100 (fileFilter (file: lib.any file.hasExt exts) ./users)
106 # nix -L build .#hello
107 packages = forAllSystems ({ pkgs, ... }: pkgs);
109 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
110 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
111 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
112 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
113 nixosConfigurations =
115 (builtins.attrNames (
116 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
123 # Required to avoid infinite recursion
124 # when `inputs` is used in `imports`.
129 (import (self + "/hosts/${hostName}.nix"))
135 hosts = nixosConfigurations;
136 host = nixosConfigurations.${hostName}._module.args;
138 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
139 nixpkgs.config.permittedInsecurePackages = [
140 # Still needed for chatty
141 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
142 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
145 nixpkgs.config.allowUnfreePredicate =
147 builtins.elem (lib.getName pkg) [
159 inputs.home-manager.nixosModules.home-manager
161 home-manager.useGlobalPkgs = true;
162 home-manager.useUserPackages = true;
163 home-manager.verbose = true;
164 #home-manager.force = true;
165 home-manager.backupFileExtension = "old";
166 home-manager.extraSpecialArgs = {
167 inherit hostName inputs;
174 # nix -L develop or direnv allow
175 devShells = forAllSystems (
176 { pkgs, system, ... }:
178 default = pkgs.callPackage (self + "/shell.nix") {
185 inherit (checks.${system}.git-hooks-check) shellHook;
190 # nix -L run .#oignon.switch
191 apps = forAllSystems (
192 { pkgs, system, ... }:
198 inherit (config.system) build;
199 scriptApp = scriptName: ps: script: {
202 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
203 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
210 # Example: nix run .#aubergine.switch
211 "switch" = scriptApp "switch" [ ] ''
214 chmod -R g-rwx,o-rwx **/*.gpg
215 trap 'git reset **/*.gpg' EXIT
216 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
218 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
219 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
221 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
223 if ssh ${config.install.target} set -x ';' \
224 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
225 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
226 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
236 ${profile}/bin/switch-to-configuration switch
239 ${build.toplevel}/bin/switch-to-configuration test
241 ssh ${config.install.target} -o ControlPath=none set -x ';' \
242 systemctl stop nixos-fallback.service ';' \
243 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
244 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
245 nix-env --delete-generations 7d --profile ${profile}
248 echo WARNING: switch-to-configuration was not registered at boot
250 ssh ${config.install.target} -o ControlPath=none set -x ';' \
251 systemctl stop nixos-fallback.service
256 ) nixosConfigurations
260 checks = forAllSystems (
262 git-hooks-check = inputs.git-hooks.lib.${system}.run {
265 nixfmt-rfc-style.enable = true;
272 formatter = forAllSystems (
274 inputs.nix-formatter-pack.lib.mkFormatter {
278 deadnix.enable = true;
279 nixfmt-rfc-style.enable = true;
280 statix.enable = true;