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.05";
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.05";
21 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
22 git-hooks.inputs.nixpkgs-stable.follows = "nixpkgs";
23 git-hooks.url = "github:cachix/git-hooks.nix";
28 remoteNixpkgsPatches = import nixpkgs/patches.nix;
29 localNixpkgsPatches = [
31 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
32 nixpkgsPath = originPkgs.applyPatches {
33 name = "nixpkgs-patched";
34 src = inputs.nixpkgs.outPath;
35 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
37 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
38 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
39 sort | sha256sum | cut -c -7)
40 echo "-patch-$patch" >.version-suffix
43 profile = "/nix/var/nix/profiles/system";
44 inherit (inputs.nixpkgs) lib;
46 import nixpkgs/overlays.nix ++ [
48 #nixosSystem = lib.nixosSystem;
49 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
50 forAllSystems = f: lib.genAttrs lib.systems.flakeExposed (system: f rec {
52 #pkgs = inputs.nixpkgs.legacyPackages.${system};
53 pkgs = import nixpkgsPath {
55 overlays = overlays system;
58 self = with lib.fileset; toSource {
61 let exts = [ "clear" "conf" "cred" "crt" "css" "el" "hs" "json" "nix" "patch" "pem" "pub" "sh" "theme" "vim" ]; in
63 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
64 (fileFilter (file: lib.any file.hasExt exts) ./homes)
65 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
66 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
67 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
68 (fileFilter (file: lib.any file.hasExt exts) ./share)
69 (fileFilter (file: lib.any file.hasExt exts) ./users)
75 # nix -L build .#hello
76 packages = forAllSystems ({ pkgs, ... }: pkgs);
78 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
79 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
80 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
81 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
82 nixosConfigurations = lib.genAttrs
83 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))))
84 (hostName: nixosSystem {
87 # Required to avoid infinite recursion
88 # when `inputs` is used in `imports`.
93 (import (self + "/hosts/${hostName}.nix"))
97 hosts = nixosConfigurations;
98 host = nixosConfigurations.${hostName}._module.args;
100 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
101 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
111 inputs.home-manager.nixosModules.home-manager
113 home-manager.useGlobalPkgs = true;
114 home-manager.useUserPackages = true;
115 home-manager.verbose = true;
116 #home-manager.force = true;
117 home-manager.backupFileExtension = "old";
118 home-manager.extraSpecialArgs = {
119 inherit hostName inputs;
125 # nix -L develop or direnv allow
126 devShells = forAllSystems ({ pkgs, system, ... }:
128 default = pkgs.callPackage (self + "/shell.nix")
130 inherit pkgs inputs system nixpkgsPath;
131 inherit (checks.${system}.git-hooks-check) shellHook;
136 # nix -L run .#oignon.switch
137 apps = forAllSystems ({ pkgs, system, ... }:
140 (hostName: { config, ... }:
142 inherit (config.system) build;
143 scriptApp = scriptName: ps: script: {
145 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
146 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
153 # Example: nix run .#aubergine.switch
154 "switch" = scriptApp "switch" [ ] ''
157 chmod -R g-rwx,o-rwx **/*.gpg
158 trap 'git reset **/*.gpg' EXIT
159 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
161 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
162 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
164 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
166 if ssh ${config.install.target} set -x ';' \
167 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
168 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
169 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
170 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
172 ${profile}/bin/switch-to-configuration switch
175 ${build.toplevel}/bin/switch-to-configuration test
177 ssh ${config.install.target} -o ControlPath=none set -x ';' \
178 systemctl stop nixos-fallback.service ';' \
179 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
180 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
181 nix-env --delete-generations 7d --profile ${profile}
184 echo WARNING: switch-to-configuration was not registered at boot
186 ssh ${config.install.target} -o ControlPath=none set -x ';' \
187 systemctl stop nixos-fallback.service
192 nixosConfigurations);
195 checks = forAllSystems (args: with args; {
196 git-hooks-check = inputs.git-hooks.lib.${system}.run {
199 nixpkgs-fmt.enable = true;
205 formatter = forAllSystems ({ pkgs, ... }:
206 inputs.nix-formatter-pack.lib.mkFormatter {
210 deadnix.enable = true;
211 nixpkgs-fmt.enable = true;
212 statix.enable = true;