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";
27 url = "github:nix-community/lanzaboote/v0.4.2";
28 inputs.nixpkgs.follows = "nixpkgs";
29 inputs.pre-commit-hooks-nix.follows = "git-hooks";
36 remoteNixpkgsPatches = import nixpkgs/patches.nix;
37 localNixpkgsPatches = [
38 nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch
39 nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch
40 nixpkgs/patches/syncoid/0001-nixos-sanoid-add-utilities-useful-to-syncoid.patch
41 nixpkgs/patches/syncoid/0002-nixos-syncoid-use-DynamicUser.patch
43 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
44 nixpkgsPath = originPkgs.applyPatches {
45 name = "nixpkgs-patched";
46 src = inputs.nixpkgs.outPath;
47 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
49 patch=$(printf '%s\n' ${
50 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
52 sort | sha256sum | cut -c -7)
53 echo "-patch-$patch" >.version-suffix
56 profile = "/nix/var/nix/profiles/system";
57 inherit (inputs.nixpkgs) lib;
60 import nixpkgs/overlays.nix
63 #nixosSystem = lib.nixosSystem;
64 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
67 lib.genAttrs lib.systems.flakeExposed (
71 #pkgs = inputs.nixpkgs.legacyPackages.${system};
72 pkgs = import nixpkgsPath {
74 overlays = overlays system;
104 (fileFilter (file: lib.any file.hasExt exts) ./domains)
105 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
106 (fileFilter (file: lib.any file.hasExt exts) ./homes)
107 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
108 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
109 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
110 (fileFilter (file: lib.any file.hasExt exts) ./users)
116 # nix -L build .#hello
117 packages = forAllSystems ({ pkgs, ... }: pkgs);
119 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
120 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
121 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
122 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
123 nixosConfigurations =
125 (builtins.attrNames (
126 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
133 # Required to avoid infinite recursion
134 # when `inputs` is used in `imports`.
139 (import (self + "/hosts/${hostName}.nix"))
140 inputs.lanzaboote.nixosModules.lanzaboote
141 inputs.home-manager.nixosModules.home-manager
145 system = config.nixpkgs.hostPlatform.system;
146 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
148 overlays = overlays system;
153 inherit hostName pkgs-unstable;
154 hosts = nixosConfigurations;
155 host = nixosConfigurations.${hostName}._module.args;
157 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
158 nixpkgs.config.permittedInsecurePackages = [
159 # Still needed for chatty
160 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
161 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
164 nixpkgs.config.allowUnfreePredicate =
166 builtins.elem (lib.getName pkg) [
176 home-manager.useGlobalPkgs = true;
177 home-manager.useUserPackages = true;
178 home-manager.verbose = true;
179 #home-manager.force = true;
180 home-manager.backupFileExtension = "old";
181 home-manager.extraSpecialArgs = {
182 inherit hostName inputs pkgs-unstable;
190 # nix -L develop or direnv allow
191 devShells = forAllSystems (
192 { pkgs, system, ... }:
194 default = pkgs.callPackage (self + "/shell.nix") {
201 inherit (checks.${system}.git-hooks-check) shellHook;
206 # nix -L run .#oignon.switch
207 apps = forAllSystems (
208 { pkgs, system, ... }:
214 inherit (config.system) build;
215 scriptApp = scriptName: ps: script: {
218 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
219 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
226 # Example: nix run .#aubergine.switch
227 "switch" = scriptApp "switch" [ ] ''
230 chmod -R g-rwx,o-rwx **/*.gpg
231 trap 'git reset **/*.gpg' EXIT
232 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
234 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
235 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
237 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
239 if ssh ${config.install.target} set -x ';' \
240 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
241 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
242 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
252 ${profile}/bin/switch-to-configuration switch
255 ${build.toplevel}/bin/switch-to-configuration test
257 ssh ${config.install.target} -o ControlPath=none set -x ';' \
258 systemctl stop nixos-fallback.service ';' \
259 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
260 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
261 nix-env --delete-generations 7d --profile ${profile}
264 echo WARNING: switch-to-configuration was not registered at boot
266 ssh ${config.install.target} -o ControlPath=none set -x ';' \
267 systemctl stop nixos-fallback.service
272 ) nixosConfigurations
276 checks = forAllSystems (
278 git-hooks-check = inputs.git-hooks.lib.${system}.run {
281 nixfmt-rfc-style.enable = true;