Give types to the Apache httpd options

This commit is contained in:
Eelco Dolstra 2013-10-29 14:03:39 +01:00
parent 0afdb1e933
commit 985f1f2d8a
2 changed files with 90 additions and 75 deletions

View File

@ -30,7 +30,7 @@ let
# Admin address: inherit from the main server if not specified for # Admin address: inherit from the main server if not specified for
# a virtual host. # a virtual host.
adminAddr = if cfg.adminAddr != "" then cfg.adminAddr else mainCfg.adminAddr; adminAddr = if cfg.adminAddr != null then cfg.adminAddr else mainCfg.adminAddr;
vhostConfig = cfg; vhostConfig = cfg;
serverConfig = mainCfg; serverConfig = mainCfg;
@ -217,7 +217,7 @@ let
${concatMapStrings (alias: "ServerAlias ${alias}\n") cfg.serverAliases} ${concatMapStrings (alias: "ServerAlias ${alias}\n") cfg.serverAliases}
${if cfg.sslServerCert != "" then '' ${if cfg.sslServerCert != null then ''
SSLCertificateFile ${cfg.sslServerCert} SSLCertificateFile ${cfg.sslServerCert}
SSLCertificateKeyFile ${cfg.sslServerKey} SSLCertificateKeyFile ${cfg.sslServerKey}
'' else ""} '' else ""}
@ -229,7 +229,7 @@ let
SSLEngine off SSLEngine off
'' else ""} '' else ""}
${if isMainServer || cfg.adminAddr != "" then '' ${if isMainServer || cfg.adminAddr != null then ''
ServerAdmin ${cfg.adminAddr} ServerAdmin ${cfg.adminAddr}
'' else ""} '' else ""}
@ -260,7 +260,7 @@ let
'' else ""} '' else ""}
${if cfg.globalRedirect != "" then '' ${if cfg.globalRedirect != null then ''
RedirectPermanent / ${cfg.globalRedirect} RedirectPermanent / ${cfg.globalRedirect}
'' else ""} '' else ""}
@ -408,96 +408,104 @@ in
services.httpd = { services.httpd = {
enable = mkOption { enable = mkOption {
type = types.bool;
default = false; default = false;
description = " description = "Whether to enable the Apache HTTP Server.";
Whether to enable the Apache httpd server.
";
}; };
package = mkOption { package = mkOption {
type = types.path;
default = pkgs.apacheHttpd.override { mpm = mainCfg.multiProcessingModule; }; default = pkgs.apacheHttpd.override { mpm = mainCfg.multiProcessingModule; };
example = "pkgs.apacheHttpd_2_4"; example = "pkgs.apacheHttpd_2_4";
description = " description = ''
Overridable attribute of the Apache HTTP Server package to use. Overridable attribute of the Apache HTTP Server package to use.
"; '';
}; };
configFile = mkOption { configFile = mkOption {
type = types.path;
default = confFile; default = confFile;
example = literalExample ''pkgs.writeText "httpd.conf" "# my custom config file ...";''; example = literalExample ''pkgs.writeText "httpd.conf" "# my custom config file ...";'';
description = " description = ''
Overridable config file to use for Apache. By default, use the Override the configuration file used by Apache. By default,
file automatically generated by nixos. NixOS generates one automatically.
"; '';
}; };
extraConfig = mkOption { extraConfig = mkOption {
type = types.lines;
default = ""; default = "";
description = " description = ''
These configuration lines will be appended to the Apache config Cnfiguration lines appended to the generated Apache
file. Note that this mechanism may not work when <option>configFile</option> configuration file. Note that this mechanism may not work
is overridden. when <option>configFile</option> is overridden.
"; '';
}; };
extraModules = mkOption { extraModules = mkOption {
type = types.listOf types.unspecified;
default = []; default = [];
example = [ "proxy_connect" { name = "php5"; path = "${php}/modules/libphp5.so"; } ]; example = [ "proxy_connect" { name = "php5"; path = "${php}/modules/libphp5.so"; } ];
description = '' description = ''
Specifies additional Apache modules. These can be specified Additional Apache modules to be used. These can be
as a string in the case of modules distributed with Apache, specified as a string in the case of modules distributed
or as an attribute set specifying the with Apache, or as an attribute set specifying the
<varname>name</varname> and <varname>path</varname> of the <varname>name</varname> and <varname>path</varname> of the
module. module.
''; '';
}; };
logPerVirtualHost = mkOption { logPerVirtualHost = mkOption {
type = types.bool;
default = false; default = false;
description = " description = ''
If enabled, each virtual host gets its own If enabled, each virtual host gets its own
<filename>access_log</filename> and <filename>access_log</filename> and
<filename>error_log</filename>, namely suffixed by the <filename>error_log</filename>, namely suffixed by the
<option>hostName</option> of the virtual host. <option>hostName</option> of the virtual host.
"; '';
}; };
user = mkOption { user = mkOption {
type = types.str;
default = "wwwrun"; default = "wwwrun";
description = " description = ''
User account under which httpd runs. The account is created User account under which httpd runs. The account is created
automatically if it doesn't exist. automatically if it doesn't exist.
"; '';
}; };
group = mkOption { group = mkOption {
type = types.str;
default = "wwwrun"; default = "wwwrun";
description = " description = ''
Group under which httpd runs. The account is created Group under which httpd runs. The account is created
automatically if it doesn't exist. automatically if it doesn't exist.
"; '';
}; };
logDir = mkOption { logDir = mkOption {
type = types.path;
default = "/var/log/httpd"; default = "/var/log/httpd";
description = " description = ''
Directory for Apache's log files. It is created automatically. Directory for Apache's log files. It is created automatically.
"; '';
}; };
stateDir = mkOption { stateDir = mkOption {
default = "/var/run/httpd"; type = types.path;
description = " default = "/run/httpd";
description = ''
Directory for Apache's transient runtime state (such as PID Directory for Apache's transient runtime state (such as PID
files). It is created automatically. Note that the default, files). It is created automatically. Note that the default,
<filename>/var/run/httpd</filename>, is deleted at boot time. <filename>/run/httpd</filename>, is deleted at boot time.
"; '';
}; };
virtualHosts = mkOption { virtualHosts = mkOption {
type = types.listOf (types.submodule ( type = types.listOf (types.submodule (
{ options = import ./per-server-options.nix { { options = import ./per-server-options.nix {
inherit mkOption; inherit pkgs;
forMainServer = false; forMainServer = false;
}; };
})); }));
@ -519,6 +527,7 @@ in
}; };
phpOptions = mkOption { phpOptions = mkOption {
type = types.lines;
default = ""; default = "";
example = example =
'' ''
@ -529,9 +538,9 @@ in
}; };
multiProcessingModule = mkOption { multiProcessingModule = mkOption {
type = types.str;
default = "prefork"; default = "prefork";
example = "worker"; example = "worker";
type = types.uniq types.string;
description = description =
'' ''
Multi-processing module to be used by Apache. Available Multi-processing module to be used by Apache. Available
@ -546,12 +555,14 @@ in
}; };
maxClients = mkOption { maxClients = mkOption {
type = types.int;
default = 150; default = 150;
example = 8; example = 8;
description = "Maximum number of httpd processes (prefork)"; description = "Maximum number of httpd processes (prefork)";
}; };
maxRequestsPerChild = mkOption { maxRequestsPerChild = mkOption {
type = types.int;
default = 0; default = 0;
example = 500; example = 500;
description = description =
@ -561,7 +572,7 @@ in
# Include the options shared between the main server and virtual hosts. # Include the options shared between the main server and virtual hosts.
// (import ./per-server-options.nix { // (import ./per-server-options.nix {
inherit mkOption; inherit pkgs;
forMainServer = true; forMainServer = true;
}); });

View File

@ -3,38 +3,40 @@
# has additional options that affect the web server as a whole, like # has additional options that affect the web server as a whole, like
# the user/group to run under.) # the user/group to run under.)
{forMainServer, mkOption}: { forMainServer, pkgs }:
with pkgs.lib;
{ {
hostName = mkOption { hostName = mkOption {
type = types.str;
default = "localhost"; default = "localhost";
description = " description = "Canonical hostname for the server.";
Canonical hostname for the server.
";
}; };
serverAliases = mkOption { serverAliases = mkOption {
type = types.listOf types.str;
default = []; default = [];
example = ["www.example.org" "www.example.org:8080" "example.org"]; example = ["www.example.org" "www.example.org:8080" "example.org"];
description = " description = ''
Additional names of virtual hosts served by this virtual host configuration. Additional names of virtual hosts served by this virtual host configuration.
"; '';
}; };
port = mkOption { port = mkOption {
type = types.int;
default = 0; default = 0;
description = " description = ''
Port for the server. 0 means use the default port: 80 for http Port for the server. 0 means use the default port: 80 for http
and 443 for https (i.e. when enableSSL is set). and 443 for https (i.e. when enableSSL is set).
"; '';
}; };
enableSSL = mkOption { enableSSL = mkOption {
type = types.bool;
default = false; default = false;
description = " description = "Whether to enable SSL (https) support.";
Whether to enable SSL (https) support.
";
}; };
# Note: sslServerCert and sslServerKey can be left empty, but this # Note: sslServerCert and sslServerKey can be left empty, but this
@ -42,62 +44,62 @@
# main server). # main server).
sslServerCert = mkOption { sslServerCert = mkOption {
default = ""; type = types.nullOr types.path;
default = null;
example = "/var/host.cert"; example = "/var/host.cert";
description = " description = "Path to server SSL certificate.";
Path to server SSL certificate.
";
}; };
sslServerKey = mkOption { sslServerKey = mkOption {
default = ""; type = types.path;
example = "/var/host.key"; example = "/var/host.key";
description = " description = "Path to server SSL certificate key.";
Path to server SSL certificate key.
";
}; };
adminAddr = mkOption ({ adminAddr = mkOption ({
type = types.nullOr types.str;
example = "admin@example.org"; example = "admin@example.org";
description = " description = "E-mail address of the server administrator.";
E-mail address of the server administrator. } // (if forMainServer then {} else {default = null;}));
";
} // (if forMainServer then {} else {default = "";}));
documentRoot = mkOption { documentRoot = mkOption {
type = types.nullOr types.path;
default = null; default = null;
example = "/data/webserver/docs"; example = "/data/webserver/docs";
description = " description = ''
The path of Apache's document root directory. If left undefined, The path of Apache's document root directory. If left undefined,
an empty directory in the Nix store will be used as root. an empty directory in the Nix store will be used as root.
"; '';
}; };
servedDirs = mkOption { servedDirs = mkOption {
type = types.listOf types.attrs;
default = []; default = [];
example = [ example = [
{ urlPath = "/nix"; { urlPath = "/nix";
dir = "/home/eelco/Dev/nix-homepage"; dir = "/home/eelco/Dev/nix-homepage";
} }
]; ];
description = " description = ''
This option provides a simple way to serve static directories. This option provides a simple way to serve static directories.
"; '';
}; };
servedFiles = mkOption { servedFiles = mkOption {
type = types.listOf types.attrs;
default = []; default = [];
example = [ example = [
{ urlPath = "/foo/bar.png"; { urlPath = "/foo/bar.png";
dir = "/home/eelco/some-file.png"; dir = "/home/eelco/some-file.png";
} }
]; ];
description = " description = ''
This option provides a simple way to serve individual, static files. This option provides a simple way to serve individual, static files.
"; '';
}; };
extraConfig = mkOption { extraConfig = mkOption {
type = types.lines;
default = ""; default = "";
example = '' example = ''
<Directory /home> <Directory /home>
@ -105,37 +107,39 @@
AllowOverride All AllowOverride All
</Directory> </Directory>
''; '';
description = " description = ''
These lines go to httpd.conf verbatim. They will go after These lines go to httpd.conf verbatim. They will go after
directories and directory aliases defined by default. directories and directory aliases defined by default.
"; '';
}; };
extraSubservices = mkOption { extraSubservices = mkOption {
type = types.listOf types.unspecified;
default = []; default = [];
description = " description = "Extra subservices to enable in the webserver.";
Extra subservices to enable in the webserver.
";
}; };
enableUserDir = mkOption { enableUserDir = mkOption {
type = types.bool;
default = false; default = false;
description = " description = ''
Whether to enable serving <filename>~/public_html</filename> as Whether to enable serving <filename>~/public_html</filename> as
<literal>/~<replaceable>username</replaceable></literal>. <literal>/~<replaceable>username</replaceable></literal>.
"; '';
}; };
globalRedirect = mkOption { globalRedirect = mkOption {
default = ""; type = types.nullOr types.str;
default = null;
example = http://newserver.example.org/; example = http://newserver.example.org/;
description = " description = ''
If set, all requests for this host are redirected permanently to If set, all requests for this host are redirected permanently to
the given URL. the given URL.
"; '';
}; };
logFormat = mkOption { logFormat = mkOption {
type = types.str;
default = "common"; default = "common";
example = "combined"; example = "combined";
description = " description = "