git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #29865 from hamhut1066/traefik-module

nixos/traefik create service

commitb8288f137f9d12e757bde925933691fd7a845e22 authorJörg Thalheim <Mic92@users.noreply.github.com> dateWed 4 Oct 2017, 11:53 (9 years ago) parent7c2b6173468c9e
2 files changed+115
nixos/modules/module-list.nix+1 nixos/modules/services/web-servers/traefik.nix+114
nixos/modules/module-list.nix+1
@@ -622,6 +622,7 @@
622622 ./services/web-servers/phpfpm/default.nix
623623 ./services/web-servers/shellinabox.nix
624624 ./services/web-servers/tomcat.nix
625+ ./services/web-servers/traefik.nix
625626 ./services/web-servers/uwsgi.nix
626627 ./services/web-servers/varnish/default.nix
627628 ./services/web-servers/winstone.nix
nixos/modules/services/web-servers/traefik.nixnew file+114
@@ -0,0 +1,114 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
6+ cfg = config.services.traefik;
7+ configFile =
8+ if cfg.configFile == null then
9+ pkgs.runCommand "config.toml" {
10+ buildInputs = [ pkgs.remarshal ];
11+ } ''
12+ remarshal -if json -of toml \
13+ < ${pkgs.writeText "config.json" (builtins.toJSON cfg.configOptions)} \
14+ > $out
15+ ''
16+ else cfg.configFile;
17+
18+in {
19+ options.services.traefik = {
20+ enable = mkEnableOption "Traefik web server";
21+
22+ configFile = mkOption {
23+ default = null;
24+ example = /path/to/config.toml;
25+ type = types.nullOr types.path;
26+ description = ''
27+ Path to verbatim traefik.toml to use.
28+ (Using that option has precedence over <literal>configOptions</literal>)
29+ '';
30+ };
31+
32+ configOptions = mkOption {
33+ description = ''
34+ Config for Traefik.
35+ '';
36+ type = types.attrs;
37+ default = {
38+ defaultEntryPoints = ["http"];
39+ entryPoints.http.address = ":80";
40+ };
41+ example = {
42+ defaultEntrypoints = [ "http" ];
43+ web.address = ":8080";
44+ entryPoints.http.address = ":80";
45+
46+ file = {};
47+ frontends = {
48+ frontend1 = {
49+ backend = "backend1";
50+ routes.test_1.rule = "Host:localhost";
51+ };
52+ };
53+ backends.backend1 = {
54+ servers.server1.url = "http://localhost:8000";
55+ };
56+ };
57+ };
58+
59+ dataDir = mkOption {
60+ default = "/var/lib/traefik";
61+ type = types.path;
62+ description = ''
63+ Location for any persistent data traefik creates, ie. acme
64+ '';
65+ };
66+
67+ package = mkOption {
68+ default = pkgs.traefik;
69+ defaultText = "pkgs.traefik";
70+ type = types.package;
71+ description = "Traefik package to use.";
72+ };
73+ };
74+
75+ config = mkIf cfg.enable {
76+ systemd.services.traefik = {
77+ description = "Traefik web server";
78+ after = [ "network-online.target" ];
79+ wantedBy = [ "multi-user.target" ];
80+ serviceConfig = {
81+ PermissionsStartOnly = true;
82+ ExecStart = ''${cfg.package.bin}/bin/traefik --configfile=${configFile}'';
83+ ExecStartPre = [
84+ ''${pkgs.coreutils}/bin/mkdir -p "${cfg.dataDir}"''
85+ ''${pkgs.coreutils}/bin/install -d -m700 --owner traefik --group traefik "${cfg.dataDir}"''
86+ ];
87+ Type = "simple";
88+ User = "traefik";
89+ Group = "traefik";
90+ Restart = "on-failure";
91+ StartLimitInterval = 86400;
92+ StartLimitBurst = 5;
93+ AmbientCapabilities = "cap_net_bind_service";
94+ CapabilityBoundingSet = "cap_net_bind_service";
95+ NoNewPrivileges = true;
96+ LimitNPROC = 64;
97+ LimitNOFILE = 1048576;
98+ PrivateTmp = true;
99+ PrivateDevices = true;
100+ ProtectHome = true;
101+ ProtectSystem = "full";
102+ ReadWriteDirectories = cfg.dataDir;
103+ };
104+ };
105+
106+ users.extraUsers.traefik = {
107+ group = "traefik";
108+ home = cfg.dataDir;
109+ createHome = true;
110+ };
111+
112+ users.extraGroups.traefik = {};
113+ };
114+}