nixos/modules/services/acme.nix

50 lines
1.4 KiB
Nix
Raw Normal View History

2023-09-13 21:13:13 +08:00
inputs:
{
options.nixos.services.acme = let inherit (inputs.lib) mkOption types; in
{
enable = mkOption { type = types.bool; default = false; };
2023-11-08 23:18:19 +08:00
cert = mkOption
2023-09-13 21:13:13 +08:00
{
2023-11-09 23:04:28 +08:00
type = types.attrsOf (types.submodule (submoduleInputs: { options =
2023-11-08 23:18:19 +08:00
{
domains = mkOption
{
type = types.nonEmptyListOf types.nonEmptyStr;
default = [ submoduleInputs.config._module.args.name ];
};
group = mkOption { type = types.nullOr types.nonEmptyStr; default = null; };
2023-11-09 23:04:28 +08:00
};}));
2023-11-08 23:18:19 +08:00
default = {};
2023-09-13 21:13:13 +08:00
};
};
config =
let
inherit (inputs.lib) mkIf;
inherit (inputs.config.nixos.services) acme;
inherit (builtins) map listToAttrs;
2023-11-08 23:18:19 +08:00
inherit (inputs.localLib) attrsToList;
2023-09-13 21:13:13 +08:00
in mkIf acme.enable
{
security.acme =
{
acceptTerms = true;
defaults.email = "chn@chn.moe";
certs = listToAttrs (map
(cert:
{
2023-11-08 23:18:19 +08:00
name = builtins.elemAt cert.value.domains 0;
2023-09-13 21:13:13 +08:00
value =
{
dnsResolver = "8.8.8.8";
dnsProvider = "cloudflare";
credentialsFile = inputs.config.sops.secrets."acme/cloudflare.ini".path;
2023-11-08 23:18:19 +08:00
extraDomainNames = builtins.tail cert.value.domains;
group = mkIf (cert.value.group != null) cert.value.group;
2023-09-13 21:13:13 +08:00
};
})
2023-11-08 23:18:19 +08:00
(attrsToList acme.cert));
2023-09-13 21:13:13 +08:00
};
sops.secrets."acme/cloudflare.ini" = {};
};
}