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";
23 nixpkgs-unstable.url = "github:NixOS/nixpkgs/423d2df5b04b4ee7688c3d71396e872afa236a89";
25 url = "github:nix-community/lanzaboote/v0.4.2";
26 inputs.nixpkgs.follows = "nixpkgs";
33 remoteNixpkgsPatches = import nixpkgs/patches.nix;
34 localNixpkgsPatches = [
36 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
37 nixpkgsPath = originPkgs.applyPatches {
38 name = "nixpkgs-patched";
39 src = inputs.nixpkgs.outPath;
40 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
42 patch=$(printf '%s\n' ${
43 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
45 sort | sha256sum | cut -c -7)
46 echo "-patch-$patch" >.version-suffix
49 profile = "/nix/var/nix/profiles/system";
50 inherit (inputs.nixpkgs) lib;
53 import nixpkgs/overlays.nix
56 #nixosSystem = lib.nixosSystem;
57 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
60 lib.genAttrs lib.systems.flakeExposed (
64 #pkgs = inputs.nixpkgs.legacyPackages.${system};
65 pkgs = import nixpkgsPath {
67 overlays = overlays system;
97 (fileFilter (file: lib.any file.hasExt exts) ./domains)
98 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
99 (fileFilter (file: lib.any file.hasExt exts) ./homes)
100 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
101 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
102 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
103 (fileFilter (file: lib.any file.hasExt exts) ./users)
109 # nix -L build .#hello
110 packages = forAllSystems ({ pkgs, ... }: pkgs);
112 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
113 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
114 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
115 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
116 nixosConfigurations =
118 (builtins.attrNames (
119 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
126 # Required to avoid infinite recursion
127 # when `inputs` is used in `imports`.
132 (import (self + "/hosts/${hostName}.nix"))
133 inputs.lanzaboote.nixosModules.lanzaboote
134 inputs.home-manager.nixosModules.home-manager
138 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
139 system = config.nixpkgs.hostPlatform.system;
140 #overlays = overlays system;
145 inherit hostName pkgs-unstable;
146 hosts = nixosConfigurations;
147 host = nixosConfigurations.${hostName}._module.args;
149 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
150 nixpkgs.config.permittedInsecurePackages = [
151 # Still needed for chatty
152 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
153 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
156 nixpkgs.config.allowUnfreePredicate =
158 builtins.elem (lib.getName pkg) [
168 home-manager.useGlobalPkgs = true;
169 home-manager.useUserPackages = true;
170 home-manager.verbose = true;
171 #home-manager.force = true;
172 home-manager.backupFileExtension = "old";
173 home-manager.extraSpecialArgs = {
174 inherit hostName inputs pkgs-unstable;
182 # nix -L develop or direnv allow
183 devShells = forAllSystems (
184 { pkgs, system, ... }:
186 default = pkgs.callPackage (self + "/shell.nix") {
193 inherit (checks.${system}.git-hooks-check) shellHook;
198 # nix -L run .#oignon.switch
199 apps = forAllSystems (
200 { pkgs, system, ... }:
206 inherit (config.system) build;
207 scriptApp = scriptName: ps: script: {
210 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
211 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
218 # Example: nix run .#aubergine.switch
219 "switch" = scriptApp "switch" [ ] ''
222 chmod -R g-rwx,o-rwx **/*.gpg
223 trap 'git reset **/*.gpg' EXIT
224 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
226 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
227 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
229 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
231 if ssh ${config.install.target} set -x ';' \
232 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
233 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
234 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
244 ${profile}/bin/switch-to-configuration switch
247 ${build.toplevel}/bin/switch-to-configuration test
249 ssh ${config.install.target} -o ControlPath=none set -x ';' \
250 systemctl stop nixos-fallback.service ';' \
251 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
252 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
253 nix-env --delete-generations 7d --profile ${profile}
256 echo WARNING: switch-to-configuration was not registered at boot
258 ssh ${config.install.target} -o ControlPath=none set -x ';' \
259 systemctl stop nixos-fallback.service
264 ) nixosConfigurations
268 checks = forAllSystems (
270 git-hooks-check = inputs.git-hooks.lib.${system}.run {
273 nixfmt-rfc-style.enable = true;