5 "https://nix-community.cachix.org"
7 extra-trusted-public-keys = [
8 "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
14 doom-emacs.flake = false;
15 doom-emacs.url = "github:hlissner/doom-emacs";
16 home-manager.inputs.nixpkgs.follows = "nixpkgs";
17 home-manager.url = "github:nix-community/home-manager/release-24.11";
18 nix-formatter-pack.inputs.nixpkgs.follows = "nixpkgs";
19 nix-formatter-pack.url = "github:Gerschtli/nix-formatter-pack";
20 nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
21 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
22 git-hooks.inputs.nixpkgs-stable.follows = "nixpkgs";
23 git-hooks.url = "github:cachix/git-hooks.nix";
24 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
30 remoteNixpkgsPatches = import nixpkgs/patches.nix;
31 localNixpkgsPatches = [
33 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
34 nixpkgsPath = originPkgs.applyPatches {
35 name = "nixpkgs-patched";
36 src = inputs.nixpkgs.outPath;
37 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
39 patch=$(printf '%s\n' ${
40 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
42 sort | sha256sum | cut -c -7)
43 echo "-patch-$patch" >.version-suffix
46 profile = "/nix/var/nix/profiles/system";
47 inherit (inputs.nixpkgs) lib;
50 import nixpkgs/overlays.nix
53 #nixosSystem = lib.nixosSystem;
54 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
57 lib.genAttrs lib.systems.flakeExposed (
61 #pkgs = inputs.nixpkgs.legacyPackages.${system};
62 pkgs = import nixpkgsPath {
64 overlays = overlays system;
93 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
94 (fileFilter (file: lib.any file.hasExt exts) ./homes)
95 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
96 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
97 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
98 (fileFilter (file: lib.any file.hasExt exts) ./share)
99 (fileFilter (file: lib.any file.hasExt exts) ./users)
105 # nix -L build .#hello
106 packages = forAllSystems ({ pkgs, ... }: pkgs);
108 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
109 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
110 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
111 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
112 nixosConfigurations =
114 (builtins.attrNames (
115 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
122 # Required to avoid infinite recursion
123 # when `inputs` is used in `imports`.
128 (import (self + "/hosts/${hostName}.nix"))
134 hosts = nixosConfigurations;
135 host = nixosConfigurations.${hostName}._module.args;
137 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
138 nixpkgs.config.permittedInsecurePackages = [
139 # Still needed for chatty
140 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
141 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
144 nixpkgs.config.allowUnfreePredicate =
146 builtins.elem (lib.getName pkg) [
157 inputs.home-manager.nixosModules.home-manager
159 home-manager.useGlobalPkgs = true;
160 home-manager.useUserPackages = true;
161 home-manager.verbose = true;
162 #home-manager.force = true;
163 home-manager.backupFileExtension = "old";
164 home-manager.extraSpecialArgs = {
165 inherit hostName inputs;
172 # nix -L develop or direnv allow
173 devShells = forAllSystems (
174 { pkgs, system, ... }:
176 default = pkgs.callPackage (self + "/shell.nix") {
183 inherit (checks.${system}.git-hooks-check) shellHook;
188 # nix -L run .#oignon.switch
189 apps = forAllSystems (
190 { pkgs, system, ... }:
196 inherit (config.system) build;
197 scriptApp = scriptName: ps: script: {
200 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
201 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
208 # Example: nix run .#aubergine.switch
209 "switch" = scriptApp "switch" [ ] ''
212 chmod -R g-rwx,o-rwx **/*.gpg
213 trap 'git reset **/*.gpg' EXIT
214 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
216 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
217 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
219 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
221 if ssh ${config.install.target} set -x ';' \
222 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
223 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
224 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
234 ${profile}/bin/switch-to-configuration switch
237 ${build.toplevel}/bin/switch-to-configuration test
239 ssh ${config.install.target} -o ControlPath=none set -x ';' \
240 systemctl stop nixos-fallback.service ';' \
241 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
242 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
243 nix-env --delete-generations 7d --profile ${profile}
246 echo WARNING: switch-to-configuration was not registered at boot
248 ssh ${config.install.target} -o ControlPath=none set -x ';' \
249 systemctl stop nixos-fallback.service
254 ) nixosConfigurations
258 checks = forAllSystems (
260 git-hooks-check = inputs.git-hooks.lib.${system}.run {
263 nixfmt-rfc-style.enable = true;
270 formatter = forAllSystems (
272 inputs.nix-formatter-pack.lib.mkFormatter {
276 deadnix.enable = true;
277 nixfmt-rfc-style.enable = true;
278 statix.enable = true;