From b1fd5298f8abe93f07e33ccf188dffe154204983 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Sun, 14 Jan 2024 13:36:53 -0500 Subject: [PATCH] Relax store path canonicalization --- src/libstore/globals.cc | 8 +++++++- src/libstore/path.cc | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index fb4f879682c6..d31e7b3aab22 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -50,7 +50,13 @@ static GlobalConfig::Register rSettings(&settings); Settings::Settings() : nixPrefix(NIX_PREFIX) - , nixStore(canonPath(getEnvNonEmpty("NIX_STORE_DIR").value_or(getEnvNonEmpty("NIX_STORE").value_or(NIX_STORE_DIR)))) + , nixStore( +#ifndef _WIN32 + // On Windows `/nix/store` is not a canonical path, but we dont' + // want to deal with that yet. + canonPath +#endif + (getEnvNonEmpty("NIX_STORE_DIR").value_or(getEnvNonEmpty("NIX_STORE").value_or(NIX_STORE_DIR)))) , nixDataDir(canonPath(getEnvNonEmpty("NIX_DATA_DIR").value_or(NIX_DATA_DIR))) , nixLogDir(canonPath(getEnvNonEmpty("NIX_LOG_DIR").value_or(NIX_LOG_DIR))) , nixStateDir(canonPath(getEnvNonEmpty("NIX_STATE_DIR").value_or(NIX_STATE_DIR))) diff --git a/src/libstore/path.cc b/src/libstore/path.cc index 5db4b974c3c3..dc5fd603ee3d 100644 --- a/src/libstore/path.cc +++ b/src/libstore/path.cc @@ -63,7 +63,17 @@ StorePath StorePath::random(std::string_view name) StorePath StoreDirConfig::parseStorePath(std::string_view path) const { - auto p = canonPath(std::string(path)); + // On Windows, `/nix/store` is not a canonical path. More broadly it + // is unclear whether this function should be using the native + // notion of a canonical path at all. It makes to talk about remote + // stores whose store dir is the "other" kind of path. + auto p = +#ifdef _WIN32 + path +#else + canonPath(std::string(path)) +#endif + ; if (dirOf(p) != storeDir) throw BadStorePath("path '%s' is not in the Nix store", p); return StorePath(baseNameOf(p));