|
109 | 109 | }; |
110 | 110 |
|
111 | 111 | outputs = |
112 | | - { self |
113 | | - , nixpkgs |
114 | | - , systems |
115 | | - , colmena |
116 | | - , agenix |
117 | | - , agenix-rekey |
118 | | - , disko |
119 | | - , nix-index-database |
120 | | - , ocflib |
121 | | - , ocf-sync-etc |
122 | | - , ocf-pam-trimspaces |
123 | | - , ocf-utils |
124 | | - , wayout |
125 | | - , ocf-cosmic-applets |
126 | | - , ocf-jukebox |
| 112 | + { |
| 113 | + self, |
| 114 | + nixpkgs, |
| 115 | + systems, |
| 116 | + colmena, |
| 117 | + agenix, |
| 118 | + agenix-rekey, |
| 119 | + disko, |
| 120 | + nix-index-database, |
| 121 | + ocflib, |
| 122 | + ocf-sync-etc, |
| 123 | + ocf-pam-trimspaces, |
| 124 | + ocf-utils, |
| 125 | + wayout, |
| 126 | + ocf-cosmic-applets, |
| 127 | + ocf-jukebox, |
127 | 128 | }@inputs: |
128 | 129 | let |
129 | 130 | # ============== # |
|
139 | 140 | agenix-rekey.overlays.default |
140 | 141 | ]; |
141 | 142 |
|
142 | | - customModules = |
143 | | - (with nixpkgs.lib; filter (hasSuffix ".nix") (filesystem.listFilesRecursive ./modules)); |
| 143 | + customModules = ( |
| 144 | + with nixpkgs.lib; filter (hasSuffix ".nix") (filesystem.listFilesRecursive ./modules) |
| 145 | + ); |
144 | 146 |
|
145 | 147 | commonModules = customModules ++ [ |
146 | 148 | ./profiles/base.nix |
|
150 | 152 | ]; |
151 | 153 |
|
152 | 154 | defaultSystem = "x86_64-linux"; |
153 | | - overrideSystem = { overheat = "aarch64-linux"; }; |
| 155 | + overrideSystem = { |
| 156 | + overheat = "aarch64-linux"; |
| 157 | + }; |
154 | 158 |
|
155 | 159 | # ============== # |
156 | 160 | # Glue/Internals # |
157 | 161 | # ============== # |
158 | 162 |
|
159 | | - pkgsFor = system: import nixpkgs { |
160 | | - inherit overlays system; |
161 | | - config = { |
162 | | - allowUnfreePredicate = pkg: builtins.elem (nixpkgs.lib.getName pkg) [ |
163 | | - "code" |
164 | | - "claude-code" |
165 | | - "dwarf-fortress" |
166 | | - "google-chrome" |
167 | | - "helvetica-neue-lt-std" #tornado |
168 | | - "mongodb" #zecora for unifi |
169 | | - "nvidia-settings" |
170 | | - "nvidia-x11" |
171 | | - "steam" |
172 | | - "steam-unwrapped" |
173 | | - "unifi-controller" |
174 | | - "vscode" |
175 | | - "zoom" |
176 | | - "drawio" |
177 | | - "datagrip" |
178 | | - "davinci-resolve" |
179 | | - ]; |
| 163 | + pkgsFor = |
| 164 | + system: |
| 165 | + import nixpkgs { |
| 166 | + inherit overlays system; |
| 167 | + config = { |
| 168 | + allowUnfreePredicate = |
| 169 | + pkg: |
| 170 | + builtins.elem (nixpkgs.lib.getName pkg) [ |
| 171 | + "code" |
| 172 | + "claude-code" |
| 173 | + "dwarf-fortress" |
| 174 | + "google-chrome" |
| 175 | + "helvetica-neue-lt-std" # tornado |
| 176 | + "mongodb" # zecora for unifi |
| 177 | + "nvidia-settings" |
| 178 | + "nvidia-x11" |
| 179 | + "steam" |
| 180 | + "steam-unwrapped" |
| 181 | + "unifi-controller" |
| 182 | + "vscode" |
| 183 | + "zoom" |
| 184 | + "drawio" |
| 185 | + "datagrip" |
| 186 | + "davinci-resolve" |
| 187 | + ]; |
| 188 | + }; |
180 | 189 | }; |
181 | | - }; |
182 | 190 |
|
183 | | - forAllSystems = fn: nixpkgs.lib.genAttrs (import systems) |
184 | | - (system: fn (pkgsFor system)); |
| 191 | + forAllSystems = fn: nixpkgs.lib.genAttrs (import systems) (system: fn (pkgsFor system)); |
185 | 192 |
|
186 | | - readGroup = group: nixpkgs.lib.mapAttrs' |
187 | | - (filename: _: { |
| 193 | + readGroup = |
| 194 | + group: |
| 195 | + nixpkgs.lib.mapAttrs' (filename: _: { |
188 | 196 | name = nixpkgs.lib.nameFromURL filename "."; |
189 | 197 | value = { |
190 | 198 | inherit group; |
191 | 199 | modules = [ ./hosts/${group}/${filename} ]; |
192 | 200 | }; |
193 | | - }) |
194 | | - (builtins.readDir ./hosts/${group}); |
| 201 | + }) (builtins.readDir ./hosts/${group}); |
195 | 202 |
|
196 | | - hosts = nixpkgs.lib.concatMapAttrs |
197 | | - (group: _: readGroup group) |
198 | | - (builtins.readDir ./hosts); |
| 203 | + hosts = nixpkgs.lib.concatMapAttrs (group: _: readGroup group) (builtins.readDir ./hosts); |
199 | 204 |
|
200 | 205 | deploy-user = "ocf-nix-deploy-user"; |
201 | | - colmenaHosts = builtins.mapAttrs |
202 | | - (host: { modules, group }: { |
| 206 | + colmenaHosts = builtins.mapAttrs ( |
| 207 | + host: |
| 208 | + { modules, group }: |
| 209 | + { |
203 | 210 | imports = commonModules ++ modules; |
204 | 211 | deployment.tags = [ group ]; |
205 | 212 | deployment.targetHost = "${host}.ocf.berkeley.edu"; |
206 | 213 | # TODO: Think of a less ugly way of doing this |
207 | | - deployment.targetUser = nixpkgs.lib.mkIf self.colmenaHive.nodes.${host}.config.ocf.managed-deployment.enable deploy-user; |
208 | | - }) |
209 | | - hosts; |
| 214 | + deployment.targetUser = |
| 215 | + nixpkgs.lib.mkIf self.colmenaHive.nodes.${host}.config.ocf.managed-deployment.enable |
| 216 | + deploy-user; |
| 217 | + } |
| 218 | + ) hosts; |
210 | 219 | in |
211 | 220 | { |
212 | 221 | formatter = forAllSystems (pkgs: pkgs.nixfmt-tree); |
213 | 222 |
|
214 | | - colmenaHive = colmena.lib.makeHive (colmenaHosts // { |
215 | | - meta = { |
216 | | - nixpkgs = pkgsFor defaultSystem; |
217 | | - nodeNixpkgs = nixpkgs.lib.mapAttrs (name: pkgsFor) overrideSystem; |
218 | | - specialArgs = { inherit self inputs; }; |
| 223 | + colmenaHive = colmena.lib.makeHive ( |
| 224 | + colmenaHosts |
| 225 | + // { |
| 226 | + meta = { |
| 227 | + nixpkgs = pkgsFor defaultSystem; |
| 228 | + nodeNixpkgs = nixpkgs.lib.mapAttrs (name: pkgsFor) overrideSystem; |
| 229 | + specialArgs = { inherit self inputs; }; |
| 230 | + }; |
| 231 | + } |
| 232 | + ); |
| 233 | + |
| 234 | + autoDeploy = |
| 235 | + let |
| 236 | + # returns the value of a managed-deployment option (given as a string containing the option name) for the given node |
| 237 | + getOptionForNode = |
| 238 | + option: node: self.colmenaHive.nodes.${node}.config.ocf.managed-deployment.${option}; |
| 239 | + |
| 240 | + # returns a list of the MAC addresses for the given list of nodes with automated deploy enabled |
| 241 | + # hosts that do not have mac-address set will be gracefully ignored |
| 242 | + getMACs = |
| 243 | + nodes: |
| 244 | + builtins.filter (mac: mac != "") (builtins.map (node: getOptionForNode "mac-address" node) nodes); |
| 245 | + in |
| 246 | + { |
| 247 | + # list of nodes with automated deploy enabled, to be consumed by github actions |
| 248 | + nodes = builtins.filter (node: getOptionForNode "automated-deploy" node) ( |
| 249 | + builtins.attrNames self.colmenaHive.nodes |
| 250 | + ); |
| 251 | + |
| 252 | + # list of mac addresses of nodes that github actions should wake up on deploy |
| 253 | + MACs = getMACs self.autoDeploy.nodes; |
| 254 | + |
| 255 | + # attribute set combining automatedDeployNodes and automatedDeployNodeMACs |
| 256 | + # get json with `nix eval .#autoDeploy.nodesWithMACs --json`! |
| 257 | + # TODO: script to wake up hosts with this |
| 258 | + nodesWithMACs = nixpkgs.lib.listToAttrs ( |
| 259 | + nixpkgs.lib.zipListsWith (name: value: { |
| 260 | + inherit name value; |
| 261 | + }) self.autoDeploy.nodes self.autoDeploy.MACs |
| 262 | + ); |
219 | 263 | }; |
220 | | - }); |
221 | | - |
222 | | - autoDeploy = let |
223 | | - # returns the value of a managed-deployment option (given as a string containing the option name) for the given node |
224 | | - getOptionForNode = option: node: self.colmenaHive.nodes.${node}.config.ocf.managed-deployment.${option}; |
225 | | - |
226 | | - # returns a list of the MAC addresses for the given list of nodes with automated deploy enabled |
227 | | - # hosts that do not have mac-address set will be gracefully ignored |
228 | | - getMACs = nodes: builtins.filter (mac: mac != "") |
229 | | - (builtins.map |
230 | | - (node: getOptionForNode "mac-address" node) |
231 | | - nodes); |
232 | | - in { |
233 | | - # list of nodes with automated deploy enabled, to be consumed by github actions |
234 | | - nodes = builtins.filter (node: getOptionForNode "automated-deploy" node) (builtins.attrNames self.colmenaHive.nodes); |
235 | | - |
236 | | - # list of mac addresses of nodes that github actions should wake up on deploy |
237 | | - MACs = getMACs self.autoDeploy.nodes; |
238 | | - |
239 | | - # attribute set combining automatedDeployNodes and automatedDeployNodeMACs |
240 | | - # get json with `nix eval .#autoDeploy.nodesWithMACs --json`! |
241 | | - # TODO: script to wake up hosts with this |
242 | | - nodesWithMACs = nixpkgs.lib.listToAttrs (nixpkgs.lib.zipListsWith |
243 | | - (name: value: { inherit name value; }) |
244 | | - self.autoDeploy.nodes self.autoDeploy.MACs); |
245 | | - }; |
246 | 264 |
|
247 | 265 | overlays.default = final: prev: { |
248 | 266 | ocf-utils = ocf-utils.packages.${final.system}.default; |
|
265 | 283 | default = pkgs.mkShell { |
266 | 284 | packages = [ |
267 | 285 | pkgs.git |
268 | | - pkgs.age |
| 286 | + pkgs.age |
269 | 287 | pkgs.agenix-rekey |
270 | 288 | pkgs.age-plugin-fido2-hmac |
271 | 289 | pkgs.wol |
|
284 | 302 | }; |
285 | 303 | }); |
286 | 304 |
|
287 | | - nixosConfigurations = builtins.mapAttrs |
288 | | - (host: colmenaConfig: nixpkgs.lib.nixosSystem rec { |
| 305 | + nixosConfigurations = builtins.mapAttrs ( |
| 306 | + host: colmenaConfig: |
| 307 | + nixpkgs.lib.nixosSystem rec { |
289 | 308 | system = overrideSystem.${host} or defaultSystem; |
290 | 309 | pkgs = pkgsFor system; |
291 | 310 | modules = colmenaConfig.imports; |
292 | 311 | specialArgs = { inherit inputs; }; |
293 | | - }) |
294 | | - colmenaHosts; |
| 312 | + } |
| 313 | + ) colmenaHosts; |
295 | 314 | }; |
296 | 315 | } |
0 commit comments