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