diff --git a/modules/module-list.nix b/modules/module-list.nix
index dc20fa605c4b..861039d73917 100644
--- a/modules/module-list.nix
+++ b/modules/module-list.nix
@@ -94,8 +94,6 @@
./services/ttys/gpm.nix
./services/ttys/mingetty.nix
./services/web-servers/apache-httpd/default.nix
- ./services/web-servers/apache-httpd/per-server-options.nix
- ./services/web-servers/apache-httpd/services.nix
./services/web-servers/jboss.nix
./services/web-servers/tomcat.nix
./services/x11/desktop-managers/default.nix
diff --git a/modules/services/web-servers/apache-httpd/default.nix b/modules/services/web-servers/apache-httpd/default.nix
index 7e3067510d3f..55902f9e5e0e 100644
--- a/modules/services/web-servers/apache-httpd/default.nix
+++ b/modules/services/web-servers/apache-httpd/default.nix
@@ -10,7 +10,7 @@ let
httpd = pkgs.apacheHttpd;
- getPort = cfg: cfg.port;
+ getPort = cfg: if cfg.port != 0 then cfg.port else if cfg.enableSSL then 443 else 80;
extraModules = attrByPath ["extraModules"] [] mainCfg;
extraForeignModules = filter builtins.isAttrs extraModules;
@@ -33,22 +33,45 @@ let
fullConfig = config; # machine config
};
- vhosts = mainCfg.virtualHosts;
+
+ vhostOptions = import ./per-server-options.nix {
+ inherit mkOption;
+ forMainServer = false;
+ };
+
+ vhosts = let
+ makeVirtualHost = cfgIn:
+ let
+ # Fill in defaults for missing options.
+ cfg = addDefaultOptionValues vhostOptions cfgIn;
+ in cfg;
+ in map makeVirtualHost mainCfg.virtualHosts;
+
allHosts = [mainCfg] ++ vhosts;
- # !!! This should be replaced by sub-modules to allow non-intrusive
- # extensions of NixOS.
+
callSubservices = serverInfo: defs:
let f = svc:
- rec {
- config =
- if res ? options then
- addDefaultOptionValues res.options svc.configuration
- else
- svc.configuration;
- res = svc // svc.function {inherit config pkgs serverInfo servicesPath;};
- }.res;
+ let
+ svcFunction =
+ if svc ? function then svc.function
+ else import "${./.}/${if svc ? serviceType then svc.serviceType else svc.serviceName}.nix";
+ config = addDefaultOptionValues res.options
+ (if svc ? config then svc.config else svc);
+ defaults = {
+ extraConfig = "";
+ extraModules = [];
+ extraModulesPre = [];
+ extraPath = [];
+ extraServerPath = [];
+ globalEnvVars = [];
+ robotsEntries = "";
+ startupScript = "";
+ options = {};
+ };
+ res = defaults // svcFunction {inherit config pkgs serverInfo servicesPath;};
+ in res;
in map f defs;
@@ -354,6 +377,13 @@ in
";
};
+ extraConfig = mkOption {
+ default = "";
+ description = "
+ These configuration lines will be passed verbatim to the apache config
+ ";
+ };
+
extraModules = mkOption {
default = [];
example = [ "proxy_connect" { name = "php5"; path = "${pkgs.php}/modules/libphp5.so"; } ];
@@ -416,7 +446,109 @@ in
";
};
- };
+ virtualHosts = mkOption {
+ default = [];
+ example = [
+ { hostName = "foo";
+ documentRoot = "/data/webroot-foo";
+ }
+ { hostName = "bar";
+ documentRoot = "/data/webroot-bar";
+ }
+ ];
+ description = ''
+ Specification of the virtual hosts served by Apache. Each
+ element should be an attribute set specifying the
+ configuration of the virtual host. The available options
+ are the non-global options permissible for the main host.
+ '';
+ };
+
+
+ subservices = {
+
+ # !!! remove this
+ subversion = {
+
+ enable = mkOption {
+ default = false;
+ description = "
+ Whether to enable the Subversion subservice in the webserver.
+ ";
+ };
+
+ notificationSender = mkOption {
+ default = "svn-server@example.org";
+ example = "svn-server@example.org";
+ description = "
+ The email address used in the Sender field of commit
+ notification messages sent by the Subversion subservice.
+ ";
+ };
+
+ userCreationDomain = mkOption {
+ default = "example.org";
+ example = "example.org";
+ description = "
+ The domain from which user creation is allowed. A client can
+ only create a new user account if its IP address resolves to
+ this domain.
+ ";
+ };
+
+ autoVersioning = mkOption {
+ default = false;
+ description = "
+ Whether you want the Subversion subservice to support
+ auto-versioning, which enables Subversion repositories to be
+ mounted as read/writable file systems on operating systems that
+ support WebDAV.
+ ";
+ };
+
+ dataDir = mkOption {
+ default = "/no/such/path/exists";
+ description = "
+ Place to put SVN repository.
+ ";
+ };
+
+ organization = {
+
+ name = mkOption {
+ default = null;
+ description = "
+ Name of the organization hosting the Subversion service.
+ ";
+ };
+
+ url = mkOption {
+ default = null;
+ description = "
+ URL of the website of the organization hosting the Subversion service.
+ ";
+ };
+
+ logo = mkOption {
+ default = null;
+ description = "
+ Logo the organization hosting the Subversion service.
+ ";
+ };
+
+ };
+
+ };
+
+ };
+
+ }
+
+ # Include the options shared between the main server and virtual hosts.
+ // (import ./per-server-options.nix {
+ inherit mkOption;
+ forMainServer = true;
+ });
};
diff --git a/modules/services/web-servers/apache-httpd/per-server-options.nix b/modules/services/web-servers/apache-httpd/per-server-options.nix
index 6e98b8685fa1..8a2ee0e849a8 100644
--- a/modules/services/web-servers/apache-httpd/per-server-options.nix
+++ b/modules/services/web-servers/apache-httpd/per-server-options.nix
@@ -3,180 +3,136 @@
# has additional options that affect the web server as a whole, like
# the user/group to run under.)
-{options, config, pkgs, ...}:
-
-let
- inherit (pkgs.lib) mkOption addDefaultOptionValues types;
-
- mainServerArgs = {
- config = config.services.httpd;
- options = options.services.httpd;
- };
-
-
- perServerOptions = {forMainServer}: {config, ...}: {
-
- hostName = mkOption {
- default = "localhost";
- description = "
- Canonical hostname for the server.
- ";
- };
-
- serverAliases = mkOption {
- default = [];
- example = ["www.example.org" "www.example.org:8080" "example.org"];
- description = "
- Additional names of virtual hosts served by this virtual host configuration.
- ";
- };
-
- port = mkOption {
- default = if config.enableSSL then 443 else 80;
- type = with types; uniq int;
- description = "
- Port for the server. The default port depends on the
- option of this server. (80 for http and
- 443 for https).
- ";
- };
-
- enableSSL = mkOption {
- default = false;
- description = "
- Whether to enable SSL (https) support.
- ";
- };
-
- # Note: sslServerCert and sslServerKey can be left empty, but this
- # only makes sense for virtual hosts (they will inherit from the
- # main server).
-
- sslServerCert = mkOption {
- default = "";
- example = "/var/host.cert";
- description = "
- Path to server SSL certificate.
- ";
- };
-
- sslServerKey = mkOption {
- default = "";
- example = "/var/host.key";
- description = "
- Path to server SSL certificate key.
- ";
- };
-
- adminAddr = mkOption ({
- example = "admin@example.org";
- description = "
- E-mail address of the server administrator.
- ";
- } // (if forMainServer then {} else {default = "";}));
-
- documentRoot = mkOption {
- default = null;
- example = "/data/webserver/docs";
- description = "
- The path of Apache's document root directory. If left undefined,
- an empty directory in the Nix store will be used as root.
- ";
- };
-
- servedDirs = mkOption {
- default = [];
- example = [
- { urlPath = "/nix";
- dir = "/home/eelco/Dev/nix-homepage";
- }
- ];
- description = "
- This option provides a simple way to serve static directories.
- ";
- };
-
- servedFiles = mkOption {
- default = [];
- example = [
- { urlPath = "/foo/bar.png";
- dir = "/home/eelco/some-file.png";
- }
- ];
- description = "
- This option provides a simple way to serve individual, static files.
- ";
- };
-
- extraConfig = mkOption {
- default = "";
- example = ''
-
- Options FollowSymlinks
- AllowOverride All
-
- '';
- description = "
- These lines go to httpd.conf verbatim. They will go after
- directories and directory aliases defined by default.
- ";
- };
-
- enableUserDir = mkOption {
- default = false;
- description = "
- Whether to enable serving ~/public_html as
- /~username.
- ";
- };
-
- globalRedirect = mkOption {
- default = "";
- example = http://newserver.example.org/;
- description = "
- If set, all requests for this host are redirected permanently to
- the given URL.
- ";
- };
-
- };
-
-
- vhostOptions = perServerOptions {
- forMainServer = false;
- };
-
-in
+{forMainServer, mkOption}:
{
- options = {
- services.httpd = {
- virtualHosts = mkOption {
- default = [];
- example = [
- { hostName = "foo";
- documentRoot = "/data/webroot-foo";
- }
- { hostName = "bar";
- documentRoot = "/data/webroot-bar";
- }
- ];
- type = with types; listOf optionSet;
- description = ''
- Specification of the virtual hosts served by Apache. Each
- element should be an attribute set specifying the
- configuration of the virtual host. The available options
- are the non-global options permissible for the main host.
- '';
-
- options = [
- vhostOptions
- ];
- };
-
- }
- // perServerOptions {forMainServer = true;} mainServerArgs
- ;
+ hostName = mkOption {
+ default = "localhost";
+ description = "
+ Canonical hostname for the server.
+ ";
};
+
+ serverAliases = mkOption {
+ default = [];
+ example = ["www.example.org" "www.example.org:8080" "example.org"];
+ description = "
+ Additional names of virtual hosts served by this virtual host configuration.
+ ";
+ };
+
+ port = mkOption {
+ default = 0;
+ description = "
+ Port for the server. 0 means use the default port: 80 for http
+ and 443 for https (i.e. when enableSSL is set).
+ ";
+ };
+
+ enableSSL = mkOption {
+ default = false;
+ description = "
+ Whether to enable SSL (https) support.
+ ";
+ };
+
+ # Note: sslServerCert and sslServerKey can be left empty, but this
+ # only makes sense for virtual hosts (they will inherit from the
+ # main server).
+
+ sslServerCert = mkOption {
+ default = "";
+ example = "/var/host.cert";
+ description = "
+ Path to server SSL certificate.
+ ";
+ };
+
+ sslServerKey = mkOption {
+ default = "";
+ example = "/var/host.key";
+ description = "
+ Path to server SSL certificate key.
+ ";
+ };
+
+ adminAddr = mkOption ({
+ example = "admin@example.org";
+ description = "
+ E-mail address of the server administrator.
+ ";
+ } // (if forMainServer then {} else {default = "";}));
+
+ documentRoot = mkOption {
+ default = null;
+ example = "/data/webserver/docs";
+ description = "
+ The path of Apache's document root directory. If left undefined,
+ an empty directory in the Nix store will be used as root.
+ ";
+ };
+
+ servedDirs = mkOption {
+ default = [];
+ example = [
+ { urlPath = "/nix";
+ dir = "/home/eelco/Dev/nix-homepage";
+ }
+ ];
+ description = "
+ This option provides a simple way to serve static directories.
+ ";
+ };
+
+ servedFiles = mkOption {
+ default = [];
+ example = [
+ { urlPath = "/foo/bar.png";
+ dir = "/home/eelco/some-file.png";
+ }
+ ];
+ description = "
+ This option provides a simple way to serve individual, static files.
+ ";
+ };
+
+ extraConfig = mkOption {
+ default = "";
+ example = ''
+
+ Options FollowSymlinks
+ AllowOverride All
+
+ '';
+ description = "
+ These lines go to httpd.conf verbatim. They will go after
+ directories and directory aliases defined by default.
+ ";
+ };
+
+ extraSubservices = mkOption {
+ default = [];
+ description = "
+ Extra subservices to enable in the webserver.
+ ";
+ };
+
+ enableUserDir = mkOption {
+ default = false;
+ description = "
+ Whether to enable serving ~/public_html as
+ /~username.
+ ";
+ };
+
+ globalRedirect = mkOption {
+ default = "";
+ example = http://newserver.example.org/;
+ description = "
+ If set, all requests for this host are redirected permanently to
+ the given URL.
+ ";
+ };
+
}
diff --git a/modules/services/web-servers/apache-httpd/services.nix b/modules/services/web-servers/apache-httpd/services.nix
deleted file mode 100644
index a8b69be636ea..000000000000
--- a/modules/services/web-servers/apache-httpd/services.nix
+++ /dev/null
@@ -1,129 +0,0 @@
-{options, config, pkgs, ...}:
-
-let
- inherit (pkgs.lib) mkOption addDefaultOptionValues types;
-
- mainServerArgs = {
- config = config.services.httpd;
- options = options.services.httpd;
- };
-
- subServiceOptions = {options, config, ...}: {
- options = {
-
- extraConfig = mkOption {
- default = "";
- description = "Not documented yet.";
- };
-
- extraModules = mkOption {
- default = [];
- description = "Not documented yet.";
- };
-
- extraModulesPre = mkOption {
- default = [];
- description = "Not documented yet.";
- };
-
- extraPath = mkOption {
- default = [];
- description = "Not documented yet.";
- };
-
- extraServerPath = mkOption {
- default = [];
- description = "Not documented yet.";
- };
-
- globalEnvVars = mkOption {
- default = [];
- description = "Not documented yet.";
- };
-
- robotsEntries = mkOption {
- default = "";
- description = "Not documented yet.";
- };
-
- startupScript = mkOption {
- default = "";
- description = "Not documented yet.";
- };
-
-
- serviceType = mkOption {
- description = "Obsolete name of .";
- # serviceType is the old name of serviceName.
- apply = x: config.serviceName;
- };
-
- serviceName = mkOption {
- example = "trac";
- description = "
- (Deprecated)
-
- Identify a service by the name of the file containing it. The
- service expression is contained inside
- ./modules/services/web-servers/apache-httpd
- directory.
-
- Due to lack of documentation, this option will be replaced by
- enable flags.
- ";
-
- # serviceName is the new name of serviceType.
- extraConfigs = map (def: def.value) options.serviceType.definitions;
- };
-
- function = mkOption {
- default = null;
- description = "
- (Deprecated) Add a function which configure the current sub-service.
- ";
- apply = f:
- if isNull f then
- import "${./.}/${config.serviceName}.nix"
- else
- f;
- };
-
- configuration = mkOption {
- default = {};
- description = "
- (Deprecated) Define option values of the current sub-service.
- ";
- };
-
- };
- };
-
-
- perServerOptions = {config, ...}: {
-
- extraSubservices = mkOption {
- default = [];
- type = with types; listOf optionSet;
- description = "
- Extra subservices to enable in the webserver.
- ";
- options = [ subServiceOptions ];
- };
-
- };
-
-in
-
-{
- options = {
- services.httpd = {
-
- virtualHosts = mkOption {
- options = [ perServerOptions ];
- };
-
- }
- // perServerOptions mainServerArgs
- ;
- };
-}
diff --git a/tests/subversion.nix b/tests/subversion.nix
index 5fed5ba77c42..82ada4576ebd 100644
--- a/tests/subversion.nix
+++ b/tests/subversion.nix
@@ -56,11 +56,9 @@ rec {
services.httpd.adminAddr = "e.dolstra@tudelft.nl";
services.httpd.extraSubservices =
[ { serviceType = "subversion";
- configuration = {
- urlPrefix = "";
- dataDir = "/data/subversion";
- userCreationDomain = "192.168.0.0/16";
- };
+ urlPrefix = "";
+ dataDir = "/data/subversion";
+ userCreationDomain = "192.168.0.0/16";
}
];
nixpkgs.config.packageOverrides = overrides;