1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 cfg = config.services.tautulli;
9in
10{
11 imports = [
12 (lib.mkRenamedOptionModule [ "services" "plexpy" ] [ "services" "tautulli" ])
13 ];
14
15 options = {
16 services.tautulli = {
17 enable = lib.mkEnableOption "Tautulli Plex Monitor";
18
19 dataDir = lib.mkOption {
20 type = lib.types.str;
21 default = "/var/lib/plexpy";
22 description = "The directory where Tautulli stores its data files.";
23 };
24
25 configFile = lib.mkOption {
26 type = lib.types.str;
27 default = "/var/lib/plexpy/config.ini";
28 description = "The location of Tautulli's config file.";
29 };
30
31 port = lib.mkOption {
32 type = lib.types.port;
33 default = 8181;
34 description = "TCP port where Tautulli listens.";
35 };
36
37 openFirewall = lib.mkOption {
38 type = lib.types.bool;
39 default = false;
40 description = "Open ports in the firewall for Tautulli.";
41 };
42
43 user = lib.mkOption {
44 type = lib.types.str;
45 default = "plexpy";
46 description = "User account under which Tautulli runs.";
47 };
48
49 group = lib.mkOption {
50 type = lib.types.str;
51 default = "nogroup";
52 description = "Group under which Tautulli runs.";
53 };
54
55 package = lib.mkPackageOption pkgs "tautulli" { };
56 };
57 };
58
59 config = lib.mkIf cfg.enable {
60 systemd.tmpfiles.rules = [
61 "d '${cfg.dataDir}' - ${cfg.user} ${cfg.group} - -"
62 ];
63
64 systemd.services.tautulli = {
65 description = "Tautulli Plex Monitor";
66 after = [ "network.target" ];
67 wantedBy = [ "multi-user.target" ];
68 serviceConfig = {
69 Type = "simple";
70 User = cfg.user;
71 Group = cfg.group;
72 GuessMainPID = "false";
73 ExecStart = "${cfg.package}/bin/tautulli --datadir ${cfg.dataDir} --config ${cfg.configFile} --port ${toString cfg.port} --pidfile ${cfg.dataDir}/tautulli.pid --nolaunch";
74 Restart = "on-failure";
75 };
76 };
77
78 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.port ];
79
80 users.users = lib.mkIf (cfg.user == "plexpy") {
81 plexpy = {
82 group = cfg.group;
83 uid = config.ids.uids.plexpy;
84 };
85 };
86 };
87}