Try relax on derivation attribute to check for SSL

This commit is contained in:
Danila Fedorin 2021-10-23 00:42:03 -07:00
parent 853dcaac4b
commit e27024dc8a
1 changed files with 5 additions and 10 deletions

View File

@ -2,22 +2,22 @@
with lib; with lib;
let let
cfg = config.services.danilafe-blog; cfg = config.services.danilafe-blog;
sslForDomain = domain: (cfg.ssl == true) || (cfg.ssl."${domain}" or false); sslForDomain = domain: package: package.ssl;
anySsl = any sslForDomain (attrNames cfg.domains); anySsl = any id (mapAttrsToList sslForDomain cfg.domains);
virtualHost = domain: package: virtualHost = domain: package:
{ {
virtualHosts."${domain}" = mkMerge [ virtualHosts."${domain}" = mkMerge [
{ {
root = package; root = package;
} }
(mkIf (sslForDomain domain) { (mkIf (sslForDomain domain package) {
addSSL = true; addSSL = true;
enableACME = true; enableACME = true;
acmeRoot = cfg.challengePath; acmeRoot = cfg.challengePath;
}) })
]; ];
}; };
service = domain: service = domain: package:
{ {
# Workaround for new configuration setting all of /var to be readonly. # Workaround for new configuration setting all of /var to be readonly.
# See https://github.com/NixOS/nixpkgs/issues/139310 # See https://github.com/NixOS/nixpkgs/issues/139310
@ -26,16 +26,11 @@ let
}; };
}; };
virtualHosts = mapAttrsToList virtualHost cfg.domains; virtualHosts = mapAttrsToList virtualHost cfg.domains;
services = map service (filter sslForDomain (attrNames cfg.domains)); services = mapAttrsToList service (filterAttrs sslForDomain cfg.domains);
in in
{ {
options.services.danilafe-blog = { options.services.danilafe-blog = {
enable = mkEnableOption "Daniel's blog service"; enable = mkEnableOption "Daniel's blog service";
ssl = mkOption {
type = types.either types.bool (types.attrsOf types.bool);
default = false;
description = "Enable SSL and ACME for all or some domains.";
};
domains = mkOption { domains = mkOption {
type = types.attrsOf types.package; type = types.attrsOf types.package;
default = {}; default = {};