libslirp, darwin.linux-builder: fix DNS resolution using libslirp on MacOS (#398952)

authored by Aleksana and committed by GitHub fddba767 9130e210

+52 -8
-8
nixos/modules/profiles/nix-builder-vm.nix
··· 111 }; 112 }; 113 114 - # DNS fails for QEMU user networking (SLiRP) on macOS. See: 115 - # 116 - # https://github.com/utmapp/UTM/issues/2353 117 - # 118 - # This works around that by using a public DNS server other than the DNS 119 - # server that QEMU provides (normally 10.0.2.3) 120 - networking.nameservers = [ "8.8.8.8" ]; 121 - 122 # The linux builder is a lightweight VM for remote building; not evaluation. 123 nix.channel.enable = false; 124
··· 111 }; 112 }; 113 114 # The linux builder is a lightweight VM for remote building; not evaluation. 115 nix.channel.enable = false; 116
+46
pkgs/by-name/li/libslirp/fix-dns-for-darwin.patch
···
··· 1 + From 735904142f95d0500c0eae6bf763e4ad24b6b9fd Mon Sep 17 00:00:00 2001 2 + From: Samuel Thibault <samuel.thibault@ens-lyon.org> 3 + Date: Wed, 26 Mar 2025 08:42:35 +0100 4 + Subject: [PATCH] apple: Fix getting IPv4 DNS server address when IPv4 and IPv4 5 + are interleaved 6 + 7 + When getting an IPv4 DNS server address, if libresolv returns 8 + 9 + IPv4 10 + IPv6 11 + IPv4 12 + IPv6 13 + 14 + (or just IPv4 and IPv6) 15 + 16 + we would still have found == 1 on the second iteration and thus take the 17 + IPv6 even if it's not the proper af. We can as well just completely ignore 18 + the non-matching af entries. 19 + 20 + Fixes #85 21 + --- 22 + src/slirp.c | 7 +++++-- 23 + 1 file changed, 5 insertions(+), 2 deletions(-) 24 + 25 + diff --git a/src/slirp.c b/src/slirp.c 26 + index bccee53..62a018a 100644 27 + --- a/src/slirp.c 28 + +++ b/src/slirp.c 29 + @@ -289,9 +289,12 @@ static int get_dns_addr_libresolv(int af, void *pdns_addr, void *cached_addr, 30 + found = 0; 31 + DEBUG_MISC("IP address of your DNS(s):"); 32 + for (int i = 0; i < count; i++) { 33 + - if (af == servers[i].sin.sin_family) { 34 + - found++; 35 + + if (af != servers[i].sin.sin_family) { 36 + + continue; 37 + } 38 + + 39 + + found++; 40 + + 41 + if (af == AF_INET) { 42 + addr = &servers[i].sin.sin_addr; 43 + } else { // af == AF_INET6 44 + -- 45 + GitLab 46 +
+6
pkgs/by-name/li/libslirp/package.nix
··· 20 sha256 = "sha256-Eqdw6epFkLv4Dnw/s1pcKW0P70ApZwx/J2VkCwn50Ew="; 21 }; 22 23 separateDebugInfo = true; 24 25 nativeBuildInputs = [
··· 20 sha256 = "sha256-Eqdw6epFkLv4Dnw/s1pcKW0P70ApZwx/J2VkCwn50Ew="; 21 }; 22 23 + patches = [ 24 + # https://gitlab.freedesktop.org/slirp/libslirp/-/commit/735904142f95d0500c0eae6bf763e4ad24b6b9fd 25 + # Vendorized due to frequent instability of the upstream repository. 26 + ./fix-dns-for-darwin.patch 27 + ]; 28 + 29 separateDebugInfo = true; 30 31 nativeBuildInputs = [