2016-04-05 01:30:21 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.caddy;
|
|
|
|
configFile = pkgs.writeText "Caddyfile" cfg.config;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.caddy = {
|
|
|
|
enable = mkEnableOption "Caddy web server";
|
|
|
|
|
|
|
|
config = mkOption {
|
|
|
|
description = "Verbatim Caddyfile to use";
|
|
|
|
};
|
|
|
|
|
2016-07-20 23:51:09 +00:00
|
|
|
ca = mkOption {
|
|
|
|
default = "https://acme-v01.api.letsencrypt.org/directory";
|
|
|
|
example = "https://acme-staging.api.letsencrypt.org/directory";
|
|
|
|
type = types.string;
|
|
|
|
description = "Certificate authority ACME server. The default (Let's Encrypt production server) should be fine for most people.";
|
|
|
|
};
|
|
|
|
|
2016-04-05 01:30:21 +00:00
|
|
|
email = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.string;
|
|
|
|
description = "Email address (for Let's Encrypt certificate)";
|
|
|
|
};
|
|
|
|
|
2016-07-20 23:51:09 +00:00
|
|
|
agree = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Agree to Let's Encrypt Subscriber Agreement";
|
|
|
|
};
|
|
|
|
|
2016-04-05 01:30:21 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
default = "/var/lib/caddy";
|
|
|
|
type = types.path;
|
|
|
|
description = "The data directory, for storing certificates.";
|
|
|
|
};
|
2017-01-14 03:29:26 +00:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
default = pkgs.caddy;
|
|
|
|
defaultText = "pkgs.caddy";
|
|
|
|
type = types.package;
|
|
|
|
description = "Caddy package to use.";
|
|
|
|
};
|
2016-04-05 01:30:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.caddy = {
|
|
|
|
description = "Caddy web server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2017-01-14 03:29:26 +00:00
|
|
|
ExecStart = ''${cfg.package.bin}/bin/caddy -conf=${configFile} \
|
2016-07-20 23:51:09 +00:00
|
|
|
-ca=${cfg.ca} -email=${cfg.email} ${optionalString cfg.agree "-agree"}
|
|
|
|
'';
|
|
|
|
Type = "simple";
|
|
|
|
User = "caddy";
|
|
|
|
Group = "caddy";
|
|
|
|
AmbientCapabilities = "cap_net_bind_service";
|
2017-02-11 00:44:29 +00:00
|
|
|
LimitNOFILE = 8192;
|
2016-04-05 01:30:21 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraUsers.caddy = {
|
|
|
|
group = "caddy";
|
|
|
|
uid = config.ids.uids.caddy;
|
|
|
|
home = cfg.dataDir;
|
|
|
|
createHome = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.extraGroups.caddy.gid = config.ids.uids.caddy;
|
|
|
|
};
|
|
|
|
}
|