diff options
| author | tv <tv@krebsco.de> | 2026-11-28 14:24:29 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-28 14:24:29 +0000 |
| commit | da6034f9818e4439a225267b5349c4d63a205bfd (patch) | |
| tree | c5c6d0cab0187cb3ed32a539d1623feb880c98b3 /modules/iptables.nix | |
| parent | 5d72c0da85ccc77d55f0dbddd96cadbe5de484d8 (diff) | |
iptables: translate by the system that builds
The translation to nft is text, and iptables-restore-translate crashes
under emulation ("Failed to initialize nft: Protocol not supported"), as
for qi, built on zu.
Diffstat (limited to 'modules/iptables.nix')
| -rw-r--r-- | modules/iptables.nix | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/modules/iptables.nix b/modules/iptables.nix index 04fa4e7b..f2a719bb 100644 --- a/modules/iptables.nix +++ b/modules/iptables.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: let { +{ buildSystem, config, lib, pkgs, ... }: let { cfg = config.tv.iptables; body = { @@ -264,6 +264,13 @@ tv-iptables-ipv6 = rule "6" "ip6tables"; }; + # The translation is text, so the system that builds can make it with its + # own iptables. Emulated, the tool crashes for lack of netlink. + buildPkgs = + if buildSystem == pkgs.stdenv.hostPlatform.system + then pkgs + else import pkgs.path { system = buildSystem; }; + translate = tool: nfproto: table: chain: rules: let input = pkgs.writeText "tv-iptables-${tool}-${table}-${chain}" '' *${table} @@ -274,15 +281,15 @@ ${lib.concatMapStrings (rule: "-A ${chain} ${rule}\n") rules} COMMIT ''; - output = pkgs.runCommand "tv-iptables-${tool}-${table}-${chain}.nft" { - nativeBuildInputs = [ pkgs.iptables ]; + output = buildPkgs.runCommand "tv-iptables-${tool}-${table}-${chain}.nft" { + nativeBuildInputs = [ buildPkgs.iptables ]; # Service names like "smtp" and host names like "leg.r" need the # host's /etc/services and /etc/hosts. NIX_REDIRECTS = lib.concatStringsSep ":" [ "/etc/hosts=${config.environment.etc.hosts.source}" "/etc/services=${config.environment.etc.services.source}" ]; - LD_PRELOAD = "${pkgs.libredirect}/lib/libredirect.so"; + LD_PRELOAD = "${buildPkgs.libredirect}/lib/libredirect.so"; } '' ${tool}-restore-translate -f ${input} > translated sed -n 's/^add rule [a-z0-9]* ${table} ${chain} \(.*\)/\1/p' translated | |
