X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=modules%2Fwebsites%2Fdefault.nix;h=2e1d23a48764a50b16fe3210a461b08e1b4601fb;hb=f4da0504f34817e39350ff7db2bc7e7e94992a03;hp=e57f505a86fae43fc3b523c5f9210db6b82a7895;hpb=9ade8f6eb774dc7d19d82a070199b5024786b819;p=perso%2FImmae%2FConfig%2FNix.git diff --git a/modules/websites/default.nix b/modules/websites/default.nix index e57f505..2e1d23a 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"; @@ -91,6 +105,13 @@ in }; }); }; + watchPaths = mkOption { + type = listOf string; + default = []; + description = '' + Paths to watch that should trigger a reload of httpd + ''; + }; }; }); }; @@ -157,10 +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.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); @@ -186,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)); @@ -196,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)} + ''; }