···
+
{ config, lib, pkgs, ... }:
+
cfg = config.services.traefik;
+
if cfg.configFile == null then
+
pkgs.runCommand "config.toml" {
+
buildInputs = [ pkgs.remarshal ];
+
remarshal -if json -of toml \
+
< ${pkgs.writeText "config.json" (builtins.toJSON cfg.configOptions)} \
+
options.services.traefik = {
+
enable = mkEnableOption "Traefik web server";
+
configFile = mkOption {
+
example = /path/to/config.toml;
+
type = types.nullOr types.path;
+
Path to verbatim traefik.toml to use.
+
(Using that option has precedence over <literal>configOptions</literal>)
+
configOptions = mkOption {
+
defaultEntryPoints = ["http"];
+
entryPoints.http.address = ":80";
+
defaultEntrypoints = [ "http" ];
+
entryPoints.http.address = ":80";
+
routes.test_1.rule = "Host:localhost";
+
servers.server1.url = "http://localhost:8000";
+
default = "/var/lib/traefik";
+
Location for any persistent data traefik creates, ie. acme
+
default = pkgs.traefik;
+
defaultText = "pkgs.traefik";
+
description = "Traefik package to use.";
+
config = mkIf cfg.enable {
+
systemd.services.traefik = {
+
description = "Traefik web server";
+
after = [ "network-online.target" ];
+
wantedBy = [ "multi-user.target" ];
+
PermissionsStartOnly = true;
+
ExecStart = ''${cfg.package.bin}/bin/traefik --configfile=${configFile}'';
+
''${pkgs.coreutils}/bin/mkdir -p "${cfg.dataDir}"''
+
''${pkgs.coreutils}/bin/install -d -m700 --owner traefik --group traefik "${cfg.dataDir}"''
+
Restart = "on-failure";
+
StartLimitInterval = 86400;
+
AmbientCapabilities = "cap_net_bind_service";
+
CapabilityBoundingSet = "cap_net_bind_service";
+
NoNewPrivileges = true;
+
ProtectSystem = "full";
+
ReadWriteDirectories = cfg.dataDir;
+
users.extraUsers.traefik = {
+
users.extraGroups.traefik = {};