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