1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7
8let
9 cfg = config.services.whisparr;
10 servarr = import ./settings-options.nix { inherit lib pkgs; };
11in
12{
13 options = {
14 services.whisparr = {
15 enable = lib.mkEnableOption "Whisparr";
16
17 package = lib.mkPackageOption pkgs "whisparr" { };
18
19 dataDir = lib.mkOption {
20 type = lib.types.path;
21 default = "/var/lib/whisparr/.config/Whisparr";
22 description = "The directory where Whisparr stores its data files.";
23 };
24
25 openFirewall = lib.mkOption {
26 type = lib.types.bool;
27 default = false;
28 description = "Open ports in the firewall for the Whisparr web interface.";
29 };
30
31 settings = servarr.mkServarrSettingsOptions "whisparr" 6969;
32
33 environmentFiles = servarr.mkServarrEnvironmentFiles "whisparr";
34
35 user = lib.mkOption {
36 type = lib.types.str;
37 default = "whisparr";
38 description = "User account under which Whisparr runs.";
39 };
40
41 group = lib.mkOption {
42 type = lib.types.str;
43 default = "whisparr";
44 description = "Group under which Whisparr runs.";
45 };
46 };
47 };
48
49 config = lib.mkIf cfg.enable {
50 systemd.tmpfiles.rules = [ "d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -" ];
51
52 systemd.services.whisparr = {
53 description = "Whisparr";
54 after = [ "network.target" ];
55 wantedBy = [ "multi-user.target" ];
56 environment = servarr.mkServarrSettingsEnvVars "WHISPARR" cfg.settings;
57
58 serviceConfig = {
59 Type = "simple";
60 User = cfg.user;
61 Group = cfg.group;
62 EnvironmentFile = cfg.environmentFiles;
63 ExecStart = "${lib.getExe cfg.package} -nobrowser -data='${cfg.dataDir}'";
64 Restart = "on-failure";
65 };
66 };
67
68 networking.firewall = lib.mkIf cfg.openFirewall {
69 allowedTCPPorts = [ cfg.settings.server.port ];
70 };
71
72 users.users = lib.mkIf (cfg.user == "whisparr") {
73 whisparr = {
74 group = cfg.group;
75 home = cfg.dataDir;
76 isSystemUser = true;
77 };
78 };
79
80 users.groups.whisparr = lib.mkIf (cfg.group == "whisparr") { };
81 };
82}