{ lib, config, ... }: with lib;
let
- cfg = config.services.websites;
+ cfg = {
+ certs = config.services.websitesCerts;
+ webappDirs = config.services.websitesWebappDirs;
+ env = config.services.websites;
+ };
in
{
options.services.websitesCerts = mkOption {
description = "Default websites configuration for certificates as accepted by acme";
};
+ options.services.websitesWebappDirs = mkOption {
+ description = ''
+ Defines a symlink between /run/current-system/webapps and a store
+ app directory to be used in http configuration. Permits to avoid
+ restarting httpd when only the folder name changes.
+ '';
+ type = types.attrsOf types.path;
+ default = {};
+ };
+ # TODO: ajouter /run/current-system/webapps (RO) et webapps (RW)
options.services.websites = with types; mkOption {
default = {};
description = "Each type of website to enable will target a distinct httpd server";
++ (attrsets.mapAttrsToList (n: v: toVhost icfg.ips v) icfg.vhostConfs)
++ [ (redirectVhost icfg.ips) ];
})
- ) cfg;
+ ) cfg.env;
config.services.filesWatcher = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
"httpd${icfg.httpdName}" {
paths = icfg.watchPaths;
waitTime = 5;
}
- ) cfg;
+ ) cfg.env;
config.security.acme.certs = let
- typesToManage = attrsets.filterAttrs (k: v: v.enable) cfg;
+ typesToManage = attrsets.filterAttrs (k: v: v.enable) cfg.env;
flatVhosts = lists.flatten (attrsets.mapAttrsToList (k: v:
attrValues v.vhostConfs
) typesToManage);
);
in attrsets.mapAttrs (k: g:
if (!isNull (groupToDomain g))
- then config.services.websitesCerts // {
+ then cfg.certs // {
domain = groupToDomain g;
extraDomains = builtins.listToAttrs (
map (d: attrsets.nameValuePair d null) (extraDomains g));
map (d: attrsets.nameValuePair d null) (extraDomains g));
}
) groupedCerts;
+
+ config.system.extraSystemBuilderCmds = lib.mkIf (builtins.length (builtins.attrValues cfg.webappDirs) > 0) ''
+ mkdir -p $out/webapps
+ ${builtins.concatStringsSep "\n" (attrsets.mapAttrsToList (name: path: "ln -s ${path} $out/webapps/${name}") cfg.webappDirs)}
+ '';
}