From 837a0c05e5c9c5ae3a4bc29fb1cbc4b26bceb077 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 18 Sep 2014 18:48:28 +0200 Subject: [PATCH] httpd: Don't emit robots.txt if there are no robots entries --- .../web-servers/apache-httpd/default.nix | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/nixos/modules/services/web-servers/apache-httpd/default.nix b/nixos/modules/services/web-servers/apache-httpd/default.nix index 9ac28373dac..c452cd126ff 100644 --- a/nixos/modules/services/web-servers/apache-httpd/default.nix +++ b/nixos/modules/services/web-servers/apache-httpd/default.nix @@ -208,16 +208,11 @@ let ''; - robotsTxt = pkgs.writeText "robots.txt" '' - ${# If this is a vhost, the include the entries for the main server as well. - if isMainServer then "" - else concatMapStrings (svc: svc.robotsEntries) mainSubservices} - ${concatMapStrings (svc: svc.robotsEntries) subservices} - ''; - - robotsConf = '' - Alias /robots.txt ${robotsTxt} - ''; + robotsTxt = + concatStringsSep "\n" ( + # If this is a vhost, the include the entries for the main server as well. + (if isMainServer then [] else map (svc: svc.robotsEntries) mainSubservices) + ++ (map (svc: svc.robotsEntries) subservices)); in '' ServerName ${serverInfo.canonicalName} @@ -245,7 +240,9 @@ let CustomLog ${mainCfg.logDir}/access_log-${cfg.hostName} ${cfg.logFormat} '' else ""} - ${robotsConf} + ${optionalString (robotsTxt != "") '' + Alias /robots.txt ${pkgs.writeText "robots.txt" robotsTxt} + ''} ${if isMainServer || maybeDocumentRoot != null then documentRootConf else ""}