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;
113 (fileFilter (file: lib.any file.hasExt exts) ./domains)
114 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
115 (fileFilter (file: lib.any file.hasExt exts) ./homes)
116 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
117 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
118 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
119 (fileFilter (file: lib.any file.hasExt exts) ./users)
125 # nix -L build .#hello
126 packages = forAllSystems ({ pkgs, ... }: pkgs);
128 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
129 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
130 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
131 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
132 nixosConfigurations =
134 (builtins.attrNames (
135 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
142 # Required to avoid infinite recursion
143 # when `inputs` is used in `imports`.
148 (import (self + "/hosts/${hostName}.nix"))
149 inputs.lanzaboote.nixosModules.lanzaboote
150 inputs.home-manager.nixosModules.home-manager
154 inherit (config.nixpkgs.hostPlatform) system;
155 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
157 overlays = overlays system;
159 pkgs-unstable-latest = import inputs.nixpkgs-unstable-latest.outPath {
161 overlays = overlays system;
166 inherit hostName pkgs-unstable pkgs-unstable-latest;
167 hosts = nixosConfigurations;
168 host = nixosConfigurations.${hostName}._module.args;
171 overlays = overlays config.nixpkgs.hostPlatform.system;
172 config.permittedInsecurePackages = [
173 # Still needed for chatty
174 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
175 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
178 config.allowUnfreePredicate =
180 builtins.elem (lib.getName pkg) [
192 useGlobalPkgs = true;
193 useUserPackages = true;
196 backupFileExtension = "old";
212 # nix -L develop or direnv allow
213 devShells = forAllSystems (
214 { pkgs, system, ... }:
216 default = pkgs.callPackage (self + "/shell.nix") {
223 inherit (checks.${system}.git-hooks-check) shellHook;
228 # nix -L run .#oignon.switch
229 apps = forAllSystems (
230 { pkgs, system, ... }:
236 inherit (config.system) build;
237 scriptApp = scriptName: ps: script: {
240 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
241 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
248 # Example: nix run .#aubergine.switch
249 "switch" = scriptApp "switch" [ ] ''
252 chmod -R g-rwx,o-rwx **/*.gpg
253 trap 'git reset **/*.gpg' EXIT
254 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
256 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
257 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
259 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
261 if ssh ${config.install.target} set -x ';' \
262 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
263 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
264 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
274 ${profile}/bin/switch-to-configuration switch
277 ${build.toplevel}/bin/switch-to-configuration test
279 ssh ${config.install.target} -o ControlPath=none set -x ';' \
280 systemctl stop nixos-fallback.service ';' \
281 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
282 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
283 nix-env --delete-generations 7d --profile ${profile}
286 echo WARNING: switch-to-configuration was not registered at boot
288 ssh ${config.install.target} -o ControlPath=none set -x ';' \
289 systemctl stop nixos-fallback.service
294 ) nixosConfigurations
298 checks = forAllSystems (
300 git-hooks-check = inputs.git-hooks.lib.${system}.run {
303 nixfmt-rfc-style.enable = true;