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-25.05";
21 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
22 #nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
23 nixpkgs.url = "github:NixOS/nixpkgs/f34483be5ee2418a563545a56743b7b59c549935";
24 nixpkgs-unstable.url = "github:NixOS/nixpkgs/423d2df5b04b4ee7688c3d71396e872afa236a89";
26 url = "github:nix-community/lanzaboote/v0.4.2";
27 inputs.nixpkgs.follows = "nixpkgs";
34 remoteNixpkgsPatches = import nixpkgs/patches.nix;
35 localNixpkgsPatches = [
36 nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch
37 nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch
38 nixpkgs/patches/syncoid/0001-nixos-sanoid-add-utilities-useful-to-syncoid.patch
39 nixpkgs/patches/syncoid/0002-nixos-syncoid-use-DynamicUser.patch
41 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
42 nixpkgsPath = originPkgs.applyPatches {
43 name = "nixpkgs-patched";
44 src = inputs.nixpkgs.outPath;
45 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
47 patch=$(printf '%s\n' ${
48 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
50 sort | sha256sum | cut -c -7)
51 echo "-patch-$patch" >.version-suffix
54 profile = "/nix/var/nix/profiles/system";
55 inherit (inputs.nixpkgs) lib;
58 import nixpkgs/overlays.nix
61 #nixosSystem = lib.nixosSystem;
62 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
65 lib.genAttrs lib.systems.flakeExposed (
69 #pkgs = inputs.nixpkgs.legacyPackages.${system};
70 pkgs = import nixpkgsPath {
72 overlays = overlays system;
102 (fileFilter (file: lib.any file.hasExt exts) ./domains)
103 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
104 (fileFilter (file: lib.any file.hasExt exts) ./homes)
105 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
106 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
107 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
108 (fileFilter (file: lib.any file.hasExt exts) ./users)
114 # nix -L build .#hello
115 packages = forAllSystems ({ pkgs, ... }: pkgs);
117 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
118 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
119 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
120 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
121 nixosConfigurations =
123 (builtins.attrNames (
124 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
131 # Required to avoid infinite recursion
132 # when `inputs` is used in `imports`.
137 (import (self + "/hosts/${hostName}.nix"))
138 inputs.lanzaboote.nixosModules.lanzaboote
139 inputs.home-manager.nixosModules.home-manager
143 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
144 system = config.nixpkgs.hostPlatform.system;
145 #overlays = overlays system;
150 inherit hostName pkgs-unstable;
151 hosts = nixosConfigurations;
152 host = nixosConfigurations.${hostName}._module.args;
154 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
155 nixpkgs.config.permittedInsecurePackages = [
156 # Still needed for chatty
157 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
158 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
161 nixpkgs.config.allowUnfreePredicate =
163 builtins.elem (lib.getName pkg) [
173 home-manager.useGlobalPkgs = true;
174 home-manager.useUserPackages = true;
175 home-manager.verbose = true;
176 #home-manager.force = true;
177 home-manager.backupFileExtension = "old";
178 home-manager.extraSpecialArgs = {
179 inherit hostName inputs pkgs-unstable;
187 # nix -L develop or direnv allow
188 devShells = forAllSystems (
189 { pkgs, system, ... }:
191 default = pkgs.callPackage (self + "/shell.nix") {
198 inherit (checks.${system}.git-hooks-check) shellHook;
203 # nix -L run .#oignon.switch
204 apps = forAllSystems (
205 { pkgs, system, ... }:
211 inherit (config.system) build;
212 scriptApp = scriptName: ps: script: {
215 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
216 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
223 # Example: nix run .#aubergine.switch
224 "switch" = scriptApp "switch" [ ] ''
227 chmod -R g-rwx,o-rwx **/*.gpg
228 trap 'git reset **/*.gpg' EXIT
229 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
231 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
232 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
234 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
236 if ssh ${config.install.target} set -x ';' \
237 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
238 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
239 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
249 ${profile}/bin/switch-to-configuration switch
252 ${build.toplevel}/bin/switch-to-configuration test
254 ssh ${config.install.target} -o ControlPath=none set -x ';' \
255 systemctl stop nixos-fallback.service ';' \
256 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
257 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
258 nix-env --delete-generations 7d --profile ${profile}
261 echo WARNING: switch-to-configuration was not registered at boot
263 ssh ${config.install.target} -o ControlPath=none set -x ';' \
264 systemctl stop nixos-fallback.service
269 ) nixosConfigurations
273 checks = forAllSystems (
275 git-hooks-check = inputs.git-hooks.lib.${system}.run {
278 nixfmt-rfc-style.enable = true;