]> Git — Sourcephile - julm/julm-nix.git/blob - flake.nix
Usability/Operability(firefox): enable to open link from some other apps
[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 "inc"
102 "json"
103 "lua"
104 "nix"
105 "patch"
106 "pem"
107 "pub"
108 "sh"
109 "theme"
110 "vim"
111 ];
112 in
113 unions [
114 (fileFilter (file: lib.any file.hasExt exts) ./domains)
115 (fileFilter (file: lib.any file.hasExt exts) ./home-manager)
116 (fileFilter (file: lib.any file.hasExt exts) ./homes)
117 (fileFilter (file: lib.any file.hasExt exts) ./hosts)
118 (fileFilter (file: lib.any file.hasExt exts) ./nixos)
119 (fileFilter (file: lib.any file.hasExt exts) ./nixpkgs)
120 (fileFilter (file: lib.any file.hasExt exts) ./users)
121 ./shell.nix
122 ];
123 };
124 in
125 rec {
126 # nix -L build .#hello
127 packages = forAllSystems ({ pkgs, ... }: pkgs);
128
129 # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
130 # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
131 # nix -L build .#nixosConfigurations.oignon.pkgs.hello
132 # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
133 nixosConfigurations =
134 lib.genAttrs
135 (builtins.attrNames (
136 lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))
137 ))
138 (
139 hostName:
140 nixosSystem {
141 system = null;
142 specialArgs = {
143 # Required to avoid infinite recursion
144 # when `inputs` is used in `imports`.
145 inherit inputs;
146 };
147 modules = [
148 nixos/default.nix
149 (import (self + "/hosts/${hostName}.nix"))
150 inputs.lanzaboote.nixosModules.lanzaboote
151 inputs.home-manager.nixosModules.home-manager
152 (
153 { config, ... }:
154 let
155 inherit (config.nixpkgs.hostPlatform) system;
156 pkgs-unstable = import inputs.nixpkgs-unstable.outPath {
157 inherit system;
158 overlays = overlays system;
159 };
160 pkgs-unstable-latest = import inputs.nixpkgs-unstable-latest.outPath {
161 inherit system;
162 overlays = overlays system;
163 };
164 in
165 {
166 _module.args = {
167 inherit hostName pkgs-unstable pkgs-unstable-latest;
168 hosts = nixosConfigurations;
169 host = nixosConfigurations.${hostName}._module.args;
170 };
171 nixpkgs = {
172 overlays = overlays config.nixpkgs.hostPlatform.system;
173 config.permittedInsecurePackages = [
174 # Still needed for chatty
175 # See https://github.com/NixOS/nixpkgs/pull/334638#issuecomment-2289025802%3E
176 # and https://gitlab.gnome.org/World/Chatty/-/issues/932
177 "olm-3.2.16"
178 ];
179 config.allowUnfreePredicate =
180 pkg:
181 builtins.elem (lib.getName pkg) [
182 "anydesk"
183 "canon-cups-ufr2"
184 "cudatoolkit"
185 "geogebra"
186 "hplip"
187 "memtest86-efi"
188 "nvidia-settings"
189 "nvidia-x11"
190 ];
191 };
192 home-manager = {
193 useGlobalPkgs = true;
194 useUserPackages = true;
195 verbose = true;
196 #force = true;
197 backupFileExtension = "old";
198 extraSpecialArgs = {
199 inherit
200 inputs
201 hostName
202 pkgs-unstable
203 pkgs-unstable-latest
204 ;
205 };
206 };
207 }
208 )
209 ];
210 }
211 );
212
213 # nix -L develop or direnv allow
214 devShells = forAllSystems (
215 { pkgs, system, ... }:
216 {
217 default = pkgs.callPackage (self + "/shell.nix") {
218 inherit
219 pkgs
220 inputs
221 system
222 nixpkgsPath
223 ;
224 inherit (checks.${system}.git-hooks-check) shellHook;
225 };
226 }
227 );
228
229 # nix -L run .#oignon.switch
230 apps = forAllSystems (
231 { pkgs, system, ... }:
232 with builtins;
233 mapAttrs (
234 hostName:
235 { config, ... }:
236 let
237 inherit (config.system) build;
238 scriptApp = scriptName: ps: script: {
239 type = "app";
240 program =
241 (pkgs.writeShellScript "${hostName}-${scriptName}" ''
242 export PATH="${lib.makeBinPath ([ pkgs.coreutils ] ++ ps)}:$PATH"
243 set -eux
244 ${script}
245 '').outPath;
246 };
247 in
248 {
249 # Example: nix run .#aubergine.switch
250 "switch" = scriptApp "switch" [ ] ''
251 shopt -s globstar
252
253 chmod -R g-rwx,o-rwx **/*.gpg
254 trap 'git reset **/*.gpg' EXIT
255 git rm -rf --cached --ignore-unmatch **/*.gpg # prevent copying to /nix/store
256
257 nix-store --add-root hosts/${hostName}.nixpkgs --indirect --realise ${nixpkgsPath}
258 nix-store --add-root hosts/${hostName}.root --indirect --realise ${build.toplevel}
259
260 nix copy --to "ssh://${config.install.target}?''${targetStore-}"${lib.optionalString config.install.substituteOnDestination " --substitute-on-destination"} ${build.toplevel}
261
262 if ssh ${config.install.target} set -x ';' \
263 systemctl reset-failed nixos-fallback '2>/dev/null' ';' \
264 test "''${NO_NIXOS_FALLBACK:+set}" '||' \
265 systemd-run -u nixos-fallback --description=nixos-fallback /bin/sh -xc '''\'''
266 PATH=${
267 with pkgs;
268 lib.makeBinPath [
269 coreutils
270 nix
271 systemd
272 ]
273 }
274 sleep $((10 * 60))
275 ${profile}/bin/switch-to-configuration switch
276 systemctl reboot
277 '\'''' '&&' \
278 ${build.toplevel}/bin/switch-to-configuration test
279 then
280 ssh ${config.install.target} -o ControlPath=none set -x ';' \
281 systemctl stop nixos-fallback.service ';' \
282 nix-env --profile ${profile} --set '${build.toplevel}' ';' \
283 ${build.toplevel}/bin/switch-to-configuration boot '&&' \
284 nix-env --delete-generations 7d --profile ${profile}
285 else
286 tput rev
287 echo WARNING: switch-to-configuration was not registered at boot
288 tput sgr0
289 ssh ${config.install.target} -o ControlPath=none set -x ';' \
290 systemctl stop nixos-fallback.service
291 false
292 fi
293 '';
294 }
295 ) nixosConfigurations
296 );
297
298 # nix flake check
299 checks = forAllSystems (
300 args: with args; {
301 git-hooks-check = inputs.git-hooks.lib.${system}.run {
302 src = self;
303 hooks = {
304 nixfmt-rfc-style.enable = true;
305 };
306 };
307 }
308 );
309 };
310 }