Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libexpr-tests/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/libmain/shared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 1 addition & 8 deletions src/libstore/globals.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
5 changes: 0 additions & 5 deletions src/libstore/include/nix/store/globals.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/include/nix/store/store-api.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
10 changes: 9 additions & 1 deletion src/libstore/store-api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filesystem>
#include <nlohmann/json.hpp>
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/perl/lib/Nix/Store.xs
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Loading