forked from kikkia/yt-cipher
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodule.nix
More file actions
110 lines (95 loc) · 2.86 KB
/
module.nix
File metadata and controls
110 lines (95 loc) · 2.86 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{
config,
lib,
pkgs,
...
}: let
cfg = config.services.yt-cipher;
in {
options.services.yt-cipher = {
enable = lib.mkEnableOption "yt-cipher service";
package = lib.mkOption {
type = lib.types.package;
default = pkgs.yt-cipher;
defaultText = "pkgs.yt-cipher";
description = "The yt-cipher package to use";
};
user = lib.mkOption {
type = lib.types.str;
default = "yt-cipher";
description = "User to run yt-cipher as";
};
group = lib.mkOption {
type = lib.types.str;
default = "yt-cipher";
description = "Group to run yt-cipher as";
};
openFirewall = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to open the specified port in the firewall";
};
apiToken = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "A required password to access this service";
};
apiTokenFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = "Path to a file containing the API token";
};
host = lib.mkOption {
type = lib.types.str;
default = "127.0.0.1";
description = "Sets the hostname for the bun server";
};
port = lib.mkOption {
type = lib.types.port;
default = 8001;
description = "Port to run the api on";
};
environment = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = "Additional environment variables to pass to the service";
example = ["MAX_THREADS=3"];
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.apiToken == null || cfg.apiTokenFile == null;
message = "cannot set both services.yt-cipher.apiToken and services.yt-cipher.apiTokenFile";
}
];
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [cfg.port];
systemd.services.yt-cipher = {
description = "yt-cipher service";
after = ["network-online.target"];
wants = ["network-online.target"];
wantedBy = ["multi-user.target"];
serviceConfig = {
ExecStart = "${cfg.package}/bin/yt-cipher";
User = cfg.user;
Group = cfg.group;
Restart = "on-failure";
CacheDirectory = "yt-cipher";
Environment =
["HOST=${cfg.host}" "PORT=${toString cfg.port}"]
++ (lib.optional (cfg.apiToken != null) "API_TOKEN=${cfg.apiToken}")
++ cfg.environment;
LoadCredential = lib.optional (cfg.apiTokenFile != null) "API_TOKEN:${cfg.apiTokenFile}";
};
};
users.users = lib.mkIf (cfg.user == "yt-cipher") {
${cfg.user} = {
isSystemUser = true;
group = cfg.group;
};
};
users.groups = lib.mkIf (cfg.group == "yt-cipher") {
${cfg.group} = {};
};
};
}