From 9a20bf56203bbe20d1e456f9d3050d94790b2833 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 15 Jan 2026 14:46:57 +0100 Subject: [PATCH] Path fetcher: Handle invalid paths This is especially important when using a chroot store and `path:...` refers to the host store. --- src/libfetchers/path.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 8f9ccd19132a..b75f7053e3ef 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -156,11 +156,13 @@ struct PathInputScheme : InputScheme // To prevent `fetchToStore()` copying the path again to Nix // store, pre-create an entry in the fetcher cache. - auto info = store.queryPathInfo(*storePath); - accessor->fingerprint = fmt("path:%s", info->narHash.to_string(HashFormat::SRI, true)); - settings.getCache()->upsert( - makeSourcePathToHashCacheKey(*accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"), - {{"hash", info->narHash.to_string(HashFormat::SRI, true)}}); + auto info = store.maybeQueryPathInfo(*storePath); + if (info) { + accessor->fingerprint = fmt("path:%s", info->narHash.to_string(HashFormat::SRI, true)); + settings.getCache()->upsert( + makeSourcePathToHashCacheKey(*accessor->fingerprint, ContentAddressMethod::Raw::NixArchive, "/"), + {{"hash", info->narHash.to_string(HashFormat::SRI, true)}}); + } } return {accessor, std::move(input)};