2024-07-08 15:07:24 +05:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2024-07-18 15:49:05 +05:00
|
|
|
bonPkgs,
|
2024-07-08 15:07:24 +05:00
|
|
|
...
|
|
|
|
}:
|
|
|
|
with lib; let
|
|
|
|
cfg = config.services.spoofdpi;
|
2023-12-26 15:16:21 +05:00
|
|
|
in {
|
2024-07-08 15:07:24 +05:00
|
|
|
options.services.spoofdpi = {
|
|
|
|
enable = mkEnableOption "SpoofDPI service";
|
2024-06-20 00:16:28 +05:00
|
|
|
|
2024-07-08 15:07:24 +05:00
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
2024-07-18 15:49:05 +05:00
|
|
|
default = bonPkgs.spoofdpi;
|
|
|
|
defaultText = literalExpression "bonPkgs.spoofdpi";
|
2024-07-08 15:07:24 +05:00
|
|
|
description = "The package to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
address = mkOption rec {
|
|
|
|
type = types.str;
|
|
|
|
default = "127.0.0.1";
|
|
|
|
example = default;
|
|
|
|
description = "Listen address.";
|
|
|
|
};
|
2023-12-26 15:16:21 +05:00
|
|
|
|
2024-07-08 15:07:24 +05:00
|
|
|
port = mkOption rec {
|
|
|
|
type = types.port;
|
|
|
|
default = 8080;
|
|
|
|
example = default;
|
|
|
|
description = "Port.";
|
|
|
|
};
|
2023-12-26 15:16:21 +05:00
|
|
|
|
2024-07-08 15:07:24 +05:00
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Open `services.spoofdpi.port`.";
|
|
|
|
};
|
2024-03-22 23:21:25 +05:00
|
|
|
|
2024-07-08 15:07:24 +05:00
|
|
|
dns = mkOption rec {
|
|
|
|
type = types.str;
|
|
|
|
default = "8.8.8.8";
|
|
|
|
example = default;
|
2024-07-25 12:15:44 +05:00
|
|
|
description = "DNS address.";
|
|
|
|
};
|
|
|
|
|
|
|
|
dnsPort = mkOption rec {
|
|
|
|
type = types.port;
|
|
|
|
default = 53;
|
|
|
|
example = default;
|
|
|
|
description = "DNS port.";
|
|
|
|
};
|
|
|
|
|
|
|
|
doh = mkEnableOption "DOH";
|
|
|
|
|
|
|
|
windowSize = mkOption rec {
|
|
|
|
type = types.int;
|
|
|
|
default = 50;
|
|
|
|
example = default;
|
|
|
|
description = "Window size for fragmented client hello.";
|
|
|
|
};
|
|
|
|
|
|
|
|
timeout = mkOption rec {
|
|
|
|
type = types.int;
|
|
|
|
default = 2000;
|
|
|
|
example = default;
|
|
|
|
description = "Timeout in milliseconds.";
|
|
|
|
};
|
|
|
|
|
|
|
|
pattern = mkOption {
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
default = null;
|
|
|
|
description = "Bypass DPI only on packets matching this regex pattern.";
|
|
|
|
};
|
|
|
|
|
|
|
|
bypassUrls = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = "Bypass DPI only on this urls.";
|
2023-12-26 15:16:21 +05:00
|
|
|
};
|
2024-07-08 15:07:24 +05:00
|
|
|
};
|
2023-12-26 15:16:21 +05:00
|
|
|
|
2024-07-08 15:07:24 +05:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.spoofdpi = {
|
|
|
|
wantedBy = ["multi-user.target"];
|
|
|
|
after = ["network.target"];
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
2024-07-25 12:15:44 +05:00
|
|
|
ExecStart = ''
|
|
|
|
${lib.getExe cfg.package} \
|
|
|
|
-no-banner \
|
|
|
|
-addr ${cfg.address} \
|
|
|
|
-port ${toString cfg.port} \
|
|
|
|
-dns-addr ${cfg.dns} \
|
|
|
|
-dns-port ${toString cfg.dnsPort} \
|
|
|
|
${lib.optionalString cfg.doh ''-enable-doh \''}
|
|
|
|
-window-size ${toString cfg.windowSize} \
|
|
|
|
-timeout ${toString cfg.timeout} \
|
|
|
|
${lib.optionalString (cfg.pattern != null) ''-pattern ${cfg.pattern} \''}
|
|
|
|
${lib.concatStringsSep " " (map (url: "-url ${url}") cfg.bypassUrls)}
|
|
|
|
'';
|
2024-07-08 15:07:24 +05:00
|
|
|
DynamicUser = "yes";
|
|
|
|
};
|
|
|
|
};
|
2024-03-22 23:21:25 +05:00
|
|
|
|
2024-07-08 15:07:24 +05:00
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [cfg.port];
|
2023-12-26 15:16:21 +05:00
|
|
|
};
|
2024-07-08 15:07:24 +05:00
|
|
|
};
|
2023-12-26 15:16:21 +05:00
|
|
|
}
|