2022-09-29 20:19:33 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
cfg = config.services.chisel-server;
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.chisel-server = {
|
2024-08-28 21:19:03 +02:00
|
|
|
enable = lib.mkEnableOption "Chisel Tunnel Server";
|
|
|
|
host = lib.mkOption {
|
2022-09-29 20:19:33 +02:00
|
|
|
description = "Address to listen on, falls back to 0.0.0.0";
|
2024-08-28 21:19:03 +02:00
|
|
|
type = with lib.types; nullOr str;
|
2022-09-29 20:19:33 +02:00
|
|
|
default = null;
|
|
|
|
example = "[::1]";
|
|
|
|
};
|
2024-08-28 21:19:03 +02:00
|
|
|
port = lib.mkOption {
|
2022-09-29 20:19:33 +02:00
|
|
|
description = "Port to listen on, falls back to 8080";
|
2024-08-28 21:19:03 +02:00
|
|
|
type = with lib.types; nullOr port;
|
2022-09-29 20:19:33 +02:00
|
|
|
default = null;
|
|
|
|
};
|
2024-08-28 21:19:03 +02:00
|
|
|
authfile = lib.mkOption {
|
2022-09-29 20:19:33 +02:00
|
|
|
description = "Path to auth.json file";
|
2024-08-28 21:19:03 +02:00
|
|
|
type = with lib.types; nullOr path;
|
2022-09-29 20:19:33 +02:00
|
|
|
default = null;
|
|
|
|
};
|
2024-08-28 21:19:03 +02:00
|
|
|
keepalive = lib.mkOption {
|
2022-09-29 20:19:33 +02:00
|
|
|
description = "Keepalive interval, falls back to 25s";
|
2024-08-28 21:19:03 +02:00
|
|
|
type = with lib.types; nullOr str;
|
2022-09-29 20:19:33 +02:00
|
|
|
default = null;
|
|
|
|
example = "5s";
|
|
|
|
};
|
2024-08-28 21:19:03 +02:00
|
|
|
backend = lib.mkOption {
|
2022-09-29 20:19:33 +02:00
|
|
|
description = "HTTP server to proxy normal requests to";
|
2024-08-28 21:19:03 +02:00
|
|
|
type = with lib.types; nullOr str;
|
2022-09-29 20:19:33 +02:00
|
|
|
default = null;
|
|
|
|
example = "http://127.0.0.1:8888";
|
|
|
|
};
|
2024-08-28 21:19:03 +02:00
|
|
|
socks5 = lib.mkOption {
|
2022-09-29 20:19:33 +02:00
|
|
|
description = "Allow clients access to internal SOCKS5 proxy";
|
2024-08-28 21:19:03 +02:00
|
|
|
type = lib.types.bool;
|
2022-09-29 20:19:33 +02:00
|
|
|
default = false;
|
|
|
|
};
|
2024-08-28 21:19:03 +02:00
|
|
|
reverse = lib.mkOption {
|
2022-09-29 20:19:33 +02:00
|
|
|
description = "Allow clients reverse port forwarding";
|
2024-08-28 21:19:03 +02:00
|
|
|
type = lib.types.bool;
|
2022-09-29 20:19:33 +02:00
|
|
|
default = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-28 21:19:03 +02:00
|
|
|
config = lib.mkIf cfg.enable {
|
2022-09-29 20:19:33 +02:00
|
|
|
systemd.services.chisel-server = {
|
|
|
|
description = "Chisel Tunnel Server";
|
|
|
|
wantedBy = [ "network-online.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
2024-08-28 21:19:03 +02:00
|
|
|
ExecStart =
|
|
|
|
"${pkgs.chisel}/bin/chisel server "
|
|
|
|
+ lib.concatStringsSep " " (
|
|
|
|
lib.optional (cfg.host != null) "--host ${cfg.host}"
|
|
|
|
++ lib.optional (cfg.port != null) "--port ${builtins.toString cfg.port}"
|
|
|
|
++ lib.optional (cfg.authfile != null) "--authfile ${cfg.authfile}"
|
|
|
|
++ lib.optional (cfg.keepalive != null) "--keepalive ${cfg.keepalive}"
|
|
|
|
++ lib.optional (cfg.backend != null) "--backend ${cfg.backend}"
|
|
|
|
++ lib.optional cfg.socks5 "--socks5"
|
|
|
|
++ lib.optional cfg.reverse "--reverse"
|
2022-09-29 20:19:33 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
# Security Hardening
|
|
|
|
# Refer to systemd.exec(5) for option descriptions.
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
|
|
|
|
# implies RemoveIPC=, PrivateTmp=, NoNewPrivileges=, RestrictSUIDSGID=,
|
|
|
|
# ProtectSystem=strict, ProtectHome=read-only
|
|
|
|
DynamicUser = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
"AF_UNIX"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = "~@clock @cpu-emulation @debug @mount @obsolete @reboot @swap @privileged @resources";
|
|
|
|
UMask = "0077";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-08-28 21:19:03 +02:00
|
|
|
meta.maintainers = with lib.maintainers; [ clerie ];
|
2022-09-29 20:19:33 +02:00
|
|
|
}
|