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/master";
21 #home-manager.url = "git+file:///home/julm/src/nix/home-manager";
22 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
23 #nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
24 nixpkgs.url = "github:NixOS/nixpkgs/9cb344e96d5b6918e94e1bca2d9f3ea1e9615545";
25 nixpkgs-unstable.url = "github:NixOS/nixpkgs/master";
26 nixpkgs-unstable-latest.url = "github:NixOS/nixpkgs/cb82756ecc37fa623f8cf3e88854f9bf7f64af93";
28 url = "github:nix-community/lanzaboote/v0.4.2";
29 inputs.nixpkgs.follows = "nixpkgs";
30 inputs.pre-commit-hooks-nix.follows = "git-hooks";
37 remoteNixpkgsPatches = import nixpkgs/patches.nix;
38 localNixpkgsPatches = [
39 nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch
40 nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch
42 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
43 nixpkgsPath = originPkgs.applyPatches {
44 name = "nixpkgs-patched";
45 src = inputs.nixpkgs.outPath;
46 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
48 patch=$(printf '%s\n' ${
49 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
51 sort | sha256sum | cut -c -7)
52 echo "-patch-$patch" >.version-suffix
55 profile = "/nix/var/nix/profiles/system";
56 inherit (inputs.nixpkgs) lib;
59 import nixpkgs/overlays.nix
62 #nixosSystem = lib.nixosSystem;
63 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
66 lib.genAttrs lib.systems.flakeExposed (
70 #pkgs = inputs.nixpkgs.legacyPackages.${system};
71 pkgs = import nixpkgsPath {
73 overlays = overlays system;
103 (fileFilter (file: lib.any file.hasExt exts) ./domains)
104 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
105 (fileFilter (file: lib.any file.hasExt exts) ./homes)
106 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
107 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
108 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
109 (fileFilter (file: lib.any file.hasExt exts) ./users)
115 # nix -L build .#hello
116 packages = forAllSystems ({ pkgs, ... }: pkgs);
118 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
119 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
120 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
121 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
122 nixosConfigurations =
124 (builtins.attrNames (
125 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
132 # Required to avoid infinite recursion
133 # when `inputs` is used in `imports`.
138 (import (self + "/hosts/${hostName}.nix"))
139 inputs.lanzaboote.nixosModules.lanzaboote
140 inputs.home-manager.nixosModules.home-manager
144 system = config.nixpkgs.hostPlatform.system;
145 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
147 overlays = overlays system;
149 pkgs-unstable-latest = import inputs.nixpkgs-unstable-latest.outPath {
151 overlays = overlays system;
156 inherit hostName pkgs-unstable pkgs-unstable-latest;
157 hosts = nixosConfigurations;
158 host = nixosConfigurations.${hostName}._module.args;
160 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
161 nixpkgs.config.permittedInsecurePackages = [
162 # Still needed for chatty
163 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
164 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
167 nixpkgs.config.allowUnfreePredicate =
169 builtins.elem (lib.getName pkg) [
179 home-manager.useGlobalPkgs = true;
180 home-manager.useUserPackages = true;
181 home-manager.verbose = true;
182 #home-manager.force = true;
183 home-manager.backupFileExtension = "old";
184 home-manager.extraSpecialArgs = {
198 # nix -L develop or direnv allow
199 devShells = forAllSystems (
200 { pkgs, system, ... }:
202 default = pkgs.callPackage (self + "/shell.nix") {
209 inherit (checks.${system}.git-hooks-check) shellHook;
214 # nix -L run .#oignon.switch
215 apps = forAllSystems (
216 { pkgs, system, ... }:
222 inherit (config.system) build;
223 scriptApp = scriptName: ps: script: {
226 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
227 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
234 # Example: nix run .#aubergine.switch
235 "switch" = scriptApp "switch" [ ] ''
238 chmod -R g-rwx,o-rwx **/*.gpg
239 trap 'git reset **/*.gpg' EXIT
240 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
242 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
243 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
245 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
247 if ssh ${config.install.target} set -x ';' \
248 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
249 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
250 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
260 ${profile}/bin/switch-to-configuration switch
263 ${build.toplevel}/bin/switch-to-configuration test
265 ssh ${config.install.target} -o ControlPath=none set -x ';' \
266 systemctl stop nixos-fallback.service ';' \
267 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
268 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
269 nix-env --delete-generations 7d --profile ${profile}
272 echo WARNING: switch-to-configuration was not registered at boot
274 ssh ${config.install.target} -o ControlPath=none set -x ';' \
275 systemctl stop nixos-fallback.service
280 ) nixosConfigurations
284 checks = forAllSystems (
286 git-hooks-check = inputs.git-hooks.lib.${system}.run {
289 nixfmt-rfc-style.enable = true;