|
| 1 | +{ |
| 2 | + config, |
| 3 | + lib, |
| 4 | + pkgs, |
| 5 | + ... |
| 6 | +}: |
| 7 | + |
| 8 | +let |
| 9 | + cfg = config.services.radicle.ci.adapters.native; |
| 10 | + brokerCfg = config.services.radicle.ci.broker; |
| 11 | + |
| 12 | + settingsFormat = pkgs.formats.yaml { }; |
| 13 | + |
| 14 | + enabledInstances = lib.filter (instance: instance.enable) (lib.attrValues cfg.instances); |
| 15 | +in |
| 16 | + |
| 17 | +{ |
| 18 | + meta.maintainers = with lib.maintainers; [ defelo ]; |
| 19 | + |
| 20 | + options.services.radicle.ci.adapters.native = { |
| 21 | + instances = lib.mkOption { |
| 22 | + type = lib.types.attrsOf ( |
| 23 | + lib.types.submodule ( |
| 24 | + { config, name, ... }: |
| 25 | + { |
| 26 | + options = { |
| 27 | + enable = lib.mkEnableOption "this radicle-native-ci instance" // { |
| 28 | + default = true; |
| 29 | + example = false; |
| 30 | + }; |
| 31 | + |
| 32 | + name = lib.mkOption { |
| 33 | + type = lib.types.str; |
| 34 | + description = '' |
| 35 | + Adapter name that is used in the radicle-ci-broker configuration. |
| 36 | + Defaults to the attribute name. |
| 37 | + ''; |
| 38 | + }; |
| 39 | + |
| 40 | + package = lib.mkPackageOption pkgs "radicle-native-ci" { }; |
| 41 | + |
| 42 | + runtimePackages = lib.mkOption { |
| 43 | + type = lib.types.listOf lib.types.package; |
| 44 | + description = "Packages added to the adapter's {env}`PATH`."; |
| 45 | + defaultText = lib.literalExpression '' |
| 46 | + with pkgs; [ |
| 47 | + bash |
| 48 | + coreutils |
| 49 | + curl |
| 50 | + gawk |
| 51 | + gitMinimal |
| 52 | + gnused |
| 53 | + wget |
| 54 | + ] |
| 55 | + ''; |
| 56 | + }; |
| 57 | + |
| 58 | + settings = lib.mkOption { |
| 59 | + type = lib.types.submodule { |
| 60 | + freeformType = settingsFormat.type; |
| 61 | + |
| 62 | + options = { |
| 63 | + state = lib.mkOption { |
| 64 | + type = lib.types.path; |
| 65 | + description = "Directory where per-run directories are stored."; |
| 66 | + defaultText = lib.literalExpression ''"''${config.services.radicle.ci.broker.stateDir}/adapters/native/${config.name}"''; |
| 67 | + }; |
| 68 | + |
| 69 | + log = lib.mkOption { |
| 70 | + type = lib.types.path; |
| 71 | + description = "File where radicle-native-ci should write the run log."; |
| 72 | + defaultText = lib.literalExpression ''"''${config.services.radicle.ci.broker.logDir}/adapters/native/${config.name}.log"''; |
| 73 | + }; |
| 74 | + |
| 75 | + base_url = lib.mkOption { |
| 76 | + type = lib.types.nullOr lib.types.str; |
| 77 | + description = "Base URL for build logs (mandatory for access from CI broker page)."; |
| 78 | + default = null; |
| 79 | + }; |
| 80 | + }; |
| 81 | + }; |
| 82 | + description = '' |
| 83 | + Configuration of radicle-native-ci. |
| 84 | + See <https://app.radicle.xyz/nodes/seed.radicle.xyz/rad:z3qg5TKmN83afz2fj9z3fQjU8vaYE#configuration> for more information. |
| 85 | + ''; |
| 86 | + default = { }; |
| 87 | + }; |
| 88 | + }; |
| 89 | + |
| 90 | + config = { |
| 91 | + name = lib.mkDefault name; |
| 92 | + |
| 93 | + runtimePackages = with pkgs; [ |
| 94 | + bash |
| 95 | + coreutils |
| 96 | + curl |
| 97 | + gawk |
| 98 | + gitMinimal |
| 99 | + gnused |
| 100 | + wget |
| 101 | + ]; |
| 102 | + |
| 103 | + settings = { |
| 104 | + state = lib.mkDefault "${brokerCfg.stateDir}/adapters/native/${config.name}"; |
| 105 | + log = lib.mkDefault "${brokerCfg.logDir}/adapters/native/${config.name}.log"; |
| 106 | + }; |
| 107 | + }; |
| 108 | + } |
| 109 | + ) |
| 110 | + ); |
| 111 | + description = "radicle-native-ci adapter instances."; |
| 112 | + default = { }; |
| 113 | + }; |
| 114 | + }; |
| 115 | + |
| 116 | + config = lib.mkIf (enabledInstances != [ ]) { |
| 117 | + services.radicle.ci.broker.settings.adapters = lib.listToAttrs ( |
| 118 | + map ( |
| 119 | + instance: |
| 120 | + lib.nameValuePair instance.name { |
| 121 | + command = lib.getExe instance.package; |
| 122 | + config = instance.settings; |
| 123 | + config_env = "RADICLE_NATIVE_CI"; |
| 124 | + env.PATH = lib.makeBinPath instance.runtimePackages; |
| 125 | + } |
| 126 | + ) enabledInstances |
| 127 | + ); |
| 128 | + |
| 129 | + systemd.tmpfiles.settings.radicle-native-ci = lib.listToAttrs ( |
| 130 | + map ( |
| 131 | + instance: |
| 132 | + lib.nameValuePair (builtins.dirOf instance.settings.log) { |
| 133 | + d = { |
| 134 | + user = config.users.users.radicle.name; |
| 135 | + group = config.users.groups.radicle.name; |
| 136 | + }; |
| 137 | + } |
| 138 | + ) enabledInstances |
| 139 | + ); |
| 140 | + }; |
| 141 | +} |
0 commit comments