modules/byedpi: improve configs

This commit is contained in:
Dmitriy Pleshevskiy 2024-12-15 16:44:09 +03:00
parent cfca967a6e
commit 9611f6850b
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 24 additions and 21 deletions
hosts/home
modules/nixos/services

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }: { config, lib, pkgs, ... }:
{ {
imports = [ imports = [
@ -17,17 +17,13 @@
################################################################################ ################################################################################
local.services.byedpi = { local.services.byedpi = {
enable = true; enable = true;
enableProxy = true;
settings = { settings = {
port = 1081; port = 1081;
fake = 1; fake = 1;
ttl = 8; ttl = 8;
}; };
}; };
networking.proxy = rec {
allProxy = "http://localhost:${toString config.local.services.byedpi.settings.port}";
httpProxy = allProxy;
httpsProxy = allProxy;
};
# local.services.i2pd.enable = true; # local.services.i2pd.enable = true;
# local.services.kubo.enable = true; # local.services.kubo.enable = true;

View file

@ -17,22 +17,23 @@ let
no-domain = !cfg.settings.domain.enable; no-domain = !cfg.settings.domain.enable;
}; };
mkSplitOption = let
strOrNum = with lib.types; either str number; splitType = with lib.types;
let strOrInt = either str int;
splitType = with lib.types; nullOr (either strOrNum (listOf strOrNum)); in nullOr (either strOrInt (listOf strOrInt));
in
mkSplitOption = description: lib.mkOption { description: lib.mkOption {
inherit description; inherit description;
type = splitType; type = splitType;
default = null; default = null;
}; };
in in
{ {
options.local.services.byedpi = with lib; { options.local.services.byedpi = with lib; {
enable = mkEnableOption "byedpi"; enable = mkEnableOption "byedpi";
package = mkPackageOption pkgs "byedpi" { }; package = mkPackageOption pkgs "byedpi" { };
openFirewall = mkEnableOption "Whether to open the required firewall ports in the firewall."; openFirewall = mkEnableOption "Whether to open the required firewall ports in the firewall.";
enableProxy = mkEnableOption "Whether to enable systemwide networking proxy";
settings = { settings = {
ip = mkOption { ip = mkOption {
type = types.str; type = types.str;
@ -40,21 +41,21 @@ in
default = "0.0.0.0"; default = "0.0.0.0";
}; };
port = mkOption { port = mkOption {
type = types.number; type = types.ints.u16;
description = "Listening port"; description = "Listening port";
default = 1080; default = 1080;
}; };
bufferSize = mkOption { bufferSize = mkOption {
type = types.number; type = types.int;
description = "Buffer size"; description = "Buffer size";
default = 16384; default = 16384;
}; };
debugLevel = mkOption { debugLevel = mkOption {
type = types.number; # 0, 1, 2 type = types.ints.between 0 2;
default = 0; default = 0;
}; };
connectionLimit = mkOption { connectionLimit = mkOption {
type = types.number; type = types.int;
description = "Connection count limit"; description = "Connection count limit";
default = 512; default = 512;
}; };
@ -63,7 +64,7 @@ in
tcpFastOpen.enable = mkEnableOption "Enable TCP Fast Open"; tcpFastOpen.enable = mkEnableOption "Enable TCP Fast Open";
ttl = mkOption { ttl = mkOption {
type = types.number; type = types.int;
default = 8; default = 8;
}; };
split = mkSplitOption "Split packet at n"; split = mkSplitOption "Split packet at n";
@ -85,6 +86,12 @@ in
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.port ]; networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ cfg.settings.port ];
networking.proxy = lib.mkIf cfg.enableProxy rec {
allProxy = "http://${cfg.settings.ip}:${toString cfg.settings.port}";
httpProxy = allProxy;
httpsProxy = allProxy;
};
systemd.services.byedpi = { systemd.services.byedpi = {
description = "Byedpi (Bypass DPI)"; description = "Byedpi (Bypass DPI)";