|
| 1 | +{ config, lib, withSystem, ... }: |
| 2 | +let |
| 3 | + inherit (lib) |
| 4 | + mkOption |
| 5 | + types |
| 6 | + optionalAttrs |
| 7 | + mapAttrs; |
| 8 | + cfg = config.hercules-ci.netlify-deploy; |
| 9 | +in |
| 10 | +{ |
| 11 | + options.hercules-ci.netlify-deploy = mkOption { |
| 12 | + type = types.attrsOf (types.submodule { |
| 13 | + options = { |
| 14 | + siteId = mkOption { |
| 15 | + type = types.str; |
| 16 | + description = '' |
| 17 | + An opaque identifier assigned by Netlify to the website you wish to deploy. |
| 18 | + See [docs.hercules-ci.com](https://docs.hercules-ci.com/hercules-ci-effects/reference/nix-functions/netlifydeploy/#param-name) on how to get the right siteId for your website from Netlify. |
| 19 | + ''; |
| 20 | + }; |
| 21 | + |
| 22 | + secretName = mkOption { |
| 23 | + type = types.str; |
| 24 | + description = '' |
| 25 | + The secret that will be looked up in [secrets.json](https://docs.hercules-ci.com/hercules-ci-agent/secrets-json). |
| 26 | + This secret must hold the `secretField` field, ith a string value that is a Netlify personal access token. |
| 27 | + ''; |
| 28 | + }; |
| 29 | + |
| 30 | + secretField = mkOption { |
| 31 | + type = types.str; |
| 32 | + default = "token"; |
| 33 | + description = "The name of the field inside the `secretName` secret which holds the Netlify personal access token."; |
| 34 | + }; |
| 35 | + |
| 36 | + content = mkOption { |
| 37 | + type = types.functionTo (types.either types.str types.package); |
| 38 | + example = lib.literalExpression "{ config, ... }: config.packages.default"; |
| 39 | + description = '' |
| 40 | + A function that returns the site content, also known as the Publish directory. |
| 41 | + This includes files such as netlify.toml, _redirects, and all web resources, like index.html, style sheets, etc. |
| 42 | + You will typically put a derivation here. |
| 43 | +
|
| 44 | + The function receives the same arguments as [perSystem](https://flake.parts/options/flake-parts.html#opt-perSystem). |
| 45 | + ''; |
| 46 | + }; |
| 47 | + |
| 48 | + productionDeployment = mkOption { |
| 49 | + type = types.functionTo types.bool; |
| 50 | + default = _: false; |
| 51 | + defaultText = lib.literalExpression "_: false"; |
| 52 | + example = lib.literalExpression ''{ branch, ... }: (branch == "master")''; |
| 53 | + description = '' |
| 54 | + Condition under which a deployment is treated as a production deployment. |
| 55 | + The function receives the value of attributes under [herculesCI.repo](https://flake.parts/options/hercules-ci-effects.html#opt-herculesCI.repo). |
| 56 | + ''; |
| 57 | + }; |
| 58 | + |
| 59 | + extraDeployArgs = mkOption { |
| 60 | + type = (types.listOf types.str); |
| 61 | + default = [ ]; |
| 62 | + description = "Extra arguments to pass to the netlify deploy invocation."; |
| 63 | + }; |
| 64 | + |
| 65 | + secretsMap = mkOption { |
| 66 | + type = types.attrs; |
| 67 | + default = { }; |
| 68 | + description = "Extra secrets to add to the effect."; |
| 69 | + }; |
| 70 | + |
| 71 | + effect.system = mkOption { |
| 72 | + type = types.str; |
| 73 | + default = config.defaultEffectSystem; |
| 74 | + defaultText = lib.literalMD "config.defaultEffectSystem"; |
| 75 | + example = "aarch64-linux"; |
| 76 | + description = "The [system](https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-system) on which to run the website deployment on."; |
| 77 | + }; |
| 78 | + }; |
| 79 | + }); |
| 80 | + }; |
| 81 | + |
| 82 | + config = { |
| 83 | + herculesCI = herculesCI: { |
| 84 | + onPush.default.outputs.effects = { |
| 85 | + netlify-deploy = mapAttrs |
| 86 | + (name: siteCfg: optionalAttrs (siteCfg != { }) (withSystem siteCfg.effect.system ({ hci-effects, ... }: |
| 87 | + hci-effects.netlifyDeploy { |
| 88 | + inherit (siteCfg) |
| 89 | + siteId |
| 90 | + secretName |
| 91 | + secretField |
| 92 | + extraDeployArgs |
| 93 | + secretsMap; |
| 94 | + productionDeployment = siteCfg.productionDeployment herculesCI.config.repo; |
| 95 | + content = withSystem siteCfg.effect.system siteCfg.content; |
| 96 | + } |
| 97 | + ))) |
| 98 | + cfg; |
| 99 | + }; |
| 100 | + }; |
| 101 | + }; |
| 102 | +} |
0 commit comments