nixos-config/lib/fudo/acme-for-hostname.nix

70 lines
1.5 KiB
Nix
Raw Normal View History

2020-01-15 09:24:11 -08:00
# Starts an Nginx server on $HOSTNAME just to get a cert for this host
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.fudo.acme;
2020-06-25 20:38:50 -07:00
# wwwRoot = hostname:
# pkgs.writeTextFile {
# name = "index.html";
# text = ''
# <html>
# <head>
# <title>${hostname}</title>
# </head>
# <body>
# <h1>${hostname}</title>
# </body>
# </html>
# '';
# destination = "/www";
# };
2020-01-15 09:24:11 -08:00
in {
options.fudo.acme = {
2020-06-25 20:38:50 -07:00
enable = mkEnableOption "Fetch ACME certs for supplied local hostnames.";
2020-01-15 09:24:11 -08:00
hostnames = mkOption {
type = with types; listOf str;
description = "A list of hostnames mapping to this host, for which to acquire SSL certificates.";
default = [];
example = [
"my.hostname.com"
"alt.hostname.com"
];
};
2020-06-25 20:38:50 -07:00
admin-address = mkOption {
type = types.str;
description = "The admin address in charge of these addresses.";
default = "admin@fudo.org";
};
2020-01-15 09:24:11 -08:00
};
2020-06-25 20:38:50 -07:00
config = mkIf cfg.enable {
2020-01-15 09:24:11 -08:00
services.nginx = {
enable = true;
virtualHosts = listToAttrs
(map
(hostname:
nameValuePair hostname
{
enableACME = true;
forceSSL = true;
2020-06-25 20:38:50 -07:00
# root = (wwwRoot hostname) + ("/" + "www");
2020-01-15 09:24:11 -08:00
})
cfg.hostnames);
};
security.acme.certs = listToAttrs
2020-06-25 20:38:50 -07:00
(map (hostname: nameValuePair hostname { email = cfg.admin-address; })
2020-01-15 09:24:11 -08:00
cfg.hostnames);
};
}