1 { lib, config, pkgs, ... }:
3 inherit (lib) escapeShellArg;
4 mkActvationScript = name: cert-cfg:
6 pem-path = "${cert-cfg.dir}/${name}.pem";
7 key-path = "${cert-cfg.dir}/${name}.key";
9 name = "make-cert-${name}";
11 if [[ ! -e ${escapeShellArg pem-path} ]];then
12 ${pkgs.coreutils}/bin/mkdir -p ${escapeShellArg cert-cfg.dir}
13 ${pkgs.openssl}/bin/openssl req -batch -x509 -newkey rsa:4096 \
14 -keyout ${escapeShellArg key-path} \
15 -out ${escapeShellArg pem-path} \
16 -days ${escapeShellArg cert-cfg.lifetime} \
18 ${pkgs.coreutils}/bin/chown ${escapeShellArg cert-cfg.user} ${
19 escapeShellArg key-path
26 chkno.make-certs = lib.mkOption {
27 type = lib.types.attrsOf (lib.types.submodule {
31 description = "Where to put the certificate and key.";
34 lifetime = lib.mkOption {
36 description = "Lifetime of the generated certificate (in days).";
37 # This doesn't yet include any notion of certificate rotation,
38 # so just make really long-lived certificates for now.
43 description = "The username that owns (can read) the secret key.";
50 system.activationScripts =
51 lib.mapAttrs' mkActvationScript config.chkno.make-certs;