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
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 system = config.nixpkgs.hostPlatform.system;
144 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
146 overlays = overlays system;
151 inherit hostName pkgs-unstable;
152 hosts = nixosConfigurations;
153 host = nixosConfigurations.${hostName}._module.args;
155 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
156 nixpkgs.config.permittedInsecurePackages = [
157 # Still needed for chatty
158 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
159 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
162 nixpkgs.config.allowUnfreePredicate =
164 builtins.elem (lib.getName pkg) [
174 home-manager.useGlobalPkgs = true;
175 home-manager.useUserPackages = true;
176 home-manager.verbose = true;
177 #home-manager.force = true;
178 home-manager.backupFileExtension = "old";
179 home-manager.extraSpecialArgs = {
180 inherit hostName inputs pkgs-unstable;
188 # nix -L develop or direnv allow
189 devShells = forAllSystems (
190 { pkgs, system, ... }:
192 default = pkgs.callPackage (self + "/shell.nix") {
199 inherit (checks.${system}.git-hooks-check) shellHook;
204 # nix -L run .#oignon.switch
205 apps = forAllSystems (
206 { pkgs, system, ... }:
212 inherit (config.system) build;
213 scriptApp = scriptName: ps: script: {
216 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
217 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
224 # Example: nix run .#aubergine.switch
225 "switch" = scriptApp "switch" [ ] ''
228 chmod -R g-rwx,o-rwx **/*.gpg
229 trap 'git reset **/*.gpg' EXIT
230 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
232 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
233 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
235 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
237 if ssh ${config.install.target} set -x ';' \
238 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
239 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
240 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
250 ${profile}/bin/switch-to-configuration switch
253 ${build.toplevel}/bin/switch-to-configuration test
255 ssh ${config.install.target} -o ControlPath=none set -x ';' \
256 systemctl stop nixos-fallback.service ';' \
257 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
258 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
259 nix-env --delete-generations 7d --profile ${profile}
262 echo WARNING: switch-to-configuration was not registered at boot
264 ssh ${config.install.target} -o ControlPath=none set -x ';' \
265 systemctl stop nixos-fallback.service
270 ) nixosConfigurations
274 checks = forAllSystems (
276 git-hooks-check = inputs.git-hooks.lib.${system}.run {
279 nixfmt-rfc-style.enable = true;