summaryrefslogtreecommitdiff
path: root/nix/libstore
diff options
context:
space:
mode:
authorRoman Scherer <roman@burningswell.com>2026-03-07 13:10:43 +0100
committerLudovic Courtès <ludo@gnu.org>2026-03-19 15:32:46 +0100
commit82f84f5e7fb34cc719ed6ea538a3d1ca7516f23d (patch)
tree7497fc15b032af634846f74638461a3c78879cba /nix/libstore
parentaa5de6c847f4676f3a6e7def844a04f1254d1a18 (diff)
daemon: Resolve symlinks in /etc/resolv.conf for slirp4netns chroot.
* nix/libstore/build.cc (prepareSlirpChrootAction): Use canonPath(i, true) to resolve symlinks when adding /etc/resolv.conf and /etc/hosts to the slirp4netns chroot, so that bindMount receives a regular file path instead of a symlink. On systems using systemd-resolved, /etc/resolv.conf is typically a symlink: /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf The slirp4netns chroot creates an empty /run/ directory, so when bindMount copies the symlink verbatim (spawn.cc line 537-542), the target does not exist and slirp4netns cannot determine the upstream DNS server. This causes all DNS resolution to fail for fixed-output derivations that use the Guile-based git-fetch builder (e.g. git-fetch/lfs), since they rely on slirp4netns for network access in the build chroot. Derivations using builtin:git-download are unaffected because they run in the daemon process itself, which has full network access. Change-Id: Ib73e69a8760e74eb8141dd0408c27aa8b3001e37 Signed-off-by: Ludovic Courtès <ludo@gnu.org> Merges: #6959
Diffstat (limited to 'nix/libstore')
-rw-r--r--nix/libstore/build.cc8
1 files changed, 6 insertions, 2 deletions
diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc
index 3071c8ef10d..9bdf0a78aed 100644
--- a/nix/libstore/build.cc
+++ b/nix/libstore/build.cc
@@ -1972,11 +1972,15 @@ static void prepareSlirpChrootAction(SpawnContext & sctx)
1972 } 1972 }
1973 1973
1974 /* Limit /etc to containing just /etc/resolv.conf and /etc/hosts, and 1974 /* Limit /etc to containing just /etc/resolv.conf and /etc/hosts, and
1975 read-only at that */ 1975 read-only at that. Resolve symlinks in the source path so that
1976 bindMount sees a regular file and bind-mounts it, rather than
1977 copying a symlink whose target may not exist in the chroot
1978 (e.g. /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf
1979 with /run/ being empty in the chroot). */
1976 Strings etcFiles = { "/etc/resolv.conf", "/etc/hosts" }; 1980 Strings etcFiles = { "/etc/resolv.conf", "/etc/hosts" };
1977 for(auto & i : etcFiles) { 1981 for(auto & i : etcFiles) {
1978 if(pathExists(i)) { 1982 if(pathExists(i)) {
1979 ctx.filesInChroot[i] = i; 1983 ctx.filesInChroot[i] = canonPath(i, true);
1980 ctx.readOnlyFilesInChroot.insert(i); 1984 ctx.readOnlyFilesInChroot.insert(i);
1981 } 1985 }
1982 } 1986 }