]> git.scottworley.com Git - nixos-make-certs/blobdiff - modules/make-certs.nix
Description and example
[nixos-make-certs] / modules / make-certs.nix
index 812c5a05dabe52622d8cc1e1baf42cad722ed01b..2da6e7dc94a7d239989c00fada9f4577cb794cc2 100644 (file)
@@ -1,13 +1,13 @@
 { lib, config, pkgs, ... }:
 let
-  inherit (lib) escapeShellArg;
+  inherit (lib) escapeShellArg stringAfter;
   mkActvationScript = name: cert-cfg:
     let
       pem-path = "${cert-cfg.dir}/${name}.pem";
       key-path = "${cert-cfg.dir}/${name}.key";
     in {
       name = "make-cert-${name}";
-      value = ''
+      value = stringAfter [ "users" ] (''
         if [[ ! -e ${escapeShellArg pem-path} ]];then
           ${pkgs.coreutils}/bin/mkdir -p ${escapeShellArg cert-cfg.dir}
           ${pkgs.openssl}/bin/openssl req -batch -x509 -newkey rsa:4096 \
@@ -19,11 +19,19 @@ let
             escapeShellArg key-path
           }
         fi
-      '';
+      '' + lib.optionalString cert-cfg.print ''
+        echo Public certificate for ${escapeShellArg name}: >&2
+        ${pkgs.coreutils}/bin/cat ${escapeShellArg pem-path} >&2
+      '');
     };
 in {
   options = {
     chkno.make-certs = lib.mkOption {
+      description = "Certificates to generate.";
+      example = {
+        send-email.user = "stunnel";
+        send-print.user = "stunnel";
+      };
       type = lib.types.attrsOf (lib.types.submodule {
         options = {
           dir = lib.mkOption {
@@ -38,6 +46,11 @@ in {
             # so just make really long-lived certificates for now.
             default = "99999";
           };
+          print = lib.mkOption {
+            type = lib.types.bool;
+            description = "If set, print the certificate (public key) during activation.";
+            default = false;
+          };
           user = lib.mkOption {
             type = lib.types.str;
             description = "The username that owns (can read) the secret key.";