-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtclip.nix
105 lines (95 loc) · 2.4 KB
/
tclip.nix
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
{
config,
pkgs,
lib,
inputs,
...
}:
with lib; let
cfg = config.services.tclip;
in {
options.services.tclip = {
enable = mkEnableOption "Enable tclip service";
package = mkOption {
type = types.package;
description = ''
tclip package to use
'';
default = pkgs.tclipd;
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/tclip";
description = "Path to data dir";
};
hostname = mkOption {
type = types.str;
default = "paste";
description = "Hostname to use on your tailnet";
};
funnel = mkOption {
type = types.bool;
default = false;
description = "if set, expose individual pastes to the public internet with Funnel";
};
user = mkOption {
type = types.str;
default = "tclip";
description = "User account under which tclip runs.";
};
group = mkOption {
type = types.str;
default = "tclip";
description = "Group account under which tclip runs.";
};
tailscaleAuthKeyFile = mkOption {
type = types.path;
description = "Path to file containing the Tailscale Auth Key";
};
verbose = mkOption {
type = types.bool;
default = false;
};
};
config = mkIf cfg.enable {
environment.systemPackages = [
pkgs.tclip
];
users.users."${cfg.user}" = {
home = cfg.dataDir;
createHome = true;
group = "${cfg.group}";
isSystemUser = true;
isNormalUser = false;
description = "User for tclip service";
};
users.groups."${cfg.group}" = {};
systemd.services.tclip = {
enable = true;
script = let
args =
[
"--data-location"
cfg.dataDir
"--hostname"
cfg.hostname
]
++ lib.optionals cfg.verbose ["--tsnet-verbose"]
++ lib.optionals cfg.funnel ["--use-funnel"];
in ''
${lib.optionalString (cfg.tailscaleAuthKeyFile != null) ''
export TS_AUTHKEY="$(head -n1 ${lib.escapeShellArg cfg.tailscaleAuthKeyFile})"
''}
${cfg.package}/bin/tclipd ${builtins.concatStringsSep " " args};
'';
wantedBy = ["multi-user.target"];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Restart = "always";
RestartSec = "15";
WorkingDirectory = "${cfg.dataDir}";
};
};
};
}