From 3902b08d8be2a1d21f5565e4a5541acf81f9c24e Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Tue, 15 Apr 2025 15:17:32 -0400 Subject: [PATCH 1/2] libslirp: fix DNS resolution on MacOS Signed-off-by: Ihar Hrachyshka --- .../li/libslirp/fix-dns-for-darwin.patch | 46 +++++++++++++++++++ pkgs/by-name/li/libslirp/package.nix | 6 +++ 2 files changed, 52 insertions(+) create mode 100644 pkgs/by-name/li/libslirp/fix-dns-for-darwin.patch diff --git a/pkgs/by-name/li/libslirp/fix-dns-for-darwin.patch b/pkgs/by-name/li/libslirp/fix-dns-for-darwin.patch new file mode 100644 index 000000000000..f6e1a8c1b519 --- /dev/null +++ b/pkgs/by-name/li/libslirp/fix-dns-for-darwin.patch @@ -0,0 +1,46 @@ +From 735904142f95d0500c0eae6bf763e4ad24b6b9fd Mon Sep 17 00:00:00 2001 +From: Samuel Thibault +Date: Wed, 26 Mar 2025 08:42:35 +0100 +Subject: [PATCH] apple: Fix getting IPv4 DNS server address when IPv4 and IPv4 + are interleaved + +When getting an IPv4 DNS server address, if libresolv returns + +IPv4 +IPv6 +IPv4 +IPv6 + +(or just IPv4 and IPv6) + +we would still have found == 1 on the second iteration and thus take the +IPv6 even if it's not the proper af. We can as well just completely ignore +the non-matching af entries. + +Fixes #85 +--- + src/slirp.c | 7 +++++-- + 1 file changed, 5 insertions(+), 2 deletions(-) + +diff --git a/src/slirp.c b/src/slirp.c +index bccee53..62a018a 100644 +--- a/src/slirp.c ++++ b/src/slirp.c +@@ -289,9 +289,12 @@ static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr, + found = 0; + DEBUG_MISC("IP address of your DNS(s):"); + for (int i = 0; i < count; i++) { +- if (af == servers[i].sin.sin_family) { +- found++; ++ if (af != servers[i].sin.sin_family) { ++ continue; + } ++ ++ found++; ++ + if (af == AF_INET) { + addr = &servers[i].sin.sin_addr; + } else { // af == AF_INET6 +-- +GitLab + diff --git a/pkgs/by-name/li/libslirp/package.nix b/pkgs/by-name/li/libslirp/package.nix index 1070b00f8195..98a73e4109fe 100644 --- a/pkgs/by-name/li/libslirp/package.nix +++ b/pkgs/by-name/li/libslirp/package.nix @@ -20,6 +20,12 @@ stdenv.mkDerivation rec { sha256 = "sha256-Eqdw6epFkLv4Dnw/s1pcKW0P70ApZwx/J2VkCwn50Ew="; }; + patches = [ + # https://gitlab.freedesktop.org/slirp/libslirp/-/commit/735904142f95d0500c0eae6bf763e4ad24b6b9fd + # Vendorized due to frequent instability of the upstream repository. + ./fix-dns-for-darwin.patch + ]; + separateDebugInfo = true; nativeBuildInputs = [ From f90236a8f2c33cc8814428ac4cda1e77e43c2375 Mon Sep 17 00:00:00 2001 From: Ihar Hrachyshka Date: Tue, 15 Apr 2025 15:17:51 -0400 Subject: [PATCH 2/2] linux-builder: remove DNS hack for libslirp libslirp DNS issues on MacOS are now fixed. The override to use 8.8.8.8 as DNS server for linux-builder is not needed anymore. Signed-off-by: Ihar Hrachyshka --- nixos/modules/profiles/nix-builder-vm.nix | 8 -------- 1 file changed, 8 deletions(-) diff --git a/nixos/modules/profiles/nix-builder-vm.nix b/nixos/modules/profiles/nix-builder-vm.nix index 1f5eff8f133f..439d7a4430f2 100644 --- a/nixos/modules/profiles/nix-builder-vm.nix +++ b/nixos/modules/profiles/nix-builder-vm.nix @@ -111,14 +111,6 @@ in }; }; - # DNS fails for QEMU user networking (SLiRP) on macOS. See: - # - # https://github.com/utmapp/UTM/issues/2353 - # - # This works around that by using a public DNS server other than the DNS - # server that QEMU provides (normally 10.0.2.3) - networking.nameservers = [ "8.8.8.8" ]; - # The linux builder is a lightweight VM for remote building; not evaluation. nix.channel.enable = false;