nixos/traefik: add environmentFiles option

Changed files
+27 -3
nixos
modules
services
web-servers
tests
+23 -2
nixos/modules/services/web-servers/traefik.nix
···
''
else
cfg.staticConfigFile;
in {
options.services.traefik = {
enable = mkEnableOption (lib.mdDoc "Traefik web server");
···
type = types.package;
description = lib.mdDoc "Traefik package to use.";
};
};
config = mkIf cfg.enable {
···
startLimitIntervalSec = 86400;
startLimitBurst = 5;
serviceConfig = {
-
ExecStart =
-
"${cfg.package}/bin/traefik --configfile=${staticConfigFile}";
Type = "simple";
User = "traefik";
Group = cfg.group;
···
ProtectHome = true;
ProtectSystem = "full";
ReadWriteDirectories = cfg.dataDir;
};
};
···
''
else
cfg.staticConfigFile;
+
+
finalStaticConfigFile =
+
if cfg.environmentFiles == []
+
then staticConfigFile
+
else "/run/traefik/config.toml";
in {
options.services.traefik = {
enable = mkEnableOption (lib.mdDoc "Traefik web server");
···
type = types.package;
description = lib.mdDoc "Traefik package to use.";
};
+
+
environmentFiles = mkOption {
+
default = [];
+
type = types.listOf types.path;
+
example = [ "/run/secrets/traefik.env" ];
+
description = lib.mdDoc ''
+
Files to load as environment file. Environment variables from this file
+
will be substituted into the static configuration file using envsubst.
+
'';
+
};
};
config = mkIf cfg.enable {
···
startLimitIntervalSec = 86400;
startLimitBurst = 5;
serviceConfig = {
+
EnvironmentFile = cfg.environmentFiles;
+
ExecStartPre = lib.optional (cfg.environmentFiles != [])
+
(pkgs.writeShellScript "pre-start" ''
+
umask 077
+
${pkgs.envsubst}/bin/envsubst -i "${staticConfigFile}" > "${finalStaticConfigFile}"
+
'');
+
ExecStart = "${cfg.package}/bin/traefik --configfile=${finalStaticConfigFile}";
Type = "simple";
User = "traefik";
Group = cfg.group;
···
ProtectHome = true;
ProtectSystem = "full";
ReadWriteDirectories = cfg.dataDir;
+
RuntimeDirectory = "traefik";
};
};
+4 -1
nixos/tests/traefik.nix
···
sendAnonymousUsage = false;
};
-
entryPoints.web.address = ":80";
providers.docker.exposedByDefault = false;
};
};
systemd.services.simplehttp = {
···
sendAnonymousUsage = false;
};
+
entryPoints.web.address = ":\${HTTP_PORT}";
providers.docker.exposedByDefault = false;
};
+
environmentFiles = [(pkgs.writeText "traefik.env" ''
+
HTTP_PORT=80
+
'')];
};
systemd.services.simplehttp = {