From 3eb621750848e0e6b30e5a79f76afbb096bb6c8a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 27 Jul 2016 17:47:18 +0200 Subject: [PATCH] Add a "root" parameter to local stores This makes it easier to create a diverted store, i.e. NIX_REMOTE="local?root=/tmp/root" instead of NIX_REMOTE="local?real=/tmp/root/nix/store&state=/tmp/root/nix/var/nix" NIX_LOG_DIR=/tmp/root/nix/var/log --- src/libstore/build.cc | 2 +- src/libstore/local-fs-store.cc | 4 +++- src/libstore/local-store.cc | 2 +- src/libstore/store-api.hh | 2 ++ src/nix-store/nix-store.cc | 8 ++++++-- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 10ae574f9..08a7fd91d 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -2910,7 +2910,7 @@ Path DerivationGoal::openLogFile() string baseName = baseNameOf(drvPath); /* Create a log file. */ - Path dir = (format("%1%/%2%/%3%/") % settings.nixLogDir % drvsLogDir % string(baseName, 0, 2)).str(); + Path dir = (format("%1%/%2%/%3%/") % worker.store.logDir % drvsLogDir % string(baseName, 0, 2)).str(); createDirs(dir); Path logFileName = (format("%1%/%2%%3%") diff --git a/src/libstore/local-fs-store.cc b/src/libstore/local-fs-store.cc index b1b9dc29e..c6ed8f746 100644 --- a/src/libstore/local-fs-store.cc +++ b/src/libstore/local-fs-store.cc @@ -7,7 +7,9 @@ namespace nix { LocalFSStore::LocalFSStore(const Params & params) : Store(params) - , stateDir(get(params, "state", settings.nixStateDir)) + , rootDir(get(params, "root")) + , stateDir(canonPath(get(params, "state", rootDir != "" ? rootDir + "/nix/var/nix" : settings.nixStateDir))) + , logDir(canonPath(get(params, "log", rootDir != "" ? rootDir + "/nix/var/log/nix" : settings.nixLogDir))) { } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index f96109123..bc03c5374 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -38,7 +38,7 @@ namespace nix { LocalStore::LocalStore(const Params & params) : LocalFSStore(params) - , realStoreDir(get(params, "real", storeDir)) + , realStoreDir(get(params, "real", rootDir != "" ? rootDir + "/nix/store" : storeDir)) , dbDir(stateDir + "/db") , linksDir(realStoreDir + "/.links") , reservedPath(dbDir + "/reserved") diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 0b80312d6..f80a06aaf 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -491,7 +491,9 @@ protected: class LocalFSStore : public Store { public: + const Path rootDir; const Path stateDir; + const Path logDir; LocalFSStore(const Params & params); diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 8532101a1..e8b56f929 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -483,6 +483,10 @@ static void opReadLog(Strings opFlags, Strings opArgs) RunPager pager; + // FIXME: move getting logs into Store. + auto store2 = std::dynamic_pointer_cast(store); + if (!store2) throw Error(format("store ā€˜%sā€™ does not support reading logs") % store->getUri()); + for (auto & i : opArgs) { Path path = useDeriver(store->followLinksToStorePath(i)); @@ -493,8 +497,8 @@ static void opReadLog(Strings opFlags, Strings opArgs) Path logPath = j == 0 - ? (format("%1%/%2%/%3%/%4%") % settings.nixLogDir % drvsLogDir % string(baseName, 0, 2) % string(baseName, 2)).str() - : (format("%1%/%2%/%3%") % settings.nixLogDir % drvsLogDir % baseName).str(); + ? (format("%1%/%2%/%3%/%4%") % store2->logDir % drvsLogDir % string(baseName, 0, 2) % string(baseName, 2)).str() + : (format("%1%/%2%/%3%") % store2->logDir % drvsLogDir % baseName).str(); Path logBz2Path = logPath + ".bz2"; if (pathExists(logPath)) {