8 inherit (lib) escapeShellArg stringAfter;
12 pem-path = "${cert-cfg.dir}/${name}.pem";
13 key-path = "${cert-cfg.dir}/${name}.key";
16 name = "make-cert-${name}";
17 value = stringAfter [ "users" ] (
19 if [[ ! -e ${escapeShellArg pem-path} ]];then
20 ${pkgs.coreutils}/bin/mkdir -p ${escapeShellArg cert-cfg.dir}
21 ${pkgs.openssl}/bin/openssl req -batch -x509 -newkey rsa:4096 \
22 -keyout ${escapeShellArg key-path} \
23 -out ${escapeShellArg pem-path} \
24 -days ${escapeShellArg cert-cfg.lifetime} \
26 ${pkgs.coreutils}/bin/chown ${escapeShellArg cert-cfg.user} ${escapeShellArg key-path}
29 + lib.optionalString cert-cfg.print ''
30 echo Public certificate for ${escapeShellArg name}: >&2
31 ${pkgs.coreutils}/bin/cat ${escapeShellArg pem-path} >&2
38 chkno.make-certs = lib.mkOption {
39 description = "Certificates to generate.";
41 send-email.user = "stunnel";
42 send-print.user = "stunnel";
44 type = lib.types.attrsOf (
49 description = "Where to put the certificate and key.";
52 lifetime = lib.mkOption {
54 description = "Lifetime of the generated certificate (in days).";
55 # This doesn't yet include any notion of certificate rotation,
56 # so just make really long-lived certificates for now.
59 print = lib.mkOption {
60 type = lib.types.bool;
61 description = "If set, print the certificate (public key) during activation.";
66 description = "The username that owns (can read) the secret key.";
74 system.activationScripts = lib.mapAttrs' mkActvationScript config.chkno.make-certs;