This repository has no description
8.8 kB
264 lines
1{
2 description = "lassulus superconfig";
3
4 inputs = {
5 nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6 # nixpkgs.url = "path:/home/lass/tmp/nixpkgs-disk-debug";
7 # nixpkgs.url = "git+file:/home/lass/src/nixpkgs";
8
9 flake-parts.url = "github:hercules-ci/flake-parts";
10
11 nix-index-database.url = "github:nix-community/nix-index-database";
12 nix-index-database.inputs.nixpkgs.follows = "nixpkgs";
13
14 nixvim.url = "github:nix-community/nixvim";
15 nixvim.inputs.nixpkgs.follows = "nixpkgs";
16
17 clan-core.url = "git+https://git.clan.lol/clan/clan-core";
18 # clan-core.url = "path:///home/lass/src/clan/clan-core";
19 # clan-core.url = "git+file:/home/lass/src/clan/clan-core";
20 clan-core.inputs.nixpkgs.follows = "nixpkgs";
21 clan-core.inputs.flake-parts.follows = "flake-parts";
22 clan-core.inputs.disko.follows = "disko";
23
24 stockholm.url = "git+https://github.com/krebs/stockholm?submodules=1";
25 # stockholm.url = "git+https://cgit.lassul.us/stockholm";
26 # stockholm.url = "path:/home/lass/sync/stockholm";
27 stockholm.inputs.nixpkgs.follows = "nixpkgs";
28 stockholm.inputs.buildbot-nix.follows = "";
29
30 disko.url = "github:nix-community/disko";
31 # disko.url = "path:/home/lass/src/disko/";
32 disko.inputs.nixpkgs.follows = "nixpkgs";
33
34 nixos-hardware.url = "github:nixos/nixos-hardware";
35
36 nether.url = "github:krebs/nether";
37 # nether.url = "git+file:/home/lass/src/nether";
38 nether.inputs.nixpkgs.follows = "nixpkgs";
39 nether.inputs.clan-core.follows = "clan-core";
40 nether.inputs.data-mesher.follows = "";
41
42 spora.url = "github:krebs/spora";
43 # spora.url = "git+file:/home/lass/src/spora";
44 spora.inputs.nixpkgs.follows = "nixpkgs";
45
46 nix-darwin.url = "github:LnL7/nix-darwin";
47 nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
48
49 nix-rosetta-builder.url = "github:cpick/nix-rosetta-builder";
50 nix-rosetta-builder.inputs.nixpkgs.follows = "nixpkgs";
51
52 nixos-facter.url = "github:numtide/nixos-facter-modules";
53
54 treefmt-nix.url = "github:numtide/treefmt-nix";
55 treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
56
57 le_menu.url = "github:lassulus/le_menu";
58 # le_menu.url = "git+file:/home/lass/src/le_menu";
59 le_menu.inputs.nixpkgs.follows = "nixpkgs";
60 };
61
62 outputs =
63 inputs@{
64 self,
65 flake-parts,
66 nixpkgs,
67 clan-core,
68 ...
69 }:
70 let
71 clan = clan-core.lib.buildClan {
72 self = self;
73 specialArgs.self = self;
74 inventory = {
75 meta.name = "superconfig";
76 machines = {
77 ignavia.tags = [
78 "laptop"
79 "focus"
80 ];
81 mors.tags = [
82 "laptop"
83 "focus"
84 ];
85 aergia.tags = [
86 "laptop"
87 "focus"
88 ];
89 barnacle = {
90 machineClass = "darwin";
91 tags = [
92 "laptop"
93 "focus"
94 ];
95 };
96 icarus.tags = [ "laptop" ];
97 prism.tags = [ "server" ];
98 neoprism.tags = [ "server" ];
99 };
100 services = {
101 state-version.x.roles.default.tags = [
102 "all"
103 ];
104 };
105 };
106 machines =
107 nixpkgs.lib.mapAttrs
108 (machineName: _: {
109 imports = [
110 ./machines/${machineName}/physical.nix
111 ];
112 })
113 (
114 nixpkgs.lib.filterAttrs (
115 machineName: _: builtins.pathExists ./machines/${machineName}/physical.nix
116 ) (builtins.readDir ./machines)
117 );
118 };
119 in
120 flake-parts.lib.mkFlake { inherit inputs; } {
121 systems = [
122 "x86_64-linux"
123 "aarch64-linux"
124 "aarch64-darwin"
125 "x86_64-darwin"
126 ];
127 imports =
128 [
129 ./formatter.nix
130 ]
131 ++ (
132 # Auto-import all flake-module.nix files from tools subdirectories
133 let
134 toolDirs = builtins.attrNames (
135 nixpkgs.lib.filterAttrs (_: type: type == "directory") (builtins.readDir ./tools)
136 );
137 in
138 map (dir: ./tools + "/${dir}/flake-module.nix") toolDirs
139 );
140 flake.nixosConfigurations = clan.nixosConfigurations;
141 flake.clanInternals = clan.clanInternals;
142 flake.darwinConfigurations = clan.darwinConfigurations;
143 perSystem =
144 {
145 lib,
146 pkgs,
147 system,
148 ...
149 }:
150 {
151 packages =
152 (lib.mapAttrs (name: _v_: pkgs.callPackage ./5pkgs/${name} { }) (builtins.readDir ./5pkgs))
153 // {
154 default = inputs.le_menu.lib.buildMenu {
155 inherit pkgs;
156 menuConfig = {
157 vim.run = "nix run ${self}#nvim";
158 shell.run = "nix run ${self}#shell";
159 machines.submenu = lib.mapAttrs (name: _machine: {
160 submenu.ssh.submenu = {
161 retiolum.run = "ssh -t ${name}.r";
162 spora.run = "ssh ${name}.s";
163 nether.run = "ssh ${name}.n";
164 tor.run = "torify ssh $(pass show machines/${name}/tor-hostname)";
165 };
166 }) self.nixosConfigurations;
167 debug.run = "env";
168 };
169 };
170 clan-cli = clan-core.packages.${system}.clan-cli;
171
172 # Script to build installer ISO with custom vars
173 build-installer-iso = pkgs.writeShellScriptBin "build-installer-iso" ''
174 set -euo pipefail
175 set -x
176
177 # Default values
178 OUTPUT="installer.iso"
179 ARCH="x86_64-linux" # Default to x86_64-linux for cross-compilation
180 VARS_DIR=""
181
182 usage() {
183 cat <<EOF
184 Usage: $0 [OPTIONS]
185
186 Build a NixOS installer ISO with custom vars appended.
187
188 OPTIONS:
189 -o, --output FILE Output ISO file (default: installer.iso)
190 -a, --arch ARCH Architecture: x86_64-linux or aarch64-linux (default: x86_64-linux)
191 -v, --vars DIR Directory containing vars to append to ISO
192 -h, --help Show this help message
193
194 EXAMPLE:
195 $0 -o my-installer.iso -v ./my-vars -a x86_64-linux
196 EOF
197 }
198
199 # Parse arguments
200 while [[ $# -gt 0 ]]; do
201 case $1 in
202 -o|--output)
203 OUTPUT="$2"
204 shift 2
205 ;;
206 -a|--arch)
207 ARCH="$2"
208 shift 2
209 ;;
210 -v|--vars)
211 VARS_DIR="$2"
212 shift 2
213 ;;
214 -h|--help)
215 usage
216 exit 0
217 ;;
218 *)
219 echo "Unknown option: $1"
220 usage
221 exit 1
222 ;;
223 esac
224 done
225
226 # Build the base ISO
227 echo "Building base ISO for $ARCH..."
228 BASE_ISO=$(nix build -L --no-link --print-out-paths ${self}#clanInternals.machines.$ARCH.installer.config.system.build.images.iso-installer)
229
230 if [ -z "$VARS_DIR" ]; then
231 # No vars specified, just copy the base ISO
232 echo "No vars directory specified, copying base ISO..."
233 cp "$BASE_ISO"/iso/*.iso "$OUTPUT"
234 else
235 # Append vars using xorriso - preserve boot structure
236 echo "Appending vars from $VARS_DIR to ISO..."
237 ${pkgs.xorriso}/bin/xorriso \
238 -indev "$BASE_ISO"/iso/*.iso \
239 -outdev "$OUTPUT" \
240 -boot_image any replay \
241 -map "$VARS_DIR" /vars \
242 -commit_eject all
243 fi
244
245 echo "ISO created: $OUTPUT"
246 '';
247 };
248 devShells.default = pkgs.mkShell {
249 packages = [
250 clan-core.packages.${system}.clan-cli
251 nixpkgs.legacyPackages.${system}.nil
252 nixpkgs.legacyPackages.${system}.nixd
253 ];
254 };
255 };
256 flake.keys = {
257 pgp.yubi = {
258 key = ./keys/yubi.pgp;
259 id = "DBCD757846069B392EA9401D6657BE8A8D1EE807";
260 };
261 ssh = builtins.readFile ./keys/yubi.ssh;
262 };
263 };
264}