]> Git — Sourcephile - julm/julm-nix.git/blob - flake.nix
nan2gua1: blender: add
[julm/julm-nix.git] / flake.nix
1 {
2 description = "julm's Nix configurations for hosts (NixOS) and homes (home-manager)";
3 /*
4 nixConfig = {
5 extra-substituters = [
6 "https://nix-community.cachix.org"
7 ];
8 extra-trusted-public-keys = [
9 "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
10 ];
11 };
12 */
13
14 inputs = {
15 doom-emacs.flake = false;
16 doom-emacs.url = "github:hlissner/doom-emacs";
17 git-hooks.inputs.nixpkgs.follows = "nixpkgs";
18 git-hooks.url = "github:cachix/git-hooks.nix";
19 home-manager.inputs.nixpkgs.follows = "nixpkgs";
20 home-manager.url = "github:nix-community/home-manager/master";
21 #home-manager.url = "git+file:///home/julm/src/nix/home-manager";
22 nixos-hardware.url = "github:NixOS/nixos-hardware/master";
23 #nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
24 nixpkgs.url = "github:NixOS/nixpkgs/9cb344e96d5b6918e94e1bca2d9f3ea1e9615545";
25 nixpkgs-unstable.url = "github:NixOS/nixpkgs/master";
26 nixpkgs-unstable-latest.url = "github:NixOS/nixpkgs/cb82756ecc37fa623f8cf3e88854f9bf7f64af93";
27 lanzaboote = {
28 url = "github:nix-community/lanzaboote/v0.4.2";
29 inputs.nixpkgs.follows = "nixpkgs";
30 inputs.pre-commit-hooks-nix.follows = "git-hooks";
31 };
32 };
33
34 outputs =
35 inputs:
36 let
37 remoteNixpkgsPatches = import nixpkgs/patches.nix;
38 localNixpkgsPatches = [
39 nixpkgs/patches/openvpn/0001-nixos-netns-init-module-to-manage-network-namespaces.patch
40 nixpkgs/patches/openvpn/0002-nixos-openvpn-add-netns-support.patch
41 ];
42 originPkgs = inputs.nixpkgs.legacyPackages."x86_64-linux";
43 nixpkgsPath = originPkgs.applyPatches {
44 name = "nixpkgs-patched";
45 src = inputs.nixpkgs.outPath;
46 patches = map originPkgs.fetchpatch remoteNixpkgsPatches ++ localNixpkgsPatches;
47 postPatch = ''
48 patch=$(printf '%s\n' ${
49 builtins.concatStringsSep " " (map (p: p.sha256) remoteNixpkgsPatches ++ localNixpkgsPatches)
50 } |
51 sort | sha256sum | cut -c -7)
52 echo "-patch-$patch" >.version-suffix
53 '';
54 };
55 profile = "/nix/var/nix/profiles/system";
56 inherit (inputs.nixpkgs) lib;
57 overlays =
58 system:
59 import nixpkgs/overlays.nix
60 ++ [
61 ];
62 #nixosSystem = lib.nixosSystem;
63 nixosSystem = import (nixpkgsPath + "/nixos/lib/eval-config.nix");
64 forAllSystems =
65 f:
66 lib.genAttrs lib.systems.flakeExposed (
67 system:
68 f rec {
69 inherit system;
70 #pkgs = inputs.nixpkgs.legacyPackages.${system};
71 pkgs = import nixpkgsPath {
72 inherit system;
73 overlays = overlays system;
74 };
75 }
76 );
77 self =
78 with lib.fileset;
79 toSource {
80 root = ./.;
81 fileset =
82 let
83 exts = [
84 "clear"
85 "conf"
86 "cred"
87 "crt"
88 "css"
89 "el"
90 "hs"
91 "json"
92 "lua"
93 "nix"
94 "patch"
95 "pem"
96 "pub"
97 "sh"
98 "theme"
99 "vim"
100 ];
101 in
102 unions [
103 (fileFilter (file: lib.any file.hasExt exts) ./domains)
104 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
105 (fileFilter (file: lib.any file.hasExt exts) ./homes)
106 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
107 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
108 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
109 (fileFilter (file: lib.any file.hasExt exts) ./users)
110 ./shell.nix
111 ];
112 };
113 in
114 rec {
115 # nix -L build .#hello
116 packages = forAllSystems ({ pkgs, ... }: pkgs);
117
118 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
119 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
120 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
121 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
122 nixosConfigurations =
123 lib.genAttrs
124 (builtins.attrNames (
125 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
126 ))
127 (
128 hostName:
129 nixosSystem {
130 system = null;
131 specialArgs = {
132 # Required to avoid infinite recursion
133 # when `inputs` is used in `imports`.
134 inherit inputs;
135 };
136 modules = [
137 nixos/default.nix
138 (import (self + "/hosts/${hostName}.nix"))
139 inputs.lanzaboote.nixosModules.lanzaboote
140 inputs.home-manager.nixosModules.home-manager
141 (
142 { config, ... }:
143 let
144 system = config.nixpkgs.hostPlatform.system;
145 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
146 inherit system;
147 overlays = overlays system;
148 };
149 pkgs-unstable-latest = import inputs.nixpkgs-unstable-latest.outPath {
150 inherit system;
151 overlays = overlays system;
152 };
153 in
154 {
155 _module.args = {
156 inherit hostName pkgs-unstable pkgs-unstable-latest;
157 hosts = nixosConfigurations;
158 host = nixosConfigurations.${hostName}._module.args;
159 };
160 nixpkgs.overlays = overlays config.nixpkgs.hostPlatform.system;
161 nixpkgs.config.permittedInsecurePackages = [
162 # Still needed for chatty
163 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
164 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
165 "olm-3.2.16"
166 ];
167 nixpkgs.config.allowUnfreePredicate =
168 pkg:
169 builtins.elem (lib.getName pkg) [
170 "anydesk"
171 "canon-cups-ufr2"
172 "cudatoolkit"
173 "geogebra"
174 "hplip"
175 "memtest86-efi"
176 "nvidia-settings"
177 "nvidia-x11"
178 ];
179 home-manager.useGlobalPkgs = true;
180 home-manager.useUserPackages = true;
181 home-manager.verbose = true;
182 #home-manager.force = true;
183 home-manager.backupFileExtension = "old";
184 home-manager.extraSpecialArgs = {
185 inherit
186 hostName
187 inputs
188 pkgs-unstable
189 pkgs-unstable-latest
190 ;
191 };
192 }
193 )
194 ];
195 }
196 );
197
198 # nix -L develop or direnv allow
199 devShells = forAllSystems (
200 { pkgs, system, ... }:
201 {
202 default = pkgs.callPackage (self + "/shell.nix") {
203 inherit
204 pkgs
205 inputs
206 system
207 nixpkgsPath
208 ;
209 inherit (checks.${system}.git-hooks-check) shellHook;
210 };
211 }
212 );
213
214 # nix -L run .#oignon.switch
215 apps = forAllSystems (
216 { pkgs, system, ... }:
217 with builtins;
218 mapAttrs (
219 hostName:
220 { config, ... }:
221 let
222 inherit (config.system) build;
223 scriptApp = scriptName: ps: script: {
224 type = "app";
225 program =
226 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
227 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
228 set -eux
229 ${script}
230 '').outPath;
231 };
232 in
233 {
234 # Example: nix run .#aubergine.switch
235 "switch" = scriptApp "switch" [ ] ''
236 shopt -s globstar
237
238 chmod -R g-rwx,o-rwx **/*.gpg
239 trap 'git reset **/*.gpg' EXIT
240 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
241
242 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
243 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
244
245 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
246
247 if ssh ${config.install.target} set -x ';' \
248 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
249 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
250 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
251 PATH=${
252 with pkgs;
253 lib.makeBinPath [
254 coreutils
255 nix
256 systemd
257 ]
258 }
259 sleep $((10 * 60))
260 ${profile}/bin/switch-to-configuration switch
261 systemctl reboot
262 '\'''' '&&' \
263 ${build.toplevel}/bin/switch-to-configuration test
264 then
265 ssh ${config.install.target} -o ControlPath=none set -x ';' \
266 systemctl stop nixos-fallback.service ';' \
267 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
268 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
269 nix-env --delete-generations 7d --profile ${profile}
270 else
271 tput rev
272 echo WARNING: switch-to-configuration was not registered at boot
273 tput sgr0
274 ssh ${config.install.target} -o ControlPath=none set -x ';' \
275 systemctl stop nixos-fallback.service
276 false
277 fi
278 '';
279 }
280 ) nixosConfigurations
281 );
282
283 # nix flake check
284 checks = forAllSystems (
285 args: with args; {
286 git-hooks-check = inputs.git-hooks.lib.${system}.run {
287 src = self;
288 hooks = {
289 nixfmt-rfc-style.enable = true;
290 };
291 };
292 }
293 );
294 };
295 }