nixpkgs/modules/services/web-servers/lighttpd/default.nix

147 lines
3.7 KiB
Nix
Raw Normal View History

2013-03-03 15:24:44 +01:00
# NixOS module for lighttpd web server
{ config, pkgs, ... }:
with pkgs.lib;
let
cfg = config.services.lighttpd;
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" )
${if cfg.mod_userdir then ''
server.modules += ("mod_userdir")
userdir.path = "public_html"
'' else ""}
${if cfg.mod_status then ''
server.modules += ("mod_status")
status.status-url = "/server-status"
status.statistics-url = "/server-statistics"
status.config-url = "/server-config"
'' else ""}
${cfg.extraConfig}
'';
2013-03-03 15:24:44 +01:00
in
{
options = {
services.lighttpd = {
enable = mkOption {
default = false;
type = types.uniq types.bool;
description = ''
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.
2013-03-03 15:24:44 +01:00
'';
};
mod_userdir = mkOption {
default = false;
type = types.uniq types.bool;
description = ''
If true, requests in the form /~user/page.html are rewritten to take
the file public_html/page.html from the home directory of the user.
'';
};
mod_status = mkOption {
default = false;
type = types.uniq types.bool;
description = ''
Show server status overview at /server-status, statistics at
/server-statistics and list of loaded modules at /server-config.
'';
};
2013-03-03 15:24:44 +01:00
configText = mkOption {
default = "";
type = types.string;
example = ''...verbatim config file contents...'';
description = ''
Overridable config file contents to use for lighttpd. By default, use
the contents automatically generated by NixOS.
2013-03-03 15:24:44 +01:00
'';
};
extraConfig = mkOption {
default = "";
type = types.string;
2013-03-03 15:24:44 +01:00
description = ''
These configuration lines will be appended to the generated lighttpd
config file. Note that this mechanism does not work when the manual
<option>configText</option> option is used.
2013-03-03 15:24:44 +01:00
'';
};
};
};
config = mkIf cfg.enable {
systemd.services.lighttpd = {
description = "Lighttpd Web Server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStart = "${pkgs.lighttpd}/sbin/lighttpd -D -f ${configFile}";
2013-03-03 15:24:44 +01:00
# SIGINT => graceful shutdown
serviceConfig.KillSignal = "SIGINT";
};
users.extraUsers.lighttpd = {
group = "lighttpd";
description = "lighttpd web server privilege separation user";
};
users.extraGroups.lighttpd = {};
};
}