diff --git a/modules/services/web-servers/lighttpd/default.nix b/modules/services/web-servers/lighttpd/default.nix index 1931fa65e51..326ed76bd40 100644 --- a/modules/services/web-servers/lighttpd/default.nix +++ b/modules/services/web-servers/lighttpd/default.nix @@ -7,9 +7,37 @@ with pkgs.lib; let cfg = config.services.lighttpd; - configFile = pkgs.writeText "lighttpd.conf" '' - ${cfg.configText} - ''; + + configFile = if cfg.configText != "" then + pkgs.writeText "lighttpd.conf" '' + ${cfg.configText} + '' + else + pkgs.writeText "lighttpd.conf" '' + server.document-root = "${cfg.document-root}" + server.port = ${toString cfg.port} + server.username = "lighttpd" + server.groupname = "lighttpd" + + # Logging (logs end up in systemd journal) + server.modules += ("mod_accesslog") + accesslog.use-syslog = "enable" + server.errorlog-use-syslog = "enable" + + mimetype.assign = ( + ".html" => "text/html", + ".htm" => "text/html", + ".txt" => "text/plain", + ".jpg" => "image/jpeg", + ".png" => "image/png", + ".css" => "text/css" + ) + + static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) + index-file.names = ( "index.html" ) + + ${cfg.extraConfig} + ''; in @@ -23,37 +51,43 @@ in default = false; type = types.uniq types.bool; description = '' - Enable the lighttpd web server. You must configure it with - services.lighttpd.configText. + Enable the lighttpd web server. + ''; + }; + + port = mkOption { + default = 80; + type = types.uniq types.int; + description = '' + TCP port number for lighttpd to bind to. + ''; + }; + + document-root = mkOption { + default = "/srv/www"; + type = types.uniq types.string; + description = '' + Document-root of the web server. Must be readable by the "lighttpd" user. ''; }; configText = mkOption { default = ""; type = types.string; - example = '' - server.document-root = "/srv/www/" - server.port = 80 - server.username = "lighttpd" - server.groupname = "lighttpd" - - mimetype.assign = ( - ".html" => "text/html", - ".txt" => "text/plain", - ".jpg" => "image/jpeg", - ".png" => "image/png" - ) - - static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" ) - index-file.names = ( "index.html" ) - ''; + example = ''...verbatim config file contents...''; description = '' - Contents of lighttpd configuration file. The user and group - "lighttpd" is available for privilege separation. See configuration - tutorial at - http://redmine.lighttpd.net/projects/lighttpd/wiki/TutorialConfiguration - or full documentation at - http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs + Overridable config file contents to use for lighttpd. By default, use + the contents automatically generated by NixOS. + ''; + }; + + extraConfig = mkOption { + default = ""; + type = types.string; + description = '' + These configuration lines will be appended to the generated lighttpd + config file. Note that this mechanism does not work when the manual + option is used. ''; };