aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libexpr/eval-cache.cc3
-rw-r--r--src/libfetchers/registry.cc2
-rw-r--r--src/libstore/gc.cc50
-rw-r--r--src/libstore/globals.hh4
-rw-r--r--src/libstore/http-binary-cache-store.cc11
-rw-r--r--src/libstore/profiles.cc6
-rw-r--r--src/libstore/profiles.hh4
-rw-r--r--src/libstore/store-api.hh3
-rwxr-xr-xsrc/nix-build/nix-build.cc2
-rw-r--r--src/nix-env/nix-env.cc4
-rw-r--r--src/nix-env/user-env.cc3
-rw-r--r--src/nix-instantiate/nix-instantiate.cc7
-rw-r--r--src/nix-store/nix-store.cc7
-rw-r--r--src/nix/build.cc4
-rw-r--r--src/nix/bundle.cc2
-rw-r--r--src/nix/command.cc2
16 files changed, 40 insertions, 74 deletions
diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc
index 46177a0a4..381344b40 100644
--- a/src/libexpr/eval-cache.cc
+++ b/src/libexpr/eval-cache.cc
@@ -391,7 +391,8 @@ Value & AttrCursor::forceValue()
if (root->db && (!cachedValue || std::get_if<placeholder_t>(&cachedValue->second))) {
if (v.type == tString)
- cachedValue = {root->db->setString(getKey(), v.string.s, v.string.context), v.string.s};
+ cachedValue = {root->db->setString(getKey(), v.string.s, v.string.context),
+ string_t{v.string.s, {}}};
else if (v.type == tPath)
cachedValue = {root->db->setString(getKey(), v.path), v.path};
else if (v.type == tBool)
diff --git a/src/libfetchers/registry.cc b/src/libfetchers/registry.cc
index d4134ce29..4367ee810 100644
--- a/src/libfetchers/registry.cc
+++ b/src/libfetchers/registry.cc
@@ -147,7 +147,7 @@ static std::shared_ptr<Registry> getGlobalRegistry(ref<Store> store)
if (!hasPrefix(path, "/")) {
auto storePath = downloadFile(store, path, "flake-registry.json", false).storePath;
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>())
- store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json", true);
+ store2->addPermRoot(storePath, getCacheDir() + "/nix/flake-registry.json");
path = store->toRealPath(storePath);
}
diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc
index e74382ed2..e6cbc525d 100644
--- a/src/libstore/gc.cc
+++ b/src/libstore/gc.cc
@@ -85,8 +85,7 @@ void LocalStore::addIndirectRoot(const Path & path)
}
-Path LocalFSStore::addPermRoot(const StorePath & storePath,
- const Path & _gcRoot, bool indirect, bool allowOutsideRootsDir)
+Path LocalFSStore::addPermRoot(const StorePath & storePath, const Path & _gcRoot)
{
Path gcRoot(canonPath(_gcRoot));
@@ -95,47 +94,12 @@ Path LocalFSStore::addPermRoot(const StorePath & storePath,
"creating a garbage collector root (%1%) in the Nix store is forbidden "
"(are you running nix-build inside the store?)", gcRoot);
- if (indirect) {
- /* Don't clobber the link if it already exists and doesn't
- point to the Nix store. */
- if (pathExists(gcRoot) && (!isLink(gcRoot) || !isInStore(readLink(gcRoot))))
- throw Error("cannot create symlink '%1%'; already exists", gcRoot);
- makeSymlink(gcRoot, printStorePath(storePath));
- addIndirectRoot(gcRoot);
- }
-
- else {
- if (!allowOutsideRootsDir) {
- Path rootsDir = canonPath((format("%1%/%2%") % stateDir % gcRootsDir).str());
-
- if (string(gcRoot, 0, rootsDir.size() + 1) != rootsDir + "/")
- throw Error(
- "path '%1%' is not a valid garbage collector root; "
- "it's not in the directory '%2%'",
- gcRoot, rootsDir);
- }
-
- if (baseNameOf(gcRoot) == std::string(storePath.to_string()))
- writeFile(gcRoot, "");
- else
- makeSymlink(gcRoot, printStorePath(storePath));
- }
-
- /* Check that the root can be found by the garbage collector.
- !!! This can be very slow on machines that have many roots.
- Instead of reading all the roots, it would be more efficient to
- check if the root is in a directory in or linked from the
- gcroots directory. */
- if (settings.checkRootReachability) {
- auto roots = findRoots(false);
- if (roots[storePath].count(gcRoot) == 0)
- logWarning({
- .name = "GC root",
- .hint = hintfmt("warning: '%1%' is not in a directory where the garbage collector looks for roots; "
- "therefore, '%2%' might be removed by the garbage collector",
- gcRoot, printStorePath(storePath))
- });
- }
+ /* Don't clobber the link if it already exists and doesn't
+ point to the Nix store. */
+ if (pathExists(gcRoot) && (!isLink(gcRoot) || !isInStore(readLink(gcRoot))))
+ throw Error("cannot create symlink '%1%'; already exists", gcRoot);
+ makeSymlink(gcRoot, printStorePath(storePath));
+ addIndirectRoot(gcRoot);
/* Grab the global GC root, causing us to block while a GC is in
progress. This prevents the set of permanent roots from
diff --git a/src/libstore/globals.hh b/src/libstore/globals.hh
index ab9f42ce6..8a2d3ff75 100644
--- a/src/libstore/globals.hh
+++ b/src/libstore/globals.hh
@@ -293,10 +293,6 @@ public:
Setting<unsigned int> pollInterval{this, 5, "build-poll-interval",
"How often (in seconds) to poll for locks."};
- Setting<bool> checkRootReachability{this, false, "gc-check-reachability",
- "Whether to check if new GC roots can in fact be found by the "
- "garbage collector."};
-
Setting<bool> gcKeepOutputs{
this, false, "keep-outputs",
R"(
diff --git a/src/libstore/http-binary-cache-store.cc b/src/libstore/http-binary-cache-store.cc
index c1ceb08cf..1733239fb 100644
--- a/src/libstore/http-binary-cache-store.cc
+++ b/src/libstore/http-binary-cache-store.cc
@@ -85,7 +85,7 @@ protected:
checkEnabled();
try {
- FileTransferRequest request(cacheUri + "/" + path);
+ FileTransferRequest request(makeRequest(path));
request.head = true;
getFileTransfer()->download(request);
return true;
@@ -103,7 +103,7 @@ protected:
std::shared_ptr<std::basic_iostream<char>> istream,
const std::string & mimeType) override
{
- auto req = FileTransferRequest(cacheUri + "/" + path);
+ auto req = makeRequest(path);
req.data = std::make_shared<string>(StreamToSourceAdapter(istream).drain());
req.mimeType = mimeType;
try {
@@ -115,8 +115,11 @@ protected:
FileTransferRequest makeRequest(const std::string & path)
{
- FileTransferRequest request(cacheUri + "/" + path);
- return request;
+ return FileTransferRequest(
+ hasPrefix(path, "https://") || hasPrefix(path, "http://") || hasPrefix(path, "file://")
+ ? path
+ : cacheUri + "/" + path);
+
}
void getFile(const std::string & path, Sink & sink) override
diff --git a/src/libstore/profiles.cc b/src/libstore/profiles.cc
index 6862b42f0..c20386e2b 100644
--- a/src/libstore/profiles.cc
+++ b/src/libstore/profiles.cc
@@ -72,7 +72,7 @@ static void makeName(const Path & profile, GenerationNumber num,
}
-Path createGeneration(ref<LocalFSStore> store, Path profile, Path outPath)
+Path createGeneration(ref<LocalFSStore> store, Path profile, StorePath outPath)
{
/* The new generation number should be higher than old the
previous ones. */
@@ -82,7 +82,7 @@ Path createGeneration(ref<LocalFSStore> store, Path profile, Path outPath)
if (gens.size() > 0) {
Generation last = gens.back();
- if (readLink(last.path) == outPath) {
+ if (readLink(last.path) == store->printStorePath(outPath)) {
/* We only create a new generation symlink if it differs
from the last one.
@@ -105,7 +105,7 @@ Path createGeneration(ref<LocalFSStore> store, Path profile, Path outPath)
user environment etc. we've just built. */
Path generation;
makeName(profile, num + 1, generation);
- store->addPermRoot(store->parseStorePath(outPath), generation, false, true);
+ store->addPermRoot(outPath, generation);
return generation;
}
diff --git a/src/libstore/profiles.hh b/src/libstore/profiles.hh
index abe507f0e..be55a65d4 100644
--- a/src/libstore/profiles.hh
+++ b/src/libstore/profiles.hh
@@ -8,6 +8,8 @@
namespace nix {
+class StorePath;
+
typedef unsigned int GenerationNumber;
@@ -28,7 +30,7 @@ std::pair<Generations, std::optional<GenerationNumber>> findGenerations(Path pro
class LocalFSStore;
-Path createGeneration(ref<LocalFSStore> store, Path profile, Path outPath);
+Path createGeneration(ref<LocalFSStore> store, Path profile, StorePath outPath);
void deleteGeneration(const Path & profile, GenerationNumber gen);
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 6583413a6..8b42aa6d2 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -651,8 +651,7 @@ public:
ref<FSAccessor> getFSAccessor() override;
/* Register a permanent GC root. */
- Path addPermRoot(const StorePath & storePath,
- const Path & gcRoot, bool indirect, bool allowOutsideRootsDir = false);
+ Path addPermRoot(const StorePath & storePath, const Path & gcRoot);
virtual Path getRealStoreDir() { return storeDir; }
diff --git a/src/nix-build/nix-build.cc b/src/nix-build/nix-build.cc
index ea4b407e7..e6fd7a4e6 100755
--- a/src/nix-build/nix-build.cc
+++ b/src/nix-build/nix-build.cc
@@ -526,7 +526,7 @@ static void _main(int argc, char * * argv)
if (auto store2 = store.dynamic_pointer_cast<LocalFSStore>()) {
std::string symlink = drvPrefix;
if (outputName != "out") symlink += "-" + outputName;
- store2->addPermRoot(outputPath, absPath(symlink), true);
+ store2->addPermRoot(outputPath, absPath(symlink));
}
outPaths.push_back(outputPath);
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc
index ddd036070..e5a433ac0 100644
--- a/src/nix-env/nix-env.cc
+++ b/src/nix-env/nix-env.cc
@@ -708,7 +708,9 @@ static void opSet(Globals & globals, Strings opFlags, Strings opArgs)
}
debug(format("switching to new user environment"));
- Path generation = createGeneration(ref<LocalFSStore>(store2), globals.profile, drv.queryOutPath());
+ Path generation = createGeneration(
+ ref<LocalFSStore>(store2), globals.profile,
+ store2->parseStorePath(drv.queryOutPath()));
switchLink(globals.profile, generation);
}
diff --git a/src/nix-env/user-env.cc b/src/nix-env/user-env.cc
index 8e7f09e12..8c6c8af05 100644
--- a/src/nix-env/user-env.cc
+++ b/src/nix-env/user-env.cc
@@ -151,7 +151,8 @@ bool createUserEnv(EvalState & state, DrvInfos & elems,
}
debug(format("switching to new user environment"));
- Path generation = createGeneration(ref<LocalFSStore>(store2), profile, topLevelOut);
+ Path generation = createGeneration(ref<LocalFSStore>(store2), profile,
+ store2->parseStorePath(topLevelOut));
switchLink(profile, generation);
}
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc
index bf353677a..539092cbe 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -20,7 +20,6 @@ using namespace nix;
static Path gcRoot;
static int rootNr = 0;
-static bool indirectRoot = false;
enum OutputKind { okPlain, okXML, okJSON };
@@ -71,11 +70,11 @@ void processExpr(EvalState & state, const Strings & attrPaths,
if (gcRoot == "")
printGCWarning();
else {
- Path rootName = indirectRoot ? absPath(gcRoot) : gcRoot;
+ Path rootName = absPath(gcRoot);
if (++rootNr > 1) rootName += "-" + std::to_string(rootNr);
auto store2 = state.store.dynamic_pointer_cast<LocalFSStore>();
if (store2)
- drvPath = store2->addPermRoot(store2->parseStorePath(drvPath), rootName, indirectRoot);
+ drvPath = store2->addPermRoot(store2->parseStorePath(drvPath), rootName);
}
std::cout << fmt("%s%s\n", drvPath, (outputName != "out" ? "!" + outputName : ""));
}
@@ -127,7 +126,7 @@ static int _main(int argc, char * * argv)
else if (*arg == "--add-root")
gcRoot = getArg(*arg, arg, end);
else if (*arg == "--indirect")
- indirectRoot = true;
+ ;
else if (*arg == "--xml")
outputKind = okXML;
else if (*arg == "--json")
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index ce5de2ae5..b027e84b7 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -34,7 +34,6 @@ typedef void (* Operation) (Strings opFlags, Strings opArgs);
static Path gcRoot;
static int rootNr = 0;
-static bool indirectRoot = false;
static bool noOutput = false;
static std::shared_ptr<Store> store;
@@ -87,7 +86,7 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true)
Path rootName = gcRoot;
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
if (i->first != "out") rootName += "-" + i->first;
- retPath = store2->addPermRoot(outPath, rootName, indirectRoot);
+ retPath = store2->addPermRoot(outPath, rootName);
}
}
outputs.insert(retPath);
@@ -106,7 +105,7 @@ static PathSet realisePath(StorePathWithOutputs path, bool build = true)
Path rootName = gcRoot;
rootNr++;
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
- return {store2->addPermRoot(path.path, rootName, indirectRoot)};
+ return {store2->addPermRoot(path.path, rootName)};
}
}
return {store->printStorePath(path.path)};
@@ -1090,7 +1089,7 @@ static int _main(int argc, char * * argv)
else if (*arg == "--add-root")
gcRoot = absPath(getArg(*arg, arg, end));
else if (*arg == "--indirect")
- indirectRoot = true;
+ ;
else if (*arg == "--no-output")
noOutput = true;
else if (*arg != "" && arg->at(0) == '-') {
diff --git a/src/nix/build.cc b/src/nix/build.cc
index cb12ee933..4605eb13e 100644
--- a/src/nix/build.cc
+++ b/src/nix/build.cc
@@ -71,7 +71,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
[&](BuildableOpaque bo) {
std::string symlink = outLink;
if (i) symlink += fmt("-%d", i);
- store2->addPermRoot(bo.path, absPath(symlink), true);
+ store2->addPermRoot(bo.path, absPath(symlink));
},
[&](BuildableFromDrv bfd) {
auto builtOutputs = store->queryDerivationOutputMap(bfd.drvPath);
@@ -79,7 +79,7 @@ struct CmdBuild : InstallablesCommand, MixDryRun, MixProfile
std::string symlink = outLink;
if (i) symlink += fmt("-%d", i);
if (output.first != "out") symlink += fmt("-%s", output.first);
- store2->addPermRoot(output.second, absPath(symlink), true);
+ store2->addPermRoot(output.second, absPath(symlink));
}
},
}, buildables[i]);
diff --git a/src/nix/bundle.cc b/src/nix/bundle.cc
index eb3339f5d..241c8699b 100644
--- a/src/nix/bundle.cc
+++ b/src/nix/bundle.cc
@@ -122,7 +122,7 @@ struct CmdBundle : InstallableCommand
if (!outLink)
outLink = baseNameOf(app.program);
- store.dynamic_pointer_cast<LocalFSStore>()->addPermRoot(outPath, absPath(*outLink), true);
+ store.dynamic_pointer_cast<LocalFSStore>()->addPermRoot(outPath, absPath(*outLink));
}
};
diff --git a/src/nix/command.cc b/src/nix/command.cc
index fefd72f45..f697eb84c 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -134,7 +134,7 @@ void MixProfile::updateProfile(const StorePath & storePath)
switchLink(profile2,
createGeneration(
ref<LocalFSStore>(store),
- profile2, store->printStorePath(storePath)));
+ profile2, storePath));
}
void MixProfile::updateProfile(const Buildables & buildables)