Skip to content

Commit fddba76

Browse files
authored
libslirp, darwin.linux-builder: fix DNS resolution using libslirp on MacOS (#398952)
2 parents 9130e21 + f90236a commit fddba76

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

nixos/modules/profiles/nix-builder-vm.nix

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ in
111111
};
112112
};
113113

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-
122114
# The linux builder is a lightweight VM for remote building; not evaluation.
123115
nix.channel.enable = false;
124116

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
From 735904142f95d0500c0eae6bf763e4ad24b6b9fd Mon Sep 17 00:00:00 2001
2+
From: Samuel Thibault <[email protected]>
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+

pkgs/by-name/li/libslirp/package.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ stdenv.mkDerivation rec {
2020
sha256 = "sha256-Eqdw6epFkLv4Dnw/s1pcKW0P70ApZwx/J2VkCwn50Ew=";
2121
};
2222

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+
2329
separateDebugInfo = true;
2430

2531
nativeBuildInputs = [

0 commit comments

Comments
 (0)