nixos/httpd: remove deprecated extraSubservices option
This commit is contained in:
parent
463eb7daff
commit
9a91679b7a
|
@ -31,70 +31,8 @@ let
|
||||||
extraForeignModules = filter isAttrs extraModules;
|
extraForeignModules = filter isAttrs extraModules;
|
||||||
extraApacheModules = filter isString extraModules;
|
extraApacheModules = filter isString extraModules;
|
||||||
|
|
||||||
|
|
||||||
makeServerInfo = cfg: {
|
|
||||||
# Canonical name must not include a trailing slash.
|
|
||||||
canonicalNames =
|
|
||||||
let defaultPort = (head (defaultListen cfg)).port; in
|
|
||||||
map (port:
|
|
||||||
(if cfg.enableSSL then "https" else "http") + "://" +
|
|
||||||
cfg.hostName +
|
|
||||||
(if port != defaultPort then ":${toString port}" else "")
|
|
||||||
) (map (x: x.port) (getListen cfg));
|
|
||||||
|
|
||||||
# Admin address: inherit from the main server if not specified for
|
|
||||||
# a virtual host.
|
|
||||||
adminAddr = if cfg.adminAddr != null then cfg.adminAddr else mainCfg.adminAddr;
|
|
||||||
|
|
||||||
vhostConfig = cfg;
|
|
||||||
serverConfig = mainCfg;
|
|
||||||
fullConfig = config; # machine config
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
allHosts = [mainCfg] ++ mainCfg.virtualHosts;
|
allHosts = [mainCfg] ++ mainCfg.virtualHosts;
|
||||||
|
|
||||||
|
|
||||||
callSubservices = serverInfo: defs:
|
|
||||||
let f = svc:
|
|
||||||
let
|
|
||||||
svcFunction =
|
|
||||||
if svc ? function then svc.function
|
|
||||||
# instead of using serviceType="mediawiki"; you can copy mediawiki.nix to any location outside nixpkgs, modify it at will, and use serviceExpression=./mediawiki.nix;
|
|
||||||
else if svc ? serviceExpression then import (toString svc.serviceExpression)
|
|
||||||
else import (toString "${toString ./.}/${if svc ? serviceType then svc.serviceType else svc.serviceName}.nix");
|
|
||||||
config = (evalModules
|
|
||||||
{ modules = [ { options = res.options; config = svc.config or svc; } ];
|
|
||||||
check = false;
|
|
||||||
}).config;
|
|
||||||
defaults = {
|
|
||||||
extraConfig = "";
|
|
||||||
extraModules = [];
|
|
||||||
extraModulesPre = [];
|
|
||||||
extraPath = [];
|
|
||||||
extraServerPath = [];
|
|
||||||
globalEnvVars = [];
|
|
||||||
robotsEntries = "";
|
|
||||||
startupScript = "";
|
|
||||||
enablePHP = false;
|
|
||||||
enablePerl = false;
|
|
||||||
phpOptions = "";
|
|
||||||
options = {};
|
|
||||||
documentRoot = null;
|
|
||||||
};
|
|
||||||
res = defaults // svcFunction { inherit config lib pkgs serverInfo php; };
|
|
||||||
in res;
|
|
||||||
in map f defs;
|
|
||||||
|
|
||||||
|
|
||||||
# !!! callSubservices is expensive
|
|
||||||
subservicesFor = cfg: callSubservices (makeServerInfo cfg) cfg.extraSubservices;
|
|
||||||
|
|
||||||
mainSubservices = subservicesFor mainCfg;
|
|
||||||
|
|
||||||
allSubservices = mainSubservices ++ concatMap subservicesFor mainCfg.virtualHosts;
|
|
||||||
|
|
||||||
|
|
||||||
enableSSL = any (vhost: vhost.enableSSL) allHosts;
|
enableSSL = any (vhost: vhost.enableSSL) allHosts;
|
||||||
|
|
||||||
|
|
||||||
|
@ -188,13 +126,18 @@ let
|
||||||
|
|
||||||
perServerConf = isMainServer: cfg: let
|
perServerConf = isMainServer: cfg: let
|
||||||
|
|
||||||
serverInfo = makeServerInfo cfg;
|
# Canonical name must not include a trailing slash.
|
||||||
|
canonicalNames =
|
||||||
subservices = callSubservices serverInfo cfg.extraSubservices;
|
let defaultPort = (head (defaultListen cfg)).port; in
|
||||||
|
map (port:
|
||||||
|
(if cfg.enableSSL then "https" else "http") + "://" +
|
||||||
|
cfg.hostName +
|
||||||
|
(if port != defaultPort then ":${toString port}" else "")
|
||||||
|
) (map (x: x.port) (getListen cfg));
|
||||||
|
|
||||||
maybeDocumentRoot = fold (svc: acc:
|
maybeDocumentRoot = fold (svc: acc:
|
||||||
if acc == null then svc.documentRoot else assert svc.documentRoot == null; acc
|
if acc == null then svc.documentRoot else assert svc.documentRoot == null; acc
|
||||||
) null ([ cfg ] ++ subservices);
|
) null ([ cfg ]);
|
||||||
|
|
||||||
documentRoot = if maybeDocumentRoot != null then maybeDocumentRoot else
|
documentRoot = if maybeDocumentRoot != null then maybeDocumentRoot else
|
||||||
pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out";
|
pkgs.runCommand "empty" { preferLocalBuild = true; } "mkdir -p $out";
|
||||||
|
@ -209,15 +152,11 @@ let
|
||||||
</Directory>
|
</Directory>
|
||||||
'';
|
'';
|
||||||
|
|
||||||
robotsTxt =
|
# If this is a vhost, the include the entries for the main server as well.
|
||||||
concatStringsSep "\n" (filter (x: x != "") (
|
robotsTxt = concatStringsSep "\n" (filter (x: x != "") ([ cfg.robotsEntries ] ++ lib.optional (!isMainServer) mainCfg.robotsEntries));
|
||||||
# If this is a vhost, the include the entries for the main server as well.
|
|
||||||
(if isMainServer then [] else [mainCfg.robotsEntries] ++ map (svc: svc.robotsEntries) mainSubservices)
|
|
||||||
++ [cfg.robotsEntries]
|
|
||||||
++ (map (svc: svc.robotsEntries) subservices)));
|
|
||||||
|
|
||||||
in ''
|
in ''
|
||||||
${concatStringsSep "\n" (map (n: "ServerName ${n}") serverInfo.canonicalNames)}
|
${concatStringsSep "\n" (map (n: "ServerName ${n}") canonicalNames)}
|
||||||
|
|
||||||
${concatMapStrings (alias: "ServerAlias ${alias}\n") cfg.serverAliases}
|
${concatMapStrings (alias: "ServerAlias ${alias}\n") cfg.serverAliases}
|
||||||
|
|
||||||
|
@ -292,8 +231,6 @@ let
|
||||||
in concatMapStrings makeDirConf cfg.servedDirs
|
in concatMapStrings makeDirConf cfg.servedDirs
|
||||||
}
|
}
|
||||||
|
|
||||||
${concatMapStrings (svc: svc.extraConfig) subservices}
|
|
||||||
|
|
||||||
${cfg.extraConfig}
|
${cfg.extraConfig}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -328,13 +265,10 @@ let
|
||||||
|
|
||||||
${let
|
${let
|
||||||
load = {name, path}: "LoadModule ${name}_module ${path}\n";
|
load = {name, path}: "LoadModule ${name}_module ${path}\n";
|
||||||
allModules =
|
allModules = map (name: {inherit name; path = "${httpd}/modules/mod_${name}.so";}) apacheModules
|
||||||
concatMap (svc: svc.extraModulesPre) allSubservices
|
|
||||||
++ map (name: {inherit name; path = "${httpd}/modules/mod_${name}.so";}) apacheModules
|
|
||||||
++ optional mainCfg.enableMellon { name = "auth_mellon"; path = "${pkgs.apacheHttpdPackages.mod_auth_mellon}/modules/mod_auth_mellon.so"; }
|
++ optional mainCfg.enableMellon { name = "auth_mellon"; path = "${pkgs.apacheHttpdPackages.mod_auth_mellon}/modules/mod_auth_mellon.so"; }
|
||||||
++ optional enablePHP { name = "php${phpMajorVersion}"; path = "${php}/modules/libphp${phpMajorVersion}.so"; }
|
++ optional mainCfg.enablePHP { name = "php${phpMajorVersion}"; path = "${php}/modules/libphp${phpMajorVersion}.so"; }
|
||||||
++ optional enablePerl { name = "perl"; path = "${mod_perl}/modules/mod_perl.so"; }
|
++ optional mainCfg.enablePerl { name = "perl"; path = "${mod_perl}/modules/mod_perl.so"; }
|
||||||
++ concatMap (svc: svc.extraModules) allSubservices
|
|
||||||
++ extraForeignModules;
|
++ extraForeignModules;
|
||||||
in concatMapStrings load (unique allModules)
|
in concatMapStrings load (unique allModules)
|
||||||
}
|
}
|
||||||
|
@ -385,17 +319,10 @@ let
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
||||||
enablePHP = mainCfg.enablePHP || any (svc: svc.enablePHP) allSubservices;
|
|
||||||
|
|
||||||
enablePerl = mainCfg.enablePerl || any (svc: svc.enablePerl) allSubservices;
|
|
||||||
|
|
||||||
|
|
||||||
# Generate the PHP configuration file. Should probably be factored
|
# Generate the PHP configuration file. Should probably be factored
|
||||||
# out into a separate module.
|
# out into a separate module.
|
||||||
phpIni = pkgs.runCommand "php.ini"
|
phpIni = pkgs.runCommand "php.ini"
|
||||||
{ options = concatStringsSep "\n"
|
{ options = mainCfg.phpOptions;
|
||||||
([ mainCfg.phpOptions ] ++ (map (svc: svc.phpOptions) allSubservices));
|
|
||||||
preferLocalBuild = true;
|
preferLocalBuild = true;
|
||||||
}
|
}
|
||||||
''
|
''
|
||||||
|
@ -408,6 +335,10 @@ in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
|
imports = [
|
||||||
|
(mkRemovedOptionModule [ "services" "httpd" "extraSubservices" ] "Most existing subservices have been ported to the NixOS module system. Please update your configuration accordingly.")
|
||||||
|
];
|
||||||
|
|
||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
@ -637,8 +568,6 @@ in
|
||||||
message = "SSL is enabled for httpd, but sslServerCert and/or sslServerKey haven't been specified."; }
|
message = "SSL is enabled for httpd, but sslServerCert and/or sslServerKey haven't been specified."; }
|
||||||
];
|
];
|
||||||
|
|
||||||
warnings = map (cfg: "apache-httpd's extraSubservices option is deprecated. Most existing subservices have been ported to the NixOS module system. Please update your configuration accordingly.") (lib.filter (cfg: cfg.extraSubservices != []) allHosts);
|
|
||||||
|
|
||||||
users.users = optionalAttrs (mainCfg.user == "wwwrun") (singleton
|
users.users = optionalAttrs (mainCfg.user == "wwwrun") (singleton
|
||||||
{ name = "wwwrun";
|
{ name = "wwwrun";
|
||||||
group = mainCfg.group;
|
group = mainCfg.group;
|
||||||
|
@ -651,7 +580,7 @@ in
|
||||||
gid = config.ids.gids.wwwrun;
|
gid = config.ids.gids.wwwrun;
|
||||||
});
|
});
|
||||||
|
|
||||||
environment.systemPackages = [httpd] ++ concatMap (svc: svc.extraPath) allSubservices;
|
environment.systemPackages = [httpd];
|
||||||
|
|
||||||
services.httpd.phpOptions =
|
services.httpd.phpOptions =
|
||||||
''
|
''
|
||||||
|
@ -674,13 +603,11 @@ in
|
||||||
|
|
||||||
path =
|
path =
|
||||||
[ httpd pkgs.coreutils pkgs.gnugrep ]
|
[ httpd pkgs.coreutils pkgs.gnugrep ]
|
||||||
++ optional enablePHP pkgs.system-sendmail # Needed for PHP's mail() function.
|
++ optional mainCfg.enablePHP pkgs.system-sendmail; # Needed for PHP's mail() function.
|
||||||
++ concatMap (svc: svc.extraServerPath) allSubservices;
|
|
||||||
|
|
||||||
environment =
|
environment =
|
||||||
optionalAttrs enablePHP { PHPRC = phpIni; }
|
optionalAttrs mainCfg.enablePHP { PHPRC = phpIni; }
|
||||||
// optionalAttrs mainCfg.enableMellon { LD_LIBRARY_PATH = "${pkgs.xmlsec}/lib"; }
|
// optionalAttrs mainCfg.enableMellon { LD_LIBRARY_PATH = "${pkgs.xmlsec}/lib"; };
|
||||||
// (listToAttrs (concatMap (svc: svc.globalEnvVars) allSubservices));
|
|
||||||
|
|
||||||
preStart =
|
preStart =
|
||||||
''
|
''
|
||||||
|
@ -698,12 +625,6 @@ in
|
||||||
for i in $(${pkgs.utillinux}/bin/ipcs -s | grep ' ${mainCfg.user} ' | cut -f2 -d ' '); do
|
for i in $(${pkgs.utillinux}/bin/ipcs -s | grep ' ${mainCfg.user} ' | cut -f2 -d ' '); do
|
||||||
${pkgs.utillinux}/bin/ipcrm -s $i
|
${pkgs.utillinux}/bin/ipcrm -s $i
|
||||||
done
|
done
|
||||||
|
|
||||||
# Run the startup hooks for the subservices.
|
|
||||||
for i in ${toString (map (svn: svn.startupScript) allSubservices)}; do
|
|
||||||
echo Running Apache startup hook $i...
|
|
||||||
$i
|
|
||||||
done
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig.ExecStart = "@${httpd}/bin/httpd httpd -f ${httpdConf}";
|
serviceConfig.ExecStart = "@${httpd}/bin/httpd httpd -f ${httpdConf}";
|
||||||
|
|
|
@ -133,12 +133,6 @@ with lib;
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
extraSubservices = mkOption {
|
|
||||||
type = types.listOf types.unspecified;
|
|
||||||
default = [];
|
|
||||||
description = "Extra subservices to enable in the webserver.";
|
|
||||||
};
|
|
||||||
|
|
||||||
enableUserDir = mkOption {
|
enableUserDir = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
|
|
Loading…
Reference in New Issue