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