blob: 84dffc5f9d3c5df82ff598d526156460cc8bc316 (
plain)
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
84
85
86
87
88
89
90
|
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.audiobookshelf;
in
{
options = {
services.audiobookshelf = {
enable = mkEnableOption "Audiobookshelf, self-hosted audiobook and podcast server.";
package = mkPackageOption pkgs "audiobookshelf" { };
dataDir = mkOption {
description = "Path to Audiobookshelf config and metadata inside of /var/lib.";
default = "audiobookshelf";
type = types.str;
};
host = mkOption {
description = "The host Audiobookshelf binds to.";
default = "127.0.0.1";
example = "0.0.0.0";
type = types.str;
};
port = mkOption {
description = "The TCP port Audiobookshelf will listen on.";
default = 8000;
type = types.port;
};
user = mkOption {
description = "User account under which Audiobookshelf runs.";
default = "audiobookshelf";
type = types.str;
};
group = mkOption {
description = "Group under which Audiobookshelf runs.";
default = "audiobookshelf";
type = types.str;
};
openFirewall = mkOption {
description = "Open ports in the firewall for the Audiobookshelf web interface.";
default = false;
type = types.bool;
};
};
};
config = mkIf cfg.enable {
systemd.services.audiobookshelf = {
description = "Audiobookshelf is a self-hosted audiobook and podcast server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
StateDirectory = cfg.dataDir;
WorkingDirectory = "/var/lib/${cfg.dataDir}";
ExecStart = "${cfg.package}/bin/audiobookshelf --host ${cfg.host} --port ${toString cfg.port}";
Restart = "on-failure";
};
};
users.users = mkIf (cfg.user == "audiobookshelf") {
audiobookshelf = {
isSystemUser = true;
group = cfg.group;
home = "/var/lib/${cfg.dataDir}";
};
};
users.groups = mkIf (cfg.group == "audiobookshelf") {
audiobookshelf = { };
};
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
};
meta.maintainers = with maintainers; [ wietsedv ];
}
|