From: Ismaƫl Bouya Date: Sat, 1 Jun 2019 10:33:18 +0000 (+0200) Subject: Add webapp dirs in websites module X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FConfig%2FNix%2FNUR.git;a=commitdiff_plain;h=ea5b3f5102c388e8855c7d5eac57aae8d99f9b57 Add webapp dirs in websites module --- 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)} + ''; }