Skip to content

Commit bd5250b

Browse files
committed
netlifyDeploy: add flake-module
1 parent fdbc15b commit bd5250b

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed

effects/netlify/flake-module.nix

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

flake-module.nix

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
./flake-modules/herculesCI-helpers.nix
66
./flake-modules/github-pages.nix
77
./effects/flake-update/flake-module.nix
8+
./effects/netlify/flake-module.nix
89
];
910
}

0 commit comments

Comments
 (0)