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