summaryrefslogtreecommitdiff
path: root/env/acme/default.nix
diff options
context:
space:
mode:
authorAlejandro Soto <alejandro@34project.org>2023-01-07 01:26:07 -0600
committerAlejandro Soto <alejandro@34project.org>2023-01-07 01:27:24 -0600
commitfd156bcd3028a42b6d6a56dc1956d934bf8ea2c9 (patch)
treef525580ba7091d55c7fea1da43422fb1621c9082 /env/acme/default.nix
parent8902317d7f6d20361d96212a5e41621e90df8b67 (diff)
env/acme: move domains, certs out of dmz
Diffstat (limited to 'env/acme/default.nix')
-rw-r--r--env/acme/default.nix44
1 files changed, 44 insertions, 0 deletions
diff --git a/env/acme/default.nix b/env/acme/default.nix
new file mode 100644
index 0000000..779b4e2
--- /dev/null
+++ b/env/acme/default.nix
@@ -0,0 +1,44 @@
+{ config, lib, ... }:
+with lib; let
+ cfg = config.local;
+in
+{
+ options.local = with types; {
+ domains = mkOption {
+ type = attrsOf (attrsOf str);
+ };
+
+ certs = mapAttrs
+ (_: _: {
+ enable = mkEnableOption "TLS cert for ${name}";
+ })
+ cfg.domains;
+ };
+
+ config = {
+ security.acme = {
+ acceptTerms = true;
+
+ defaults = {
+ email = "security@${config.networking.domain}";
+ renewInterval = "weekly";
+ };
+
+ certs =
+ let
+ domainSort = sort (a: b: splitString "." a < splitString "." b);
+
+ certConfig = domains: {
+ domain = domains.main;
+ extraDomainNames = domainSort (attrValues (filterAttrs (k: _: k != "main") domains));
+ webroot = "/var/lib/acme/acme-challenge";
+ };
+ in
+ mapAttrs'
+ (_: value: nameValuePair value.main (certConfig value))
+ (filterAttrs (name: _: cfg.certs.${name}.enable) cfg.domains);
+ };
+
+ local.domains = import ./domains.nix;
+ };
+}