2013-03-03 14:24:44 +00:00
|
|
|
# NixOS module for lighttpd web server
|
|
|
|
|
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.lighttpd;
|
2013-05-06 11:14:01 +01:00
|
|
|
|
2013-06-14 20:01:12 +01:00
|
|
|
needModRedirect = cfg.gitweb.enable;
|
|
|
|
needModAlias = cfg.cgit.enable or cfg.gitweb.enable;
|
|
|
|
needModSetenv = cfg.cgit.enable or cfg.gitweb.enable;
|
|
|
|
needModCgi = cfg.cgit.enable or cfg.gitweb.enable;
|
|
|
|
needModStatus = cfg.mod_status;
|
|
|
|
needModUserdir = cfg.mod_userdir;
|
|
|
|
|
2013-05-06 11:14:01 +01:00
|
|
|
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"
|
|
|
|
|
2013-06-14 20:01:12 +01:00
|
|
|
# As for why all modules are loaded here, instead of having small
|
|
|
|
# server.modules += () entries in each sub-service extraConfig snippet,
|
|
|
|
# read this:
|
|
|
|
#
|
|
|
|
# http://redmine.lighttpd.net/projects/1/wiki/Server_modulesDetails
|
|
|
|
# http://redmine.lighttpd.net/issues/2337
|
|
|
|
#
|
|
|
|
# Basically, lighttpd doesn't want to load (or even silently ignore) a
|
|
|
|
# module for a second time, and there is no way to check if a module has
|
|
|
|
# been loaded already. So if two services were to put the same module in
|
|
|
|
# server.modules += (), that would break the lighttpd configuration.
|
|
|
|
server.modules = (
|
|
|
|
${optionalString needModRedirect ''"mod_redirect",''}
|
|
|
|
${optionalString needModAlias ''"mod_alias",''}
|
|
|
|
${optionalString needModSetenv ''"mod_setenv",''}
|
|
|
|
${optionalString needModCgi ''"mod_cgi",''}
|
|
|
|
${optionalString needModStatus ''"mod_status",''}
|
|
|
|
${optionalString needModUserdir ''"mod_userdir",''}
|
|
|
|
"mod_accesslog"
|
|
|
|
)
|
|
|
|
|
2013-05-06 11:14:01 +01:00
|
|
|
# Logging (logs end up in systemd journal)
|
|
|
|
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" )
|
|
|
|
|
2013-05-06 11:28:30 +01:00
|
|
|
${if cfg.mod_userdir then ''
|
|
|
|
userdir.path = "public_html"
|
|
|
|
'' else ""}
|
|
|
|
|
2013-05-06 11:31:17 +01:00
|
|
|
${if cfg.mod_status then ''
|
|
|
|
status.status-url = "/server-status"
|
|
|
|
status.statistics-url = "/server-statistics"
|
|
|
|
status.config-url = "/server-config"
|
|
|
|
'' else ""}
|
|
|
|
|
2013-05-06 11:14:01 +01:00
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
2013-03-03 14:24:44 +00:00
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.lighttpd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.uniq types.bool;
|
|
|
|
description = ''
|
2013-05-06 11:14:01 +01:00
|
|
|
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";
|
2013-10-30 10:02:04 +00:00
|
|
|
type = types.str;
|
2013-05-06 11:14:01 +01:00
|
|
|
description = ''
|
|
|
|
Document-root of the web server. Must be readable by the "lighttpd" user.
|
2013-03-03 14:24:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-05-06 11:28:30 +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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2013-05-06 11:31:17 +01:00
|
|
|
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 14:24:44 +00:00
|
|
|
configText = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.string;
|
2013-05-06 11:14:01 +01:00
|
|
|
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 14:24:44 +00:00
|
|
|
'';
|
2013-05-06 11:14:01 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.string;
|
2013-03-03 14:24:44 +00:00
|
|
|
description = ''
|
2013-05-06 11:14:01 +01:00
|
|
|
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 14:24:44 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.lighttpd = {
|
|
|
|
description = "Lighttpd Web Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2013-05-31 22:53:13 +01:00
|
|
|
preStart = ''
|
|
|
|
${if cfg.cgit.enable then ''
|
|
|
|
mkdir -p /var/cache/cgit
|
|
|
|
chown lighttpd:lighttpd /var/cache/cgit
|
|
|
|
'' else ""}
|
|
|
|
'';
|
2013-03-31 15:10:06 +01:00
|
|
|
serviceConfig.ExecStart = "${pkgs.lighttpd}/sbin/lighttpd -D -f ${configFile}";
|
2013-03-03 14:24:44 +00:00
|
|
|
# SIGINT => graceful shutdown
|
|
|
|
serviceConfig.KillSignal = "SIGINT";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers.lighttpd = {
|
|
|
|
group = "lighttpd";
|
|
|
|
description = "lighttpd web server privilege separation user";
|
2013-08-23 10:33:24 +01:00
|
|
|
uid = config.ids.uids.lighttpd;
|
2013-03-03 14:24:44 +00:00
|
|
|
};
|
|
|
|
|
2013-08-23 10:33:24 +01:00
|
|
|
users.extraGroups.lighttpd.gid = config.ids.gids.lighttpd;
|
2013-03-03 14:24:44 +00:00
|
|
|
};
|
|
|
|
}
|