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";
18 url = "github:NicolasGB/jj.nvim";
22 url = "github:mvllow/modes.nvim";
26 solarized-osaka-nvim = {
27 url = "github:craftzdog/solarized-osaka.nvim";
31 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
32 git-hooks.url = "github:cachix/git-hooks.nix";
33 home-manager.inputs.nixpkgs.follows = "nixpkgs";
34 home-manager.url = "github:nix-community/home-manager/master";
35 #home-manager.url = "git+file:///home/julm/src/nix/home-manager";
36 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
37 #nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
38 nixpkgs.url = "github:NixOS/nixpkgs/9cb344e96d5b6918e94e1bca2d9f3ea1e9615545";
39 nixpkgs-unstable.url = "github:NixOS/nixpkgs/master";
40 nixpkgs-unstable-latest.url = "github:NixOS/nixpkgs/cb82756ecc37fa623f8cf3e88854f9bf7f64af93";
42 url = "github:nix-community/lanzaboote/v0.4.2";
43 inputs.nixpkgs.follows = "nixpkgs";
44 inputs.pre-commit-hooks-nix.follows = "git-hooks";
51 remoteNixpkgsPatches = import nixpkgs/patches.nix;
52 localNixpkgsPatches = [
53 nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch
54 nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch
56 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
57 nixpkgsPath = originPkgs.applyPatches {
58 name = "nixpkgs-patched";
59 src = inputs.nixpkgs.outPath;
60 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
62 patch=$(printf '%s\n' ${
63 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
65 sort | sha256sum | cut -c -7)
66 echo "-patch-$patch" >.version-suffix
69 profile = "/nix/var/nix/profiles/system";
70 inherit (inputs.nixpkgs) lib;
71 overlays = _system: import nixpkgs/overlays.nix;
72 #nixosSystem = lib.nixosSystem;
73 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
76 lib.genAttrs lib.systems.flakeExposed (
80 #pkgs = inputs.nixpkgs.legacyPackages.${system};
81 pkgs = import nixpkgsPath {
83 overlays = overlays system;
114 (fileFilter (file: lib.any file.hasExt exts) ./domains)
115 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
116 (fileFilter (file: lib.any file.hasExt exts) ./homes)
117 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
118 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
119 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
120 (fileFilter (file: lib.any file.hasExt exts) ./users)
126 # nix -L build .#hello
127 packages = forAllSystems ({ pkgs, ... }: pkgs);
129 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
130 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
131 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
132 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
133 nixosConfigurations =
135 (builtins.attrNames (
136 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
143 # Required to avoid infinite recursion
144 # when `inputs` is used in `imports`.
149 (import (self + "/hosts/${hostName}.nix"))
150 inputs.lanzaboote.nixosModules.lanzaboote
151 inputs.home-manager.nixosModules.home-manager
155 inherit (config.nixpkgs.hostPlatform) system;
156 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
158 overlays = overlays system;
160 pkgs-unstable-latest = import inputs.nixpkgs-unstable-latest.outPath {
162 overlays = overlays system;
167 inherit hostName pkgs-unstable pkgs-unstable-latest;
168 hosts = nixosConfigurations;
169 host = nixosConfigurations.${hostName}._module.args;
172 overlays = overlays config.nixpkgs.hostPlatform.system;
173 config.permittedInsecurePackages = [
174 # Still needed for chatty
175 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
176 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
179 config.allowUnfreePredicate =
181 builtins.elem (lib.getName pkg) [
193 useGlobalPkgs = true;
194 useUserPackages = true;
197 backupFileExtension = "old";
213 # nix -L develop or direnv allow
214 devShells = forAllSystems (
215 { pkgs, system, ... }:
217 default = pkgs.callPackage (self + "/shell.nix") {
224 inherit (checks.${system}.git-hooks-check) shellHook;
229 # nix -L run .#oignon.switch
230 apps = forAllSystems (
231 { pkgs, system, ... }:
237 inherit (config.system) build;
238 scriptApp = scriptName: ps: script: {
241 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
242 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
249 # Example: nix run .#aubergine.switch
250 "switch" = scriptApp "switch" [ ] ''
253 chmod -R g-rwx,o-rwx **/*.gpg
254 trap 'git reset **/*.gpg' EXIT
255 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
257 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
258 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
260 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
262 if ssh ${config.install.target} set -x ';' \
263 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
264 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
265 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
275 ${profile}/bin/switch-to-configuration switch
278 ${build.toplevel}/bin/switch-to-configuration test
280 ssh ${config.install.target} -o ControlPath=none set -x ';' \
281 systemctl stop nixos-fallback.service ';' \
282 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
283 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
284 nix-env --delete-generations 7d --profile ${profile}
287 echo WARNING: switch-to-configuration was not registered at boot
289 ssh ${config.install.target} -o ControlPath=none set -x ';' \
290 systemctl stop nixos-fallback.service
295 ) nixosConfigurations
299 checks = forAllSystems (
301 git-hooks-check = inputs.git-hooks.lib.${system}.run {
304 nixfmt-rfc-style.enable = true;