]> git.immae.eu Git - perso/Immae/Config/Nix.git/commitdiff
Pre-generate certificates with acme
authorIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 12 May 2019 23:34:11 +0000 (01:34 +0200)
committerIsmaël Bouya <ismael.bouya@normalesup.org>
Sun, 12 May 2019 23:34:11 +0000 (01:34 +0200)
Fixes https://git.immae.eu/mantisbt/view.php?id=81

nixops/modules/certificates.nix

index bfad4e1d82cf9b23557dc28feadb051df3eb738c..08f84fd1786c1a1ee13ae01b6071852b4ec3ecb7 100644 (file)
         domain = "eldiron.immae.eu";
       };
     };
+
+    systemd.services = lib.attrsets.mapAttrs' (k: v:
+      lib.attrsets.nameValuePair "acme-selfsigned-${k}" (lib.mkBefore { script =
+        (lib.optionalString (builtins.elem "cert.pem" v.plugins) ''
+        cp $workdir/server.crt /var/lib/acme/${k}/cert.pem
+        chown '${v.user}:${v.group}' /var/lib/acme/${k}/cert.pem
+        chmod ${if v.allowKeysForGroup then "750" else "700"} /var/lib/acme/${k}/cert.pem
+        '') +
+        (lib.optionalString (builtins.elem "chain.pem" v.plugins) ''
+        cp $workdir/ca.crt /var/lib/acme/${k}/chain.pem
+        chown '${v.user}:${v.group}' /var/lib/acme/${k}/chain.pem
+        chmod ${if v.allowKeysForGroup then "750" else "700"} /var/lib/acme/${k}/chain.pem
+        '')
+      ; })
+    ) config.security.acme.certs // {
+      httpdProd.after = [ "acme-selfsigned-certificates.target" ];
+      httpdProd.wants = [ "acme-selfsigned-certificates.target" ];
+      httpdTools.after = [ "acme-selfsigned-certificates.target" ];
+      httpdTools.wants = [ "acme-selfsigned-certificates.target" ];
+      httpdInte.after = [ "acme-selfsigned-certificates.target" ];
+      httpdInte.wants = [ "acme-selfsigned-certificates.target" ];
+    };
   };
 }