summary refs log tree commit diff
path: root/nixos/modules/services/web-servers/apache-httpd/default.nix
diff options
context:
space:
mode:
authorAaron Andersen <aaron@fosslib.net>2019-12-26 10:04:12 -0500
committerAaron Andersen <aaron@fosslib.net>2020-01-23 21:03:15 -0500
commitae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f (patch)
tree15ea8cf401ac624200afb01f53899348f5b4d5f3 /nixos/modules/services/web-servers/apache-httpd/default.nix
parent109f179e445f73e5740028cffd2e44741dcdb5e8 (diff)
downloadnixpkgs-ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f.tar
nixpkgs-ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f.tar.gz
nixpkgs-ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f.tar.bz2
nixpkgs-ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f.tar.lz
nixpkgs-ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f.tar.xz
nixpkgs-ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f.tar.zst
nixpkgs-ae9980040fe267aa6e1b04e10c9ef1cbfe7fb53f.zip
nixos/httpd: add services.httpd.virtualHosts.<name>.locations option to match nginx
Diffstat (limited to 'nixos/modules/services/web-servers/apache-httpd/default.nix')
-rw-r--r--nixos/modules/services/web-servers/apache-httpd/default.nix34
1 files changed, 28 insertions, 6 deletions
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: ''
+        <Location ${config.location}>
+          ${optionalString (config.proxyPass != null) ''
+            <IfModule mod_proxy.c>
+                ProxyPass ${config.proxyPass}
+                ProxyPassReverse ${config.proxyPass}
+            </IfModule>
+          ''}
+          ${optionalString (config.index != null) ''
+            <IfModule mod_dir.c>
+                DirectoryIndex ${config.index}
+            </IfModule>
+          ''}
+          ${optionalString (config.alias != null) ''
+            <IfModule mod_alias.c>
+                Alias "${config.alias}"
+            </IfModule>
+          ''}
+          ${config.extraConfig}
+        </Location>
+      '') (sortProperties (mapAttrsToList (k: v: v // { location = k; }) locations)));
     in
       ''
         ${optionalString mainCfg.logPerVirtualHost ''
@@ -218,12 +240,6 @@ let
         ''}
 
         ${
-          let makeFileConf = elem: ''
-                Alias ${elem.urlPath} ${elem.file}
-              '';
-          in concatMapStrings makeFileConf hostOpts.servedFiles
-        }
-        ${
           let makeDirConf = elem: ''
                 Alias ${elem.urlPath} ${elem.dir}/
                 <Directory ${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;