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";
29 remoteNixpkgsPatches = import nixpkgs/patches.nix;
30 localNixpkgsPatches = [
32 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
33 nixpkgsPath = originPkgs.applyPatches {
34 name = "nixpkgs-patched";
35 src = inputs.nixpkgs.outPath;
36 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
38 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
39 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
40 sort | sha256sum | cut -c -7)
41 echo "-patch-$patch" >.version-suffix
44 profile = "/nix/var/nix/profiles/system";
45 inherit (inputs.nixpkgs) lib;
47 import nixpkgs/overlays.nix ++ [
49 #nixosSystem = lib.nixosSystem;
50 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
51 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
53 #pkgs = inputs.nixpkgs.legacyPackages.${system};
54 pkgs = import nixpkgsPath {
56 overlays = overlays system;
59 self = with lib.fileset; toSource {
62 let exts = [ "clear" "conf" "cred" "crt" "css" "el" "hs" "json" "nix" "patch" "pem" "pub" "sh" "theme" "vim" ]; in
64 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
65 (fileFilter (file: lib.any file.hasExt exts) ./homes)
66 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
67 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
68 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
69 (fileFilter (file: lib.any file.hasExt exts) ./share)
70 (fileFilter (file: lib.any file.hasExt exts) ./users)
76 # nix -L build .#hello
77 packages = forAllSystems ({ pkgs, ... }: pkgs);
79 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
80 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
81 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
82 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
83 nixosConfigurations = lib.genAttrs
84 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))))
85 (hostName: nixosSystem {
88 # Required to avoid infinite recursion
89 # when `inputs` is used in `imports`.
94 (import (self + "/hosts/${hostName}.nix"))
98 hosts = nixosConfigurations;
99 host = nixosConfigurations.${hostName}._module.args;
101 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
102 nixpkgs.config.permittedInsecurePackages = [
103 # Still needed for chatty
104 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
105 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
108 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
118 inputs.home-manager.nixosModules.home-manager
120 home-manager.useGlobalPkgs = true;
121 home-manager.useUserPackages = true;
122 home-manager.verbose = true;
123 #home-manager.force = true;
124 home-manager.backupFileExtension = "old";
125 home-manager.extraSpecialArgs = {
126 inherit hostName inputs;
132 # nix -L develop or direnv allow
133 devShells = forAllSystems ({ pkgs, system, ... }:
135 default = pkgs.callPackage (self + "/shell.nix")
137 inherit pkgs inputs system nixpkgsPath;
138 inherit (checks.${system}.git-hooks-check) shellHook;
143 # nix -L run .#oignon.switch
144 apps = forAllSystems ({ pkgs, system, ... }:
147 (hostName: { config, ... }:
149 inherit (config.system) build;
150 scriptApp = scriptName: ps: script: {
152 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
153 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
160 # Example: nix run .#aubergine.switch
161 "switch" = scriptApp "switch" [ ] ''
164 chmod -R g-rwx,o-rwx **/*.gpg
165 trap 'git reset **/*.gpg' EXIT
166 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
168 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
169 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
171 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
173 if ssh ${config.install.target} set -x ';' \
174 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
175 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
176 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
177 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
179 ${profile}/bin/switch-to-configuration switch
182 ${build.toplevel}/bin/switch-to-configuration test
184 ssh ${config.install.target} -o ControlPath=none set -x ';' \
185 systemctl stop nixos-fallback.service ';' \
186 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
187 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
188 nix-env --delete-generations 7d --profile ${profile}
191 echo WARNING: switch-to-configuration was not registered at boot
193 ssh ${config.install.target} -o ControlPath=none set -x ';' \
194 systemctl stop nixos-fallback.service
199 nixosConfigurations);
202 checks = forAllSystems (args: with args; {
203 git-hooks-check = inputs.git-hooks.lib.${system}.run {
206 nixpkgs-fmt.enable = true;
212 formatter = forAllSystems ({ pkgs, ... }:
213 inputs.nix-formatter-pack.lib.mkFormatter {
217 deadnix.enable = true;
218 nixfmt-rfc-style.enable = true;
219 statix.enable = true;