From ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Thu, 26 Dec 2019 10:04:12 -0500 Subject: nixos/httpd: add services.httpd.virtualHosts..locations option to match nginx --- .../services/web-servers/apache-httpd/default.nix | 34 ++++++++++++++++++---- 1 file changed, 28 insertions(+), 6 deletions(-) (limited to 'nixos/modules/services/web-servers/apache-httpd/default.nix') diff --git a/nixos/modules/services/web-servers/apache-httpd/default.nix b/nixos/modules/services/web-servers/apache-httpd/default.nix index fd17e4b54f0..9942c63acce 100644 --- a/nixos/modules/services/web-servers/apache-httpd/default.nix +++ b/nixos/modules/services/web-servers/apache-httpd/default.nix @@ -179,6 +179,28 @@ let then hostOpts.documentRoot else pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out" ; + + mkLocations = locations: concatStringsSep "\n" (map (config: '' + + ${optionalString (config.proxyPass != null) '' + + ProxyPass ${config.proxyPass} + ProxyPassReverse ${config.proxyPass} + + ''} + ${optionalString (config.index != null) '' + + DirectoryIndex ${config.index} + + ''} + ${optionalString (config.alias != null) '' + + Alias "${config.alias}" + + ''} + ${config.extraConfig} + + '') (sortProperties (mapAttrsToList (k: v: v // { location = k; }) locations))); in '' ${optionalString mainCfg.logPerVirtualHost '' @@ -217,12 +239,6 @@ let RedirectPermanent / ${hostOpts.globalRedirect} ''} - ${ - let makeFileConf = elem: '' - Alias ${elem.urlPath} ${elem.file} - ''; - in concatMapStrings makeFileConf hostOpts.servedFiles - } ${ let makeDirConf = elem: '' Alias ${elem.urlPath} ${elem.dir}/ @@ -235,6 +251,7 @@ let in concatMapStrings makeDirConf hostOpts.servedDirs } + ${mkLocations hostOpts.locations} ${hostOpts.extraConfig} '' ; @@ -606,6 +623,11 @@ in } ]; + warnings = + mapAttrsToList (name: hostOpts: '' + Using config.services.httpd.virtualHosts."${name}".servedFiles is deprecated and will become unsupported in a future release. Your configuration will continue to work as is but please migrate your configuration to config.services.httpd.virtualHosts."${name}".locations before the 20.09 release of NixOS. + '') (filterAttrs (name: hostOpts: hostOpts.servedFiles != []) mainCfg.virtualHosts); + users.users = optionalAttrs (mainCfg.user == "wwwrun") { wwwrun = { group = mainCfg.group; -- cgit 1.4.1