From 54bf53c664a7bf0401b78fd86cd2809f4cfc8829 Mon Sep 17 00:00:00 2001 From: Ilan Joselevich Date: Fri, 11 Nov 2022 19:36:44 +0200 Subject: [PATCH] netlifyDeploy: add flake-module --- effects/netlify/flake-module.nix | 67 ++++++++++++++++++++++++++++++++ flake-module.nix | 1 + 2 files changed, 68 insertions(+) create mode 100644 effects/netlify/flake-module.nix diff --git a/effects/netlify/flake-module.nix b/effects/netlify/flake-module.nix new file mode 100644 index 0000000..4186b99 --- /dev/null +++ b/effects/netlify/flake-module.nix @@ -0,0 +1,67 @@ +{ config, lib, withSystem, ... }: +let + inherit (lib) mkOption types optionalAttrs mapAttrs; + cfg = config.netlify-deploy; +in +{ + options.netlify-deploy = mkOption { + type = (types.attrsOf types.submodule { + options = { + enable = lib.mkEnableOption "On-push deployment to Netlify"; + + siteId = mkOption { + type = types.str; + description = '' + An opaque identifier assigned by Netlify to the website you wish to deploy. + 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. + ''; + }; + + secretName = mkOption { + type = types.str; + description = '' + The secret that will be looked up in [secrets.json](https://docs.hercules-ci.com/hercules-ci-agent/secrets-json). + This secret must hold the `secretField` field, ith a string value that is a Netlify personal access token. + ''; + }; + + secretField = mkOption { + type = types.str; + default = "token"; + description = "The name of the field inside the `secretName` secret which holds the Netlify personal access token."; + }; + + content = mkOption { + type = types.str; + description = '' + Path to the site content, also known as the Publish directory. + This includes files such as netlify.toml, _redirects, and all web resources, like index.html, style sheets, etc. + You will typically put a derivation here. + ''; + }; + + productionDeployment = mkOption { + type = types.bool; + default = false; + description = "Whether this should be production deployment."; + }; + + extraDeployArgs = mkOption { + type = (types.listOf types.str); + default = [ ]; + description = "Extra arguments to pass to the netlify deploy invocation."; + }; + }; + }); + }; + + config = { + herculesCI.onPush.default.outputs.effects = { + netlify-deploy = mapAttrs + (name: siteCfg: optionalAttrs (siteCfg.enable) withSystem config.defaultEffectSystem ({ hci-effects, ... }: + hci-effects.netlifyDeploy { inherit (siteCfg) siteId secretName secretField content productionDeployment extraDeployArgs; } + )) + cfg; + }; + }; +} diff --git a/flake-module.nix b/flake-module.nix index 6eb157c..1b11cfa 100644 --- a/flake-module.nix +++ b/flake-module.nix @@ -4,5 +4,6 @@ ./flake-modules/herculesCI-attribute.nix ./flake-modules/herculesCI-helpers.nix ./effects/flake-update/flake-module.nix + ./effects/netlify/flake-module.nix ]; }