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