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