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