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-23.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-23.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 radicle-explorer.url = "git+https://seed.radicle.garden/z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git";
25 radicle-explorer.inputs.heartwood.follows = "heartwood";
26 heartwood.url = "git+https://seed.radicle.garden/z3gqcJUoA1n9HaHKufZs5FCSGazv5.git";
27 heartwood.inputs.nixpkgs.follows = "nixpkgs";
32 remoteNixpkgsPatches = import nixpkgs/patches.nix;
33 localNixpkgsPatches = [
35 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
36 nixpkgsPath = originPkgs.applyPatches {
37 name = "nixpkgs-patched";
38 src = inputs.nixpkgs.outPath;
39 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
41 patch=$(printf '%s\n' ${builtins.concatStringsSep " "
42 (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)} |
43 sort | sha256sum | cut -c -7)
44 echo "-patch-$patch" >.version-suffix
47 profile = "/nix/var/nix/profiles/system";
48 inherit (inputs.nixpkgs) lib;
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 = import nixpkgs/overlays.nix ++ [
57 (finalPkgs: previousPkgs: {
58 radicle-full = inputs.heartwood.packages.${system}.radicle-full;
63 self = with lib.fileset; toSource {
66 let exts = [ "clear" "conf" "cred" "crt" "css" "el" "hs" "json" "nix" "patch" "pem" "pub" "sh" "theme" "vim" ]; in
68 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
69 (fileFilter (file: lib.any file.hasExt exts) ./homes)
70 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
71 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
72 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
73 (fileFilter (file: lib.any file.hasExt exts) ./share)
74 (fileFilter (file: lib.any file.hasExt exts) ./users)
80 # nix -L build .#hello
81 packages = forAllSystems ({ pkgs, ... }: pkgs);
83 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
84 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
85 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
86 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
87 nixosConfigurations = lib.genAttrs
88 (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))))
89 (hostName: nixosSystem {
92 # Required to avoid infinite recursion
93 # when `inputs` is used in `imports`.
98 (import (self + "/hosts/${hostName}.nix"))
102 hosts = nixosConfigurations;
103 host = nixosConfigurations.${hostName}._module.args;
105 nixpkgs.overlays = import (self + "/nixpkgs/overlays.nix");
106 nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
116 inputs.home-manager.nixosModules.home-manager
118 home-manager.useGlobalPkgs = true;
119 home-manager.useUserPackages = true;
120 home-manager.verbose = true;
121 home-manager.backupFileExtension = null;
122 home-manager.extraSpecialArgs = {
123 inherit hostName inputs;
129 # nix -L develop or direnv allow
130 devShells = forAllSystems ({ pkgs, system, ... }:
132 default = pkgs.callPackage (self + "/shell.nix")
134 inherit pkgs inputs system nixpkgsPath;
135 inherit (checks.${system}.git-hooks-check) shellHook;
140 # nix -L run .#oignon.switch
141 apps = forAllSystems ({ pkgs, system, ... }:
144 (hostName: { config, ... }:
146 inherit (config.system) build;
147 scriptApp = scriptName: ps: script: {
149 program = (pkgs.writeShellScript "${hostName}-${scriptName}" ''
150 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
157 # Example: nix run .#aubergine.switch
158 "switch" = scriptApp "switch" [ ] ''
161 chmod -R g-rwx,o-rwx **/*.gpg
162 trap 'git reset **/*.gpg' EXIT
163 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
165 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
166 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
168 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
170 if ssh ${config.install.target} set -x ';' \
171 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
172 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
173 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
174 PATH=${with pkgs; lib.makeBinPath [ coreutils nix systemd ]}
176 ${profile}/bin/switch-to-configuration switch
179 ${build.toplevel}/bin/switch-to-configuration test
181 ssh ${config.install.target} -o ControlPath=none set -x ';' \
182 systemctl stop nixos-fallback.service ';' \
183 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
184 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
185 nix-env --delete-generations 7d --profile ${profile}
188 echo WARNING: switch-to-configuration was not registered at boot
190 ssh ${config.install.target} -o ControlPath=none set -x ';' \
191 systemctl stop nixos-fallback.service
196 nixosConfigurations);
199 checks = forAllSystems (args: with args; {
200 git-hooks-check = inputs.git-hooks.lib.${system}.run {
203 nixpkgs-fmt.enable = true;
209 formatter = forAllSystems ({ pkgs, ... }:
210 inputs.nix-formatter-pack.lib.mkFormatter {
214 deadnix.enable = true;
215 nixpkgs-fmt.enable = true;
216 statix.enable = true;