1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.podgrab;
9
10 stateDir = "/var/lib/podgrab";
11in
12{
13 options.services.podgrab = with lib; {
14 enable = mkEnableOption "Podgrab, a self-hosted podcast manager";
15
16 passwordFile = mkOption {
17 type = with types; nullOr str;
18 default = null;
19 example = "/run/secrets/password.env";
20 description = ''
21 The path to a file containing the PASSWORD environment variable
22 definition for Podgrab's authentication.
23 '';
24 };
25
26 port = mkOption {
27 type = types.port;
28 default = 8080;
29 example = 4242;
30 description = "The port on which Podgrab will listen for incoming HTTP traffic.";
31 };
32
33 dataDirectory = mkOption {
34 type = types.path;
35 default = "${stateDir}/data";
36 example = "/mnt/podcasts";
37 description = "Directory to store downloads.";
38 };
39
40 user = mkOption {
41 type = types.str;
42 default = "podgrab";
43 description = "User under which Podgrab runs, and which owns the download directory.";
44 };
45
46 group = mkOption {
47 type = types.str;
48 default = "podgrab";
49 description = "Group under which Podgrab runs, and which owns the download directory.";
50 };
51 };
52
53 config = lib.mkIf cfg.enable {
54 systemd.tmpfiles.settings."10-pyload" = {
55 ${cfg.dataDirectory}.d = { inherit (cfg) user group; };
56 };
57
58 systemd.services.podgrab = {
59 description = "Podgrab podcast manager";
60 wantedBy = [ "multi-user.target" ];
61 environment = {
62 CONFIG = "${stateDir}/config";
63 DATA = cfg.dataDirectory;
64 GIN_MODE = "release";
65 PORT = toString cfg.port;
66 };
67 serviceConfig = {
68 User = cfg.user;
69 Group = cfg.group;
70 EnvironmentFile = lib.optionals (cfg.passwordFile != null) [
71 cfg.passwordFile
72 ];
73 ExecStart = "${pkgs.podgrab}/bin/podgrab";
74 WorkingDirectory = "${pkgs.podgrab}/share";
75 StateDirectory = [ "podgrab/config" ];
76 };
77 };
78
79 users.users.podgrab = lib.mkIf (cfg.user == "podgrab") {
80 isSystemUser = true;
81 group = cfg.group;
82 };
83
84 users.groups.podgrab = lib.mkIf (cfg.group == "podgrab") { };
85 };
86
87 meta.maintainers = with lib.maintainers; [ ambroisie ];
88}