| 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 | meta = { |
| 59 | nixpkgs = inputs.nixpkgs.legacyPackages.${config.colmena.system}; |
| 60 | # https://github.com/zhaofengli/colmena/issues/60#issuecomment-1510496861 |
| 61 | nodeSpecialArgs = builtins.mapAttrs (_: value: value._module.specialArgs) self.nixosConfigurations; |
| 62 | }; |
| 63 | } |
| 64 | // builtins.mapAttrs (name: _: { |
| 65 | imports = (self.nixosConfigurations.${name})._module.args.modules ++ [ |
| 66 | { |
| 67 | deployment = config.colmena.hosts.${name}; |
| 68 | } |
| 69 | ]; |
| 70 | }) config.colmena.hosts; |
| 71 | } |