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