fix: per-site config was not working properly

This commit is contained in:
FUFSoB committed 2026-07-02 19:18:55 +05:00
1 parent 459a864478
commit 57a3426c85
7 files changed
+123 -42

No files matched your search

+17 -9
View File
@@ -5069,10 +5069,11 @@ Each entry generates hostlists/list-\<name>\.txt and can clone a built-in
zapret family from the active config, clone it from another configName, zapret family from the active config, clone it from another configName,
add custom NFQWS rule fragments, or combine these pieces\. add custom NFQWS rule fragments, or combine these pieces\.
defaultDomains provides built-in zapret-discord-youtube domain groups defaultDomains selects same-named upstream zapret-discord-youtube
such as “youtube” and “discord”; defaultIps provides upstream IP/CIDR hostlists such as “general” and “google”, with the aliases “discord”
groups such as “all”\. configName is a higher-level and “youtube” for readability\. defaultIps provides upstream IP/CIDR
alternative to nfqwsArgs and cannot be used together with nfqwsArgs\. groups such as “all”\. configName is a higher-level alternative to
nfqwsArgs and cannot be used together with nfqwsArgs\.
@@ -5198,9 +5199,16 @@ null
Built-in domain groups copied from zapret-discord-youtube hostlists\. Built-in domain groups copied from zapret-discord-youtube hostlists\.
These are expanded and combined with domains\. These are expanded and combined with domains\.
“youtube” uses the upstream Google/YouTube list\. “discord” uses Each value maps directly to the same-named upstream file:
Discord-related domains from the upstream general list\. “other” uses “general” uses list-general\.txt, “google” uses list-google\.txt,
the non-Discord domains from the upstream general list\. and the remaining values use their corresponding list-\<name>\.txt\.
“discord” is an alias for “general”; “youtube” is an alias for
“google”\.
When “general” or “discord” is used together with configName, the
module also clones the selected config’s Discord UDP voice rule
(–filter-l7=discord,stun)\.
When preset is unset, use one defaultDomains entry per rule so the When preset is unset, use one defaultDomains entry per rule so the
module can infer a single rule family\. Split groups into separate module can infer a single rule family\. Split groups into separate
@@ -5209,7 +5217,7 @@ rules when they need different strategies\.
*Type:* *Type:*
list of (one of “youtube”, “discord”, “other”, “instagram”, “soundcloud”, “twitter”) list of (one of “general”, “google”, “discord”, “youtube”, “instagram”, “soundcloud”, “twitter”)
@@ -5225,7 +5233,7 @@ list of (one of “youtube”, “discord”, “other”, “instagram”, “s
```nix ```nix
[ [
"youtube" "google"
] ]
``` ```
+14 -6
View File
@@ -278,9 +278,10 @@ let
]; ];
zapretDefaultDomainType = types.enum [ zapretDefaultDomainType = types.enum [
"youtube" "general"
"google"
"discord" "discord"
"other" "youtube"
"instagram" "instagram"
"soundcloud" "soundcloud"
"twitter" "twitter"
@@ -321,15 +322,22 @@ let
Built-in domain groups copied from zapret-discord-youtube hostlists. Built-in domain groups copied from zapret-discord-youtube hostlists.
These are expanded and combined with domains. These are expanded and combined with domains.
"youtube" uses the upstream Google/YouTube list. "discord" uses Each value maps directly to the same-named upstream file:
Discord-related domains from the upstream general list. "other" uses "general" uses list-general.txt, "google" uses list-google.txt,
the non-Discord domains from the upstream general list. and the remaining values use their corresponding list-<name>.txt.
"discord" is an alias for "general"; "youtube" is an alias for
"google".
When "general" or "discord" is used together with configName, the
module also clones the selected config's Discord UDP voice rule
(--filter-l7=discord,stun).
When preset is unset, use one defaultDomains entry per rule so the When preset is unset, use one defaultDomains entry per rule so the
module can infer a single rule family. Split groups into separate module can infer a single rule family. Split groups into separate
rules when they need different strategies. rules when they need different strategies.
''; '';
example = [ "youtube" ]; example = [ "google" ];
}; };
ips = mkOption { ips = mkOption {
+5 -4
View File
@@ -152,10 +152,11 @@ in
zapret family from the active config, clone it from another configName, zapret family from the active config, clone it from another configName,
add custom NFQWS rule fragments, or combine these pieces. add custom NFQWS rule fragments, or combine these pieces.
defaultDomains provides built-in zapret-discord-youtube domain groups defaultDomains selects same-named upstream zapret-discord-youtube
such as "youtube" and "discord"; defaultIps provides upstream IP/CIDR hostlists such as "general" and "google", with the aliases "discord"
groups such as "all". configName is a higher-level and "youtube" for readability. defaultIps provides upstream IP/CIDR
alternative to nfqwsArgs and cannot be used together with nfqwsArgs. groups such as "all". configName is a higher-level alternative to
nfqwsArgs and cannot be used together with nfqwsArgs.
''; '';
example = [ example = [
{ {
+24 -6
View File
@@ -6,7 +6,6 @@
let let
trim = lib.strings.trim; trim = lib.strings.trim;
hasPrefix = lib.strings.hasPrefix; hasPrefix = lib.strings.hasPrefix;
hasInfix = lib.strings.hasInfix;
splitString = lib.strings.splitString; splitString = lib.strings.splitString;
zapretSrc = if builtins.isAttrs zapret && zapret ? outPath then zapret.outPath else zapret; zapretSrc = if builtins.isAttrs zapret && zapret ? outPath then zapret.outPath else zapret;
@@ -21,21 +20,22 @@ let
upstreamHostlist = file: parseListFile "${zapretSrc}/hostlists/${file}"; upstreamHostlist = file: parseListFile "${zapretSrc}/hostlists/${file}";
generalDomains = upstreamHostlist "list-general.txt"; generalDomains = upstreamHostlist "list-general.txt";
isDiscordDomain = domain: domain == "dis.gd" || hasInfix "discord" domain;
domainGroups = { domainGroups = {
general = generalDomains;
google = upstreamHostlist "list-google.txt";
discord = generalDomains;
youtube = upstreamHostlist "list-google.txt"; youtube = upstreamHostlist "list-google.txt";
discord = builtins.filter isDiscordDomain generalDomains;
other = builtins.filter (domain: !(isDiscordDomain domain)) generalDomains;
instagram = upstreamHostlist "list-instagram.txt"; instagram = upstreamHostlist "list-instagram.txt";
soundcloud = upstreamHostlist "list-soundcloud.txt"; soundcloud = upstreamHostlist "list-soundcloud.txt";
twitter = upstreamHostlist "list-twitter.txt"; twitter = upstreamHostlist "list-twitter.txt";
}; };
groupPresets = { groupPresets = {
youtube = "google"; general = "general";
google = "google";
discord = "general"; discord = "general";
other = "general"; youtube = "google";
instagram = "instagram"; instagram = "instagram";
soundcloud = "soundcloud"; soundcloud = "soundcloud";
twitter = "twitter"; twitter = "twitter";
@@ -45,6 +45,11 @@ let
all = upstreamHostlist "ipset-all.txt"; all = upstreamHostlist "ipset-all.txt";
}; };
protocolGroups = {
general = [ "discord-voice" ];
discord = [ "discord-voice" ];
};
expandDefaultDomains = expandDefaultDomains =
groups: groups:
lib.unique ( lib.unique (
@@ -76,12 +81,24 @@ let
effectiveRuleIpsetFamilies = effectiveRuleIpsetFamilies =
rule: rule:
lib.optional (effectiveRuleIps rule != [ ]) "all"; lib.optional (effectiveRuleIps rule != [ ]) "all";
effectiveRuleProtocolFamilies =
rule:
lib.optionals (rule.configName != null) (
lib.unique (
lib.concatMap (
group:
if builtins.hasAttr group protocolGroups then protocolGroups.${group} else [ ]
) rule.defaultDomains
)
);
in in
{ {
inherit inherit
domainGroups domainGroups
groupPresets groupPresets
ipGroups ipGroups
protocolGroups
expandDefaultDomains expandDefaultDomains
expandDefaultIps expandDefaultIps
inferPresets inferPresets
@@ -89,5 +106,6 @@ in
effectiveRuleIps effectiveRuleIps
effectiveRulePresets effectiveRulePresets
effectiveRuleIpsetFamilies effectiveRuleIpsetFamilies
effectiveRuleProtocolFamilies
; ;
} }
+2
View File
@@ -46,6 +46,7 @@ let
ips = zapretDomainGroups.effectiveRuleIps rule; ips = zapretDomainGroups.effectiveRuleIps rule;
presets = zapretDomainGroups.effectiveRulePresets rule; presets = zapretDomainGroups.effectiveRulePresets rule;
ipsets = zapretDomainGroups.effectiveRuleIpsetFamilies rule; ipsets = zapretDomainGroups.effectiveRuleIpsetFamilies rule;
protocols = zapretDomainGroups.effectiveRuleProtocolFamilies rule;
} }
) zapretCfg.hostlistRules; ) zapretCfg.hostlistRules;
@@ -73,6 +74,7 @@ let
nfqwsArgs nfqwsArgs
ipsets ipsets
presets presets
protocols
; ;
hasDomains = rule.domains != [ ]; hasDomains = rule.domains != [ ];
hasIps = rule.ips != [ ]; hasIps = rule.ips != [ ];
+34 -16
View File
@@ -1185,19 +1185,26 @@ let
enableDirectSync = false; enableDirectSync = false;
} }
{ {
name = "youtube-general"; name = "google-general";
defaultDomains = [ "youtube" ]; defaultDomains = [ "google" ];
configName = "general"; configName = "general";
} }
{ {
name = "discord-alt12"; name = "general-alt12";
defaultDomains = [ "discord" ]; defaultDomains = [ "general" ];
configName = "general (ALT12)"; configName = "general (ALT12)";
} }
{ {
name = "other"; name = "youtube-alias";
defaultDomains = [ "other" ]; defaultDomains = [ "youtube" ];
preset = "general"; configName = "general";
enableDirectSync = false;
}
{
name = "discord-alias";
defaultDomains = [ "discord" ];
configName = "general (ALT12)";
enableDirectSync = false;
} }
{ {
name = "upstream-ips"; name = "upstream-ips";
@@ -1273,7 +1280,7 @@ let
hostlistRules = [ hostlistRules = [
{ {
name = "conflict"; name = "conflict";
defaultDomains = [ "youtube" ]; defaultDomains = [ "google" ];
configName = "general"; configName = "general";
nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ]; nfqwsArgs = [ "--filter-tcp=443 --dpi-desync=fake" ];
} }
@@ -3640,19 +3647,30 @@ in
grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-googlevideo.txt"' "${zapretHostlistBase}/config" grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-googlevideo.txt"' "${zapretHostlistBase}/config"
grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-example.txt"' "${zapretHostlistBase}/config" grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-example.txt"' "${zapretHostlistBase}/config"
grep -F -- '--filter-tcp=443 --dpi-desync=fake,multisplit --hostlist="${zapretHostlistBase}/hostlists/list-example.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude-user.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude-user.txt" --new' "${zapretHostlistBase}/config" grep -F -- '--filter-tcp=443 --dpi-desync=fake,multisplit --hostlist="${zapretHostlistBase}/hostlists/list-example.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude.txt" --hostlist-exclude="${zapretHostlistBase}/hostlists/list-exclude-user.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude.txt" --ipset-exclude="${zapretHostlistBase}/hostlists/ipset-exclude-user.txt" --new' "${zapretHostlistBase}/config"
grep -F 'youtube.com' "${zapretHostlistBase}/hostlists/list-youtube-general.txt" grep -F 'youtube.com' "${zapretHostlistBase}/hostlists/list-google-general.txt"
grep -F 'googlevideo.com' "${zapretHostlistBase}/hostlists/list-youtube-general.txt" grep -F 'googlevideo.com' "${zapretHostlistBase}/hostlists/list-google-general.txt"
grep -F 'discord.com' "${zapretHostlistBase}/hostlists/list-discord-alt12.txt" grep -F 'discord.com' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
grep -F 'discord.gg' "${zapretHostlistBase}/hostlists/list-discord-alt12.txt" grep -F 'discord.gg' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
! grep -F 'cloudflare-ech.com' "${zapretHostlistBase}/hostlists/list-discord-alt12.txt" grep -F 'cloudflare-ech.com' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
grep -F 'cloudflare-ech.com' "${zapretHostlistBase}/hostlists/list-other.txt" grep -F 'cloudfront.net' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
! grep -F 'discord.com' "${zapretHostlistBase}/hostlists/list-other.txt" grep -F '7tv.app' "${zapretHostlistBase}/hostlists/list-general-alt12.txt"
cmp "${zapretHostlistBase}/hostlists/list-google-general.txt" "${zapretHostlistBase}/hostlists/list-youtube-alias.txt"
cmp "${zapretHostlistBase}/hostlists/list-general-alt12.txt" "${zapretHostlistBase}/hostlists/list-discord-alias.txt"
grep -F '1.1.1.0/24' "${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt" grep -F '1.1.1.0/24' "${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt"
grep -F '203.0.113.0/24' "${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt" grep -F '203.0.113.0/24' "${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt"
grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-youtube-general.txt"' "${zapretHostlistBase}/config" grep -F -- '--hostlist="${zapretHostlistBase}/hostlists/list-google-general.txt"' "${zapretHostlistBase}/config"
grep -F -- '--dpi-desync=multisplit --dpi-desync-split-seqovl=681' "${zapretHostlistBase}/config" grep -F -- '--dpi-desync=multisplit --dpi-desync-split-seqovl=681' "${zapretHostlistBase}/config"
grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt"' "${zapretHostlistBase}/config" grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-upstream-ips.txt"' "${zapretHostlistBase}/config"
grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt"' "${zapretHostlistBase}/config" grep -F -- '--ipset="${zapretHostlistBase}/hostlists/ipset-explicit-ips.txt"' "${zapretHostlistBase}/config"
google_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-google-general.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
default_google_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-google.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
general_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-general-alt12.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
default_general_rule_line=$(grep -nF -- '--hostlist="${zapretHostlistBase}/hostlists/list-general.txt"' "${zapretHostlistBase}/config" | head -n1 | cut -d: -f1)
discord_voice_rule_line=$(grep -nF -- '--filter-l7=discord,stun' "${zapretHostlistBase}/config" | grep -F -- '--dpi-desync-repeats=3' | head -n1 | cut -d: -f1)
default_voice_rule_line=$(grep -nF -- '--filter-l7=discord,stun' "${zapretHostlistBase}/config" | grep -F -- '--dpi-desync-repeats=6' | head -n1 | cut -d: -f1)
test "$google_rule_line" -lt "$default_google_rule_line"
test "$general_rule_line" -lt "$default_general_rule_line"
test "$discord_voice_rule_line" -lt "$default_voice_rule_line"
touch "$out" touch "$out"
''; '';
} }
+27 -1
View File
@@ -45,6 +45,12 @@ IPSET_PATTERNS = {
}, },
} }
PROTOCOL_PATTERNS = {
"discord-voice": {
"match": ["--filter-l7=discord,stun"],
},
}
def locate_nfqws_block(lines: list[str]) -> tuple[int, int]: def locate_nfqws_block(lines: list[str]) -> tuple[int, int]:
start = None start = None
@@ -149,6 +155,10 @@ def _render_ipset_args(
return f"{normalize_spaces(rendered)} --new" return f"{normalize_spaces(rendered)} --new"
def render_protocol_clone(line: str) -> str:
return f"{normalize_spaces(strip_trailing_new(line))} --new"
def render_preset_clone( def render_preset_clone(
line: str, line: str,
family: str, family: str,
@@ -225,6 +235,19 @@ def clone_ipset_lines(
] ]
def clone_protocol_lines(existing_lines: list[str], family: str) -> list[str]:
matches = [
line
for line in existing_lines
if any(marker in line for marker in PROTOCOL_PATTERNS[family]["match"])
]
if not matches:
raise ValueError(
f"Protocol family '{family}' is not present in the selected zapret config"
)
return [render_protocol_clone(line) for line in matches]
def activate_builtin_hostlists( def activate_builtin_hostlists(
existing_lines: list[str], existing_lines: list[str],
hostlists_dir: Path, hostlists_dir: Path,
@@ -301,6 +324,7 @@ def main() -> int:
preset = entry.get("preset") preset = entry.get("preset")
presets = [preset] if preset else [] presets = [preset] if preset else []
ipsets = entry.get("ipsets", []) ipsets = entry.get("ipsets", [])
protocols = entry.get("protocols", [])
has_domains = entry.get("hasDomains", bool(presets)) has_domains = entry.get("hasDomains", bool(presets))
has_ips = entry.get("hasIps", bool(ipsets)) has_ips = entry.get("hasIps", bool(ipsets))
@@ -316,6 +340,8 @@ def main() -> int:
entry_nfqws_lines, ipset, ipset_path, standard_excludes entry_nfqws_lines, ipset, ipset_path, standard_excludes
) )
) )
for protocol in protocols:
generated_lines.extend(clone_protocol_lines(entry_nfqws_lines, protocol))
for fragment in entry.get("nfqwsArgs", []): for fragment in entry.get("nfqwsArgs", []):
if has_domains: if has_domains:
generated_lines.append( generated_lines.append(
@@ -326,7 +352,7 @@ def main() -> int:
render_custom_ipset_args(fragment, ipset_path, standard_excludes) render_custom_ipset_args(fragment, ipset_path, standard_excludes)
) )
updated_lines = lines[:end] + generated_lines + lines[end:] updated_lines = lines[: start + 1] + generated_lines + lines[start + 1 :]
config_path.write_text("\n".join(updated_lines) + "\n", encoding="utf-8") config_path.write_text("\n".join(updated_lines) + "\n", encoding="utf-8")
return 0 return 0