diff --git a/src/libexpr-tests/primops.cc b/src/libexpr-tests/primops.cc index 36e3fa59803..ac5e893bf7d 100644 --- a/src/libexpr-tests/primops.cc +++ b/src/libexpr-tests/primops.cc @@ -756,7 +756,7 @@ TEST_F(PrimOpTest, langVersion) TEST_F(PrimOpTest, storeDir) { auto v = eval("builtins.storeDir"); - ASSERT_THAT(v, IsStringEq(settings.nixStore)); + ASSERT_THAT(v, IsStringEq(state.store->storeDir)); } TEST_F(PrimOpTest, nixVersion) diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index fd56e3f1e21..64520bee04d 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -3,6 +3,7 @@ #include "nix/util/executable-path.hh" #include "nix/main/shared.hh" #include "nix/store/store-api.hh" +#include "nix/store/store-open.hh" #include "nix/store/gc-store.hh" #include "nix/main/loggers.hh" #include "nix/main/progress-bar.hh" @@ -331,7 +332,8 @@ void printVersion(const std::string & programName) std::cout << "System configuration file: " << nixConfFile() << "\n"; std::cout << "User configuration files: " << os_string_to_string(ExecutablePath{.directories = nixUserConfFiles()}.render()) << "\n"; - std::cout << "Store directory: " << settings.nixStore << "\n"; + std::cout << "Store directory: " << resolveStoreConfig(StoreReference{settings.storeUri.get()})->storeDir + << "\n"; std::cout << "State directory: " << settings.nixStateDir << "\n"; } throw Exit(); diff --git a/src/libstore/globals.cc b/src/libstore/globals.cc index 47086519ad3..71877c7b632 100644 --- a/src/libstore/globals.cc +++ b/src/libstore/globals.cc @@ -83,14 +83,7 @@ Settings settings; static GlobalConfig::Register rSettings(&settings); Settings::Settings() - : 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)))) - , nixStateDir(canonPath(getEnvNonEmpty("NIX_STATE_DIR").value_or(NIX_STATE_DIR))) + : nixStateDir(canonPath(getEnvNonEmpty("NIX_STATE_DIR").value_or(NIX_STATE_DIR))) , nixDaemonSocketFile(canonPath(getEnvOsNonEmpty(OS_STR("NIX_DAEMON_SOCKET_PATH")) .transform([](auto && s) { return std::filesystem::path(s); }) .value_or(nixStateDir / DEFAULT_SOCKET_PATH))) diff --git a/src/libstore/include/nix/store/globals.hh b/src/libstore/include/nix/store/globals.hh index bd84770023e..059e35b43c6 100644 --- a/src/libstore/include/nix/store/globals.hh +++ b/src/libstore/include/nix/store/globals.hh @@ -158,11 +158,6 @@ public: static unsigned int getDefaultCores(); - /** - * The directory where we store sources and derived files. - */ - Path nixStore; - /** * The directory where state is stored. */ diff --git a/src/libstore/include/nix/store/store-api.hh b/src/libstore/include/nix/store/store-api.hh index ffaaeaa2c2a..890f7c075ee 100644 --- a/src/libstore/include/nix/store/store-api.hh +++ b/src/libstore/include/nix/store/store-api.hh @@ -83,8 +83,8 @@ struct StoreConfigBase : Config private: /** - * An indirection so that we don't need to refer to global settings - * in headers. + * Compute the default Nix store directory from environment variables + * (`NIX_STORE_DIR`, `NIX_STORE`) or the compile-time default. */ static Path getDefaultNixStoreDir(); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index 488295a37c6..2af96e4804f 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -18,6 +18,10 @@ // `addMultipleToStore`. #include "nix/store/worker-protocol.hh" #include "nix/util/signals.hh" +#include "nix/util/environment-variables.hh" +#include "nix/util/file-system.hh" + +#include "store-config-private.hh" #include #include @@ -30,7 +34,11 @@ namespace nix { Path StoreConfigBase::getDefaultNixStoreDir() { - return settings.nixStore; + return +#ifndef _WIN32 + canonPath +#endif + (getEnvNonEmpty("NIX_STORE_DIR").value_or(getEnvNonEmpty("NIX_STORE").value_or(NIX_STORE_DIR))); } StoreConfig::StoreConfig(const Params & params) diff --git a/src/perl/lib/Nix/Store.xs b/src/perl/lib/Nix/Store.xs index 0c158218506..6c4bf2e7051 100644 --- a/src/perl/lib/Nix/Store.xs +++ b/src/perl/lib/Nix/Store.xs @@ -424,4 +424,4 @@ StoreWrapper::addTempRoot(char * storePath) SV * getStoreDir() PPCODE: - XPUSHs(sv_2mortal(newSVpv(settings.nixStore.c_str(), 0))); + XPUSHs(sv_2mortal(newSVpv(resolveStoreConfig(StoreReference{settings.storeUri.get()})->storeDir.c_str(), 0)));