about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/misc/podgrab.nix
blob: 50dc70e2bd767d9d1ae34b1e68a8ea062a4fb48f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
{ config, lib, pkgs, ... }:
let
  cfg = config.services.podgrab;

  stateDir = "/var/lib/podgrab";
in
{
  options.services.podgrab = with lib; {
    enable = mkEnableOption "Podgrab, a self-hosted podcast manager";

    passwordFile = mkOption {
      type = with types; nullOr str;
      default = null;
      example = "/run/secrets/password.env";
      description = ''
        The path to a file containing the PASSWORD environment variable
        definition for Podgrab's authentication.
      '';
    };

    port = mkOption {
      type = types.port;
      default = 8080;
      example = 4242;
      description = "The port on which Podgrab will listen for incoming HTTP traffic.";
    };

    dataDirectory = mkOption {
      type = types.path;
      default = "${stateDir}/data";
      example = "/mnt/podcasts";
      description = "Directory to store downloads.";
    };

    user = mkOption {
      type = types.str;
      default = "podgrab";
      description = "User under which Podgrab runs, and which owns the download directory.";
    };

    group = mkOption {
      type = types.str;
      default = "podgrab";
      description = "Group under which Podgrab runs, and which owns the download directory.";
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.tmpfiles.settings."10-pyload" = {
      ${cfg.dataDirectory}.d = { inherit (cfg) user group; };
    };

    systemd.services.podgrab = {
      description = "Podgrab podcast manager";
      wantedBy = [ "multi-user.target" ];
      environment = {
        CONFIG = "${stateDir}/config";
        DATA = cfg.dataDirectory;
        GIN_MODE = "release";
        PORT = toString cfg.port;
      };
      serviceConfig = {
        User = cfg.user;
        Group = cfg.group;
        EnvironmentFile = lib.optionals (cfg.passwordFile != null) [
          cfg.passwordFile
        ];
        ExecStart = "${pkgs.podgrab}/bin/podgrab";
        WorkingDirectory = "${pkgs.podgrab}/share";
        StateDirectory = [ "podgrab/config" ];
      };
    };

    users.users.podgrab = lib.mkIf (cfg.user == "podgrab") {
      isSystemUser = true;
      group = cfg.group;
    };

    users.groups.podgrab = lib.mkIf (cfg.group == "podgrab") { };
  };

  meta.maintainers = with lib.maintainers; [ ambroisie ];
}