From da6034f9818e4439a225267b5349c4d63a205bfd Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 28 Nov 2026 14:24:29 +0000 Subject: 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. --- modules/iptables.nix | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'modules') 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 | -- cgit v1.3.1