@cryptotaxi247 / infra / commits / 73dcb877

add colmena flake-parts module

Jörg Thalheim committed Feb 23, 2025 at 16:34 UTC 73dcb8770667ce9a639112497d32d2ba7430f26c
3 files changed +85 -28
build/colmena.nix new
+72
@@ -0,0 +1,72 @@
1 +# heavily adapted from https://github.com/juspay/colmena-flake
2 +# Original license: GNU Affero General Public License v3.0
3 +{
4 + config,
5 + lib,
6 + self,
7 + inputs,
8 + ...
9 +}:
10 +{
11 + options.colmena = {
12 + hosts = lib.mkOption {
13 + type = lib.types.attrsOf (
14 + lib.types.submodule (
15 + { name, ... }:
16 + {
17 + options = {
18 + targetHost = lib.mkOption {
19 + type = lib.types.str;
20 + default = "${name}.nixos.org";
21 + description = ''
22 + The target host for colmena nodes
23 + '';
24 + };
25 +
26 + targetUser = lib.mkOption {
27 + type = lib.types.str;
28 + default = "root";
29 + description = ''
30 + The target user for colmena nodes
31 + '';
32 + };
33 + };
34 + }
35 + )
36 + );
37 + description = ''
38 + Deployment configuration for colmena nodes
39 + '';
40 + example = {
41 + node1 = {
42 + targetHost = "node1.nixos.org";
43 + targetUser = "foo";
44 + };
45 + };
46 + };
47 +
48 + system = lib.mkOption {
49 + type = lib.types.str;
50 + description = ''
51 + The system for colmena nodes
52 + '';
53 + default = "x86_64-linux";
54 + };
55 + };
56 + config.flake.colmenaHive = inputs.colmena.lib.makeHive self.outputs.colmena;
57 + config.flake.colmena =
58 + {
59 + meta = {
60 + nixpkgs = inputs.nixpkgs.legacyPackages.${config.colmena.system};
61 + # https://github.com/zhaofengli/colmena/issues/60#issuecomment-1510496861
62 + nodeSpecialArgs = builtins.mapAttrs (_: value: value._module.specialArgs) self.nixosConfigurations;
63 + };
64 + }
65 + // builtins.mapAttrs (name: _: {
66 + imports = (self.nixosConfigurations.${name})._module.args.modules ++ [
67 + {
68 + deployment = config.colmena.hosts.${name};
69 + }
70 + ];
71 + }) config.colmena.hosts;
72 +}
build/flake-module.nix
+9 -14
@@ -20,6 +20,15 @@ let
20 };
21 in
22 {
23 + imports = [
24 + ./colmena.nix
25 + ];
26 + colmena.hosts = {
27 + haumea = { };
28 + pluto = { };
29 + mimas = { };
30 + };
31 +
32 flake = {
33 nixosConfigurations.haumea = lib.nixosSystem {
34 system = "x86_64-linux";
@@ -47,20 +56,6 @@ in
56 ./mimas
57 ];
58 };
50 - colmena =
51 - {
52 - meta = {
53 - description = "NixOS.org infrastructure";
54 - nixpkgs = inputs.nixpkgs.legacyPackages.x86_64-linux;
55 - };
56 - }
57 - // builtins.mapAttrs (name: value: {
58 - nixpkgs.system = value.config.nixpkgs.system;
59 - imports = value._module.args.modules;
60 - deployment = {
61 - targetHost = "${name}.nixos.org";
62 - };
63 - }) self.nixosConfigurations;
59 };
60
61 perSystem =
non-critical-infra/flake-module.nix
+4 -14
@@ -1,10 +1,13 @@
1 {
2 - self,
2 inputs,
3 lib,
4 ...
5 }:
6 {
7 + colmena.hosts = {
8 + caliban = { };
9 + umbriel = { };
10 + };
11 flake =
12 let
13 importConfig =
@@ -34,19 +37,6 @@
37 }
38 ) (importConfig ./hosts);
39
37 - colmena =
38 - {
39 - meta = {
40 - nixpkgs = import inputs.nixpkgs { system = "x86_64-linux"; };
41 - nodeNixpkgs = builtins.mapAttrs (_: v: v.pkgs) self.nixosConfigurations;
42 - nodeSpecialArgs = builtins.mapAttrs (_: v: v._module.specialArgs) self.nixosConfigurations;
43 - specialArgs.lib = lib;
44 - };
45 - }
46 - // builtins.mapAttrs (_: v: {
47 - deployment.tags = [ "non-critical-infra" ];
48 - imports = v._module.args.modules;
49 - }) self.nixosConfigurations;
40 };
41
42 perSystem =