From ea5b3f5102c388e8855c7d5eac57aae8d99f9b57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 1 Jun 2019 12:33:18 +0200 Subject: Add webapp dirs in websites module --- modules/websites/default.nix | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/modules/websites/default.nix b/modules/websites/default.nix index 4b21efb7..2e1d23a4 100644 --- a/modules/websites/default.nix +++ b/modules/websites/default.nix @@ -1,11 +1,25 @@ { 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"; @@ -164,17 +178,17 @@ in ++ (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); @@ -200,7 +214,7 @@ in ); 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)); @@ -210,4 +224,9 @@ in 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)} + ''; } -- cgit v1.2.3