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="
16 doom-emacs.flake = false;
17 doom-emacs.url = "github:hlissner/doom-emacs";
20 url = "github:NicolasGB/jj.nvim";
23 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
24 git-hooks.url = "github:cachix/git-hooks.nix";
25 home-manager.inputs.nixpkgs.follows = "nixpkgs";
26 home-manager.url = "github:nix-community/home-manager/master";
27 #home-manager.url = "git+file:///home/julm/src/nix/home-manager";
28 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
29 #nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
30 nixpkgs.url = "github:NixOS/nixpkgs/9cb344e96d5b6918e94e1bca2d9f3ea1e9615545";
31 nixpkgs-unstable.url = "github:NixOS/nixpkgs/master";
32 nixpkgs-unstable-latest.url = "github:NixOS/nixpkgs/cb82756ecc37fa623f8cf3e88854f9bf7f64af93";
34 url = "github:nix-community/lanzaboote/v0.4.2";
35 inputs.nixpkgs.follows = "nixpkgs";
36 inputs.pre-commit-hooks-nix.follows = "git-hooks";
43 remoteNixpkgsPatches = import nixpkgs/patches.nix;
44 localNixpkgsPatches = [
45 nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch
46 nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch
48 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
49 nixpkgsPath = originPkgs.applyPatches {
50 name = "nixpkgs-patched";
51 src = inputs.nixpkgs.outPath;
52 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
54 patch=$(printf '%s\n' ${
55 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
57 sort | sha256sum | cut -c -7)
58 echo "-patch-$patch" >.version-suffix
61 profile = "/nix/var/nix/profiles/system";
62 inherit (inputs.nixpkgs) lib;
63 overlays = _system: import nixpkgs/overlays.nix;
64 #nixosSystem = lib.nixosSystem;
65 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
68 lib.genAttrs lib.systems.flakeExposed (
72 #pkgs = inputs.nixpkgs.legacyPackages.${system};
73 pkgs = import nixpkgsPath {
75 overlays = overlays system;
106 (fileFilter (file: lib.any file.hasExt exts) ./domains)
107 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
108 (fileFilter (file: lib.any file.hasExt exts) ./homes)
109 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
110 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
111 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
112 (fileFilter (file: lib.any file.hasExt exts) ./users)
118 # nix -L build .#hello
119 packages = forAllSystems ({ pkgs, ... }: pkgs);
121 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
122 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
123 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
124 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
125 nixosConfigurations =
127 (builtins.attrNames (
128 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
135 # Required to avoid infinite recursion
136 # when `inputs` is used in `imports`.
141 (import (self + "/hosts/${hostName}.nix"))
142 inputs.lanzaboote.nixosModules.lanzaboote
143 inputs.home-manager.nixosModules.home-manager
147 inherit (config.nixpkgs.hostPlatform) system;
148 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
150 overlays = overlays system;
152 pkgs-unstable-latest = import inputs.nixpkgs-unstable-latest.outPath {
154 overlays = overlays system;
159 inherit hostName pkgs-unstable pkgs-unstable-latest;
160 hosts = nixosConfigurations;
161 host = nixosConfigurations.${hostName}._module.args;
164 overlays = overlays config.nixpkgs.hostPlatform.system;
165 config.permittedInsecurePackages = [
166 # Still needed for chatty
167 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
168 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
171 config.allowUnfreePredicate =
173 builtins.elem (lib.getName pkg) [
185 useGlobalPkgs = true;
186 useUserPackages = true;
189 backupFileExtension = "old";
205 # nix -L develop or direnv allow
206 devShells = forAllSystems (
207 { pkgs, system, ... }:
209 default = pkgs.callPackage (self + "/shell.nix") {
216 inherit (checks.${system}.git-hooks-check) shellHook;
221 # nix -L run .#oignon.switch
222 apps = forAllSystems (
223 { pkgs, system, ... }:
229 inherit (config.system) build;
230 scriptApp = scriptName: ps: script: {
233 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
234 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
241 # Example: nix run .#aubergine.switch
242 "switch" = scriptApp "switch" [ ] ''
245 chmod -R g-rwx,o-rwx **/*.gpg
246 trap 'git reset **/*.gpg' EXIT
247 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
249 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
250 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
252 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
254 if ssh ${config.install.target} set -x ';' \
255 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
256 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
257 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
267 ${profile}/bin/switch-to-configuration switch
270 ${build.toplevel}/bin/switch-to-configuration test
272 ssh ${config.install.target} -o ControlPath=none set -x ';' \
273 systemctl stop nixos-fallback.service ';' \
274 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
275 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
276 nix-env --delete-generations 7d --profile ${profile}
279 echo WARNING: switch-to-configuration was not registered at boot
281 ssh ${config.install.target} -o ControlPath=none set -x ';' \
282 systemctl stop nixos-fallback.service
287 ) nixosConfigurations
291 checks = forAllSystems (
293 git-hooks-check = inputs.git-hooks.lib.${system}.run {
296 nixfmt-rfc-style.enable = true;