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