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
|
{
pkgs,
lib,
config,
...
}:
let
cfg = config.services.tailproxy;
pkg = pkgs.callPackage ./pkg.nix { inherit pkgs; };
in
{
options =
let
inherit (lib) mkEnableOption mkOption types;
in
{
services.tailproxy = {
enable = mkEnableOption "Enable tailproxy";
package = mkOption {
type = types.package;
description = "tailproxy package to use";
default = pkg;
};
hostname = mkOption {
type = types.str;
description = "Tailscale hostname";
};
auth-key = mkOption {
type = types.str;
description = "Tailscale auth key";
};
funnel = mkOption {
type = types.bool;
description = "Expose on Tailscale funnel";
};
data-dir = mkOption {
type = types.str;
description = "tsnet data directory";
default = ".tailproxy";
};
port = mkOption {
type = types.int;
description = "Port to proxy";
};
user = mkOption {
type = types.str;
default = "tailproxy";
description = "User account under which tailproxy runs";
};
group = mkOption {
type = types.str;
default = "tailproxy";
description = "Group account under which tailproxy runs";
};
};
};
config = lib.mkIf cfg.enable {
users.users."${cfg.user}" = {
home = "/var/lib/tailproxy";
createHome = true;
group = "${cfg.group}";
isSystemUser = true;
isNormalUser = false;
description = "user for tailproxy service";
};
users.groups."${cfg.group}" = { };
systemd.services = {
tailproxy = {
enable = true;
script =
let
args = [
"--hostname=${cfg.hostname}"
"--auth-key=${cfg.auth-key}"
"--funnel=${cfg.funnel}"
"--data-dir=${cfg.data-dir}"
"--port=${cfg.port}"
];
in
"${cfg.package}/bin/tailproxyd ${builtins.concatStringsSep " " args}";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
path = [
cfg.package
];
serviceConfig = {
User = cfg.user;
Group = cfg.group;
Restart = "always";
RestartSec = "15";
WorkingDirectory = "/var/lib/tailproxy";
};
};
};
};
}
|