git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #20366 from MarcWeber/submit/apache-port-to-listen

apache-httpd

commit36010e70464074fcd279fa91026d3b71d3a9b828 authorMichael Raskin <7c6f434c@mail.ru> dateSat 26 Nov 2016, 13:37 (10 years ago) parentfcc5a4db51f165
2 files changed+52−16
nixos/modules/services/web-servers/apache-httpd/default.nix+29−14 nixos/modules/services/web-servers/apache-httpd/per-server-options.nix+23−2
nixos/modules/services/web-servers/apache-httpd/default.nix+29−14
@@ -16,7 +16,17 @@ let
1616
1717 phpMajorVersion = head (splitString "." php.version);
1818
19− getPort = cfg: if cfg.port != 0 then cfg.port else if cfg.enableSSL then 443 else 80;
19+ defaultListen = cfg: if cfg.enableSSL
20+ then [{ip = "*"; port = 443;}]
21+ else [{ip = "*"; port = 80;}];
22+
23+ getListen = cfg:
24+ let list = (lib.optional (cfg.port != 0) {ip = "*"; port = cfg.port;}) ++ cfg.listen;
25+ in if list == []
26+ then defaultListen cfg
27+ else list;
28+
29+ listenToString = l: "${l.ip}:${toString l.port}";
2030
2131 extraModules = attrByPath ["extraModules"] [] mainCfg;
2232 extraForeignModules = filter isAttrs extraModules;
@@ -25,10 +35,13 @@ let
2535
2636 makeServerInfo = cfg: {
2737 # Canonical name must not include a trailing slash.
28− canonicalName =
29− (if cfg.enableSSL then "https" else "http") + "://" +
30− cfg.hostName +
31− (if getPort cfg != (if cfg.enableSSL then 443 else 80) then ":${toString (getPort cfg)}" else "");
38+ canonicalNames =
39+ let defaultPort = (head (defaultListen cfg)).port; in
40+ map (port:
41+ (if cfg.enableSSL then "https" else "http") + "://" +
42+ cfg.hostName +
43+ (if port != defaultPort then ":${toString port}" else "")
44+ ) (map (x: x.port) (getListen cfg));
3245
3346 # Admin address: inherit from the main server if not specified for
3447 # a virtual host.
@@ -224,7 +237,7 @@ let
224237 ++ (map (svc: svc.robotsEntries) subservices)));
225238
226239 in ''
227− ServerName ${serverInfo.canonicalName}
240+ ${concatStringsSep "\n" (map (n: "ServerName ${n}") serverInfo.canonicalNames)}
228241
229242 ${concatMapStrings (alias: "ServerAlias ${alias}\n") cfg.serverAliases}
230243
@@ -326,9 +339,10 @@ let
326339 </IfModule>
327340
328341 ${let
329− ports = map getPort allHosts;
330− uniquePorts = uniqList {inputList = ports;};
331− in concatMapStrings (port: "Listen ${toString port}\n") uniquePorts
342+ listen = concatMap getListen allHosts;
343+ toStr = listen: "Listen ${listenToString listen}\n";
344+ uniqueListen = uniqList {inputList = map toStr listen;};
345+ in concatStrings uniqueListen
332346 }
333347
334348 User ${mainCfg.user}
@@ -382,15 +396,15 @@ let
382396
383397 # Always enable virtual hosts; it doesn't seem to hurt.
384398 ${let
385− ports = map getPort allHosts;
386− uniquePorts = uniqList {inputList = ports;};
387− directives = concatMapStrings (port: "NameVirtualHost *:${toString port}\n") uniquePorts;
399+ listen = concatMap getListen allHosts;
400+ uniqueListen = uniqList {inputList = listen;};
401+ directives = concatMapStrings (listen: "NameVirtualHost ${listenToString listen}\n") uniqueListen;
388402 in optionalString (!version24) directives
389403 }
390404
391405 ${let
392406 makeVirtualHost = vhost: ''
393− <VirtualHost *:${toString (getPort vhost)}>
407+ <VirtualHost ${concatStringsSep " " (map listenToString (getListen vhost))}>
394408 ${perServerConf false vhost}
395409 </VirtualHost>
396410 '';
@@ -628,6 +642,8 @@ in
628642 message = "SSL is enabled for httpd, but sslServerCert and/or sslServerKey haven't been specified."; }
629643 ];
630644
645+ warnings = map (cfg: ''apache-httpd's port option is deprecated. Use listen = [{/*ip = "*"; */ port = ${toString cfg.port}";}]; instead'' ) (lib.filter (cfg: cfg.port != 0) allHosts);
646+
631647 users.extraUsers = optionalAttrs (mainCfg.user == "wwwrun") (singleton
632648 { name = "wwwrun";
633649 group = mainCfg.group;
@@ -712,5 +728,4 @@ in
712728 };
713729
714730 };
715−
716731}
nixos/modules/services/web-servers/apache-httpd/per-server-options.nix+23−2
@@ -28,9 +28,30 @@ with lib;
2828 type = types.int;
2929 default = 0;
3030 description = ''
31− Port for the server. 0 means use the default port: 80 for http
32− and 443 for https (i.e. when enableSSL is set).
31+ Port for the server. Option will be removed, use <option>listen</option> instead.
32+ '';
33+ };
34+
35+ listen = mkOption {
36+ type = types.listOf (types.submodule (
37+ {
38+ options = {
39+ port = mkOption {
40+ type = types.int;
41+ description = "port to listen on";
42+ };
43+ ip = mkOption {
44+ type = types.string;
45+ default = "*";
46+ description = "Ip to listen on. 0.0.0.0 for ipv4 only, * for all.";
47+ };
48+ };
49+ } ));
50+ description = ''
51+ List of { /* ip: "*"; */ port = 80;} to listen on
3352 '';
53+
54+ default = [];
3455 };
3556
3657 enableSSL = mkOption {