1 { config, lib, name, ... }:
3 inherit (lib) literalExpression mkOption nameValuePair types;
11 description = "Canonical hostname for the server.";
14 serverAliases = mkOption {
15 type = types.listOf types.str;
17 example = ["www.example.org" "www.example.org:8080" "example.org"];
19 Additional names of virtual hosts served by this virtual host configuration.
24 type = with types; listOf (submodule ({
28 description = "Port to listen on";
33 description = "IP to listen on. 0.0.0.0 for IPv4 only, * for all.";
38 description = "Whether to enable SSL (https) support.";
44 { ip = "195.154.1.1"; port = 443; ssl = true;}
45 { ip = "192.154.1.1"; port = 80; }
46 { ip = "*"; port = 8080; }
49 Listen addresses and ports for this virtual host.
52 This option overrides `addSSL`, `forceSSL` and `onlySSL`.
54 If you only want to set the addresses manually and not the ports, take a look at `listenAddresses`.
59 listenAddresses = mkOption {
60 type = with types; nonEmptyListOf str;
63 Listen addresses for this virtual host.
64 Compared to `listen` this only sets the addresses
65 and the ports are chosen automatically.
68 example = [ "127.0.0.1" ];
71 enableSSL = mkOption {
81 Whether to enable HTTPS in addition to plain HTTP. This will set defaults for
82 `listen` to listen on all interfaces on the respective default
91 Whether to enable HTTPS and reject plain HTTP connections. This will set
92 defaults for `listen` to listen on all interfaces on port 443.
100 Whether to add a separate nginx server block that permanently redirects (301)
101 all plain HTTP traffic to HTTPS. This will set defaults for
102 `listen` to listen on all interfaces on the respective default
103 ports (80, 443), where the non-SSL listens are used for the redirect vhosts.
107 enableACME = mkOption {
111 Whether to ask Let's Encrypt to sign a certificate for this vhost.
112 Alternately, you can use an existing certificate through {option}`useACMEHost`.
116 useACMEHost = mkOption {
117 type = types.nullOr types.str;
120 A host of an existing Let's Encrypt certificate to use.
121 This is useful if you have many subdomains and want to avoid hitting the
122 [rate limit](https://letsencrypt.org/docs/rate-limits).
123 Alternately, you can generate a certificate through {option}`enableACME`.
124 *Note that this option does not create any certificates, nor it does add subdomains to existing ones – you will need to create them manually using [](#opt-security.acme.certs).*
128 acmeRoot = mkOption {
129 type = types.nullOr types.str;
130 default = "/var/lib/acme/acme-challenge";
132 Directory for the acme challenge which is PUBLIC, don't put certs or keys in here.
133 Set to null to inherit from config.security.acme.
137 sslServerCert = mkOption {
139 example = "/var/host.cert";
140 description = "Path to server SSL certificate.";
143 sslServerKey = mkOption {
145 example = "/var/host.key";
146 description = "Path to server SSL certificate key.";
149 sslServerChain = mkOption {
150 type = types.nullOr types.path;
152 example = "/var/ca.pem";
153 description = "Path to server SSL chain file.";
160 Whether to enable HTTP 2. HTTP/2 is supported in all multi-processing modules that come with httpd. *However, if you use the prefork mpm, there will
161 be severe restrictions.* Refer to <https://httpd.apache.org/docs/2.4/howto/http2.html#mpm-config> for details.
165 adminAddr = mkOption {
166 type = types.nullOr types.str;
168 example = "admin@example.org";
169 description = "E-mail address of the server administrator.";
172 documentRoot = mkOption {
173 type = types.nullOr types.path;
175 example = "/data/webserver/docs";
177 The path of Apache's document root directory. If left undefined,
178 an empty directory in the Nix store will be used as root.
182 servedDirs = mkOption {
183 type = types.listOf types.attrs;
187 dir = "/home/eelco/Dev/nix-homepage";
191 This option provides a simple way to serve static directories.
195 servedFiles = mkOption {
196 type = types.listOf types.attrs;
199 { urlPath = "/foo/bar.png";
200 file = "/home/eelco/some-file.png";
204 This option provides a simple way to serve individual, static files.
207 This option has been deprecated and will be removed in a future
208 version of NixOS. You can achieve the same result by making use of
209 the `locations.<name>.alias` option.
214 extraConfig = mkOption {
219 Options FollowSymlinks
224 These lines go to httpd.conf verbatim. They will go after
225 directories and directory aliases defined by default.
229 enableUserDir = mkOption {
233 Whether to enable serving {file}`~/public_html` as
238 globalRedirect = mkOption {
239 type = types.nullOr types.str;
241 example = "http://newserver.example.org/";
243 If set, all requests for this host are redirected permanently to
248 logFormat = mkOption {
251 example = "combined";
253 Log format for Apache's log files. Possible values are: combined, common, referer, agent.
257 robotsEntries = mkOption {
260 example = "Disallow: /foo/";
262 Specification of pages to be ignored by web crawlers. See <http://www.robotstxt.org/> for details.
266 locations = mkOption {
267 type = with types; attrsOf (submodule (import ./location-options.nix));
269 example = literalExpression ''
272 proxyPass = "http://localhost:3000";
275 alias = "/home/eelco/some-file.png";
280 Declarative location config. See <https://httpd.apache.org/docs/2.4/mod/core.html#location> for details.
288 locations = builtins.listToAttrs (map (elem: nameValuePair elem.urlPath { alias = elem.file; }) config.servedFiles);