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:rafikdraoui/jj-diffconflicts";
24 url = "github:NicolasGB/jj.nvim";
27 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
28 git-hooks.url = "github:cachix/git-hooks.nix";
29 home-manager.inputs.nixpkgs.follows = "nixpkgs";
30 home-manager.url = "github:nix-community/home-manager/master";
31 #home-manager.url = "git+file:///home/julm/src/nix/home-manager";
32 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
33 #nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
34 nixpkgs.url = "github:NixOS/nixpkgs/9cb344e96d5b6918e94e1bca2d9f3ea1e9615545";
35 nixpkgs-unstable.url = "github:NixOS/nixpkgs/master";
36 nixpkgs-unstable-latest.url = "github:NixOS/nixpkgs/117cc7f94e8072499b0a7aa4c52084fa4e11cc9b";
38 url = "github:nix-community/lanzaboote/v0.4.2";
39 inputs.nixpkgs.follows = "nixpkgs";
40 inputs.pre-commit-hooks-nix.follows = "git-hooks";
47 remoteNixpkgsPatches = import nixpkgs/patches.nix;
48 localNixpkgsPatches = [
49 nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch
50 nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch
52 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
53 nixpkgsPath = originPkgs.applyPatches {
54 name = "nixpkgs-patched";
55 src = inputs.nixpkgs.outPath;
56 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
58 patch=$(printf '%s\n' ${
59 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
61 sort | sha256sum | cut -c -7)
62 echo "-patch-$patch" >.version-suffix
65 profile = "/nix/var/nix/profiles/system";
66 inherit (inputs.nixpkgs) lib;
67 overlays = _system: import nixpkgs/overlays.nix;
68 #nixosSystem = lib.nixosSystem;
69 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
72 lib.genAttrs lib.systems.flakeExposed (
76 #pkgs = inputs.nixpkgs.legacyPackages.${system};
77 pkgs = import nixpkgsPath {
79 overlays = overlays system;
112 (fileFilter (file: lib.any file.hasExt exts) ./domains)
113 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
114 (fileFilter (file: lib.any file.hasExt exts) ./homes)
115 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
116 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
117 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
118 (fileFilter (file: lib.any file.hasExt exts) ./users)
124 # nix -L build .#hello
125 packages = forAllSystems ({ pkgs, ... }: pkgs);
127 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
128 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
129 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
130 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
131 nixosConfigurations =
133 (builtins.attrNames (
134 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
141 # Required to avoid infinite recursion
142 # when `inputs` is used in `imports`.
147 (import (self + "/hosts/${hostName}.nix"))
148 inputs.lanzaboote.nixosModules.lanzaboote
149 inputs.home-manager.nixosModules.home-manager
153 inherit (config.nixpkgs.hostPlatform) system;
154 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
156 overlays = overlays system;
158 pkgs-unstable-latest = import inputs.nixpkgs-unstable-latest.outPath {
160 overlays = overlays system;
165 inherit hostName pkgs-unstable pkgs-unstable-latest;
166 hosts = nixosConfigurations;
167 host = nixosConfigurations.${hostName}._module.args;
170 overlays = overlays config.nixpkgs.hostPlatform.system;
171 config.permittedInsecurePackages = [
172 # Still needed for chatty
173 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
174 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
177 config.allowUnfreePredicate =
179 builtins.elem (lib.getName pkg) [
191 useGlobalPkgs = true;
192 useUserPackages = true;
195 backupFileExtension = "old";
211 # nix -L develop or direnv allow
212 devShells = forAllSystems (
213 { pkgs, system, ... }:
215 default = pkgs.callPackage (self + "/shell.nix") {
222 inherit (checks.${system}.git-hooks-check) shellHook;
227 # nix -L run .#oignon.switch
228 apps = forAllSystems (
229 { pkgs, system, ... }:
235 inherit (config.system) build;
236 scriptApp = scriptName: ps: script: {
239 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
240 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
247 # Example: nix run .#aubergine.switch
248 "switch" = scriptApp "switch" [ ] ''
251 chmod -R g-rwx,o-rwx **/*.gpg
252 trap 'git reset **/*.gpg' EXIT
253 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
255 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
256 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
258 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
260 if ssh ${config.install.target} set -x ';' \
261 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
262 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
263 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
273 ${profile}/bin/switch-to-configuration switch
276 ${build.toplevel}/bin/switch-to-configuration test
278 ssh ${config.install.target} -o ControlPath=none set -x ';' \
279 systemctl stop nixos-fallback.service ';' \
280 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
281 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
282 nix-env --delete-generations 7d --profile ${profile}
285 echo WARNING: switch-to-configuration was not registered at boot
287 ssh ${config.install.target} -o ControlPath=none set -x ';' \
288 systemctl stop nixos-fallback.service
293 ) nixosConfigurations
297 checks = forAllSystems (
299 git-hooks-check = inputs.git-hooks.lib.${system}.run {
302 nixfmt-rfc-style.enable = true;