xin/modules/ts-rev-prox.nix

106 lines
2.5 KiB
Nix
Raw Normal View History

2023-07-11 09:12:50 -06:00
{
lib,
config,
pkgs,
...
}: let
cfg = config.services.tsrevprox;
2023-01-31 12:55:00 -07:00
in {
options = with lib; {
services.tsrevprox = {
enable = lib.mkEnableOption "Enable tsrevprox";
reversePort = mkOption {
type = types.int;
default = 5000;
description = ''
Port to forward connections to.
'';
};
reverseIP = mkOption {
type = types.str;
default = "127.0.0.1";
description = ''
IP to forward connections to.
'';
};
reverseName = mkOption {
type = types.str;
default = "tsrevprox";
description = ''
Name used in for the front facing http server (will be a tailscale name).
2023-01-31 12:55:24 -07:00
'';
2023-01-31 12:55:00 -07:00
};
user = mkOption {
2023-07-11 09:12:50 -06:00
type = with types; oneOf [str int];
2023-01-31 12:55:00 -07:00
default = "tsrevprox";
description = ''
The user the service will use.
'';
};
group = mkOption {
2023-07-11 09:12:50 -06:00
type = with types; oneOf [str int];
2023-01-31 12:55:00 -07:00
default = "tsrevprox";
description = ''
The group the service will use.
'';
};
dataDir = mkOption {
type = types.path;
default = "/var/lib/tsrevprox";
description = "Path tsrevprox home directory";
};
package = mkOption {
type = types.package;
default = pkgs.ts-reverse-proxy;
defaultText = literalExpression "pkgs.ts-reverse-proxy";
description = "The package to use for ts-reverse-proxy";
};
envFile = mkOption {
type = types.path;
default = "/run/secrets/ts_proxy_env";
description = ''
Path to a file containing the ts-reverse-proxy token information
'';
};
};
};
2023-01-31 12:55:24 -07:00
config = lib.mkIf cfg.enable {
2023-07-11 09:12:50 -06:00
users.groups.${cfg.group} = {};
2023-01-31 12:55:00 -07:00
users.users.${cfg.user} = {
description = "tsrevprox service user";
isSystemUser = true;
home = "${cfg.dataDir}";
createHome = true;
group = "${cfg.group}";
};
systemd.services.tsrevprox = {
enable = true;
description = "tsrevprox server";
2023-07-11 09:12:50 -06:00
wantedBy = ["network-online.target"];
after = ["network-online.target"];
2023-01-31 12:55:00 -07:00
2023-07-11 09:12:50 -06:00
environment = {HOME = "${cfg.dataDir}";};
2023-01-31 12:55:00 -07:00
serviceConfig = {
User = cfg.user;
Group = cfg.group;
2023-07-11 09:12:50 -06:00
ExecStart = "${cfg.package}/bin/ts-reverse-proxy -name ${cfg.reverseName} -port ${
toString cfg.reversePort
} -ip ${cfg.reverseIP}";
2023-01-31 12:55:00 -07:00
EnvironmentFile = cfg.envFile;
};
};
};
}