diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 9f3b58909..6e3fa41f7 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -501,7 +501,7 @@ LockedFlake lockFlake( this input. */ debug("creating new input '%s'", inputPathS); - if (!lockFlags.allowMutable && !input.ref->input.isImmutable()) + if (!lockFlags.allowMutable && !input.ref->input.isLocked()) throw Error("cannot update flake input '%s' in pure mode", inputPathS); if (input.isFlake) { @@ -650,7 +650,7 @@ LockedFlake lockFlake( now. Corner case: we could have reverted from a dirty to a clean tree! */ if (flake.lockedRef.input == prevLockedRef.input - && !flake.lockedRef.input.isImmutable()) + && !flake.lockedRef.input.isLocked()) throw Error("'%s' did not change after I updated its 'flake.lock' file; is 'flake.lock' under version control?", flake.originalRef); } } else @@ -709,8 +709,8 @@ static void prim_getFlake(EvalState & state, const Pos & pos, Value * * args, Va string flakeRefS(state.forceStringNoCtx(*args[0], pos)); auto flakeRef = parseFlakeRef(flakeRefS, {}, true); - if (evalSettings.pureEval && !flakeRef.input.isImmutable()) - throw Error("cannot call 'getFlake' on mutable flake reference '%s', at %s (use --impure to override)", flakeRefS, pos); + if (evalSettings.pureEval && !flakeRef.input.isLocked()) + throw Error("cannot call 'getFlake' on unlocked flake reference '%s', at %s (use --impure to override)", flakeRefS, pos); callFlake(state, lockFlake(state, flakeRef, diff --git a/src/libexpr/flake/lockfile.cc b/src/libexpr/flake/lockfile.cc index fda340789..60b52d578 100644 --- a/src/libexpr/flake/lockfile.cc +++ b/src/libexpr/flake/lockfile.cc @@ -35,7 +35,7 @@ LockedNode::LockedNode(const nlohmann::json & json) , originalRef(getFlakeRef(json, "original", nullptr)) , isFlake(json.find("flake") != json.end() ? (bool) json["flake"] : true) { - if (!lockedRef.input.isImmutable()) + if (!lockedRef.input.isLocked()) throw Error("lockfile contains mutable lock '%s'", fetchers::attrsToJSON(lockedRef.input.toAttrs())); } @@ -220,7 +220,7 @@ bool LockFile::isImmutable() const for (auto & i : nodes) { if (i == root) continue; auto lockedNode = std::dynamic_pointer_cast(i); - if (lockedNode && !lockedNode->lockedRef.input.isImmutable()) return false; + if (lockedNode && !lockedNode->lockedRef.input.isLocked()) return false; } return true; diff --git a/src/libexpr/primops/fetchTree.cc b/src/libexpr/primops/fetchTree.cc index d09e2d9e1..7496104b6 100644 --- a/src/libexpr/primops/fetchTree.cc +++ b/src/libexpr/primops/fetchTree.cc @@ -19,7 +19,7 @@ void emitTreeAttrs( bool emptyRevFallback, bool forceDirty) { - assert(input.isImmutable()); + assert(input.isLocked()); auto attrs = state.buildBindings(8); @@ -166,8 +166,8 @@ static void fetchTree( if (!evalSettings.pureEval && !input.isDirect()) input = lookupInRegistries(state.store, input).first; - if (evalSettings.pureEval && !input.isImmutable()) - throw Error("in pure evaluation mode, 'fetchTree' requires an immutable input, at %s", pos); + if (evalSettings.pureEval && !input.isLocked()) + throw Error("in pure evaluation mode, 'fetchTree' requires a locked input, at %s", pos); auto [tree, input2] = input.fetch(state.store); diff --git a/src/libfetchers/cache.cc b/src/libfetchers/cache.cc index 34ff6f85b..0c8ecac9d 100644 --- a/src/libfetchers/cache.cc +++ b/src/libfetchers/cache.cc @@ -52,13 +52,13 @@ struct CacheImpl : Cache const Attrs & inAttrs, const Attrs & infoAttrs, const StorePath & storePath, - bool immutable) override + bool locked) override { _state.lock()->add.use() (attrsToJSON(inAttrs).dump()) (attrsToJSON(infoAttrs).dump()) (store->printStorePath(storePath)) - (immutable) + (locked) (time(0)).exec(); } @@ -91,7 +91,7 @@ struct CacheImpl : Cache auto infoJSON = stmt.getStr(0); auto storePath = store->parseStorePath(stmt.getStr(1)); - auto immutable = stmt.getInt(2) != 0; + auto locked = stmt.getInt(2) != 0; auto timestamp = stmt.getInt(3); store->addTempRoot(storePath); @@ -105,7 +105,7 @@ struct CacheImpl : Cache inAttrsJSON, infoJSON, store->printStorePath(storePath)); return Result { - .expired = !immutable && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)), + .expired = !locked && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)), .infoAttrs = jsonToAttrs(nlohmann::json::parse(infoJSON)), .storePath = std::move(storePath) }; diff --git a/src/libfetchers/cache.hh b/src/libfetchers/cache.hh index 3db4f081c..3763ee2a6 100644 --- a/src/libfetchers/cache.hh +++ b/src/libfetchers/cache.hh @@ -13,7 +13,7 @@ struct Cache const Attrs & inAttrs, const Attrs & infoAttrs, const StorePath & storePath, - bool immutable) = 0; + bool locked) = 0; virtual std::optional> lookup( ref store, diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index c06ccb929..976f40d3b 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -24,11 +24,11 @@ static void fixupInput(Input & input) input.getType(); input.getRef(); if (input.getRev()) - input.immutable = true; + input.locked = true; input.getRevCount(); input.getLastModified(); if (input.getNarHash()) - input.immutable = true; + input.locked = true; } Input Input::fromURL(const ParsedURL & url) @@ -165,7 +165,7 @@ std::pair Input::fetch(ref store) const input.to_string(), *prevRevCount); } - input.immutable = true; + input.locked = true; assert(input.hasAllInfo()); @@ -209,7 +209,7 @@ StorePath Input::computeStorePath(Store & store) const { auto narHash = getNarHash(); if (!narHash) - throw Error("cannot compute store path for mutable input '%s'", to_string()); + throw Error("cannot compute store path for unlocked input '%s'", to_string()); return store.makeFixedOutputPath(FileIngestionMethod::Recursive, *narHash, getName()); } diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index 2836af5fa..bc9a76b0b 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -34,7 +34,7 @@ struct Input std::shared_ptr scheme; // note: can be null Attrs attrs; - bool immutable = false; + bool locked = false; bool direct = true; /* path of the parent of this input, used for relative path resolution */ @@ -59,9 +59,9 @@ public: one that goes through a registry. */ bool isDirect() const { return direct; } - /* Check whether this is an "immutable" input, that is, + /* Check whether this is a "locked" input, that is, one that contains a commit hash or content hash. */ - bool isImmutable() const { return immutable; } + bool isLocked() const { return locked; } bool hasAllInfo() const; @@ -69,6 +69,8 @@ public: bool contains(const Input & other) const; + /* Fetch the input into the Nix store, returning the location in + the Nix store and the locked input. */ std::pair fetch(ref store) const; Input applyOverrides( @@ -146,14 +148,14 @@ DownloadFileResult downloadFile( ref store, const std::string & url, const std::string & name, - bool immutable, + bool locked, const Headers & headers = {}); std::pair downloadTarball( ref store, const std::string & url, const std::string & name, - bool immutable, + bool locked, const Headers & headers = {}); } diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index c3f0f8c8f..7f65c1533 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -187,7 +187,7 @@ struct GitInputScheme : InputScheme if (submodules) cacheType += "-submodules"; if (allRefs) cacheType += "-all-refs"; - auto getImmutableAttrs = [&]() + auto getLockedAttrs = [&]() { return Attrs({ {"type", cacheType}, @@ -208,7 +208,7 @@ struct GitInputScheme : InputScheme }; if (input.getRev()) { - if (auto res = getCache()->lookup(store, getImmutableAttrs())) + if (auto res = getCache()->lookup(store, getLockedAttrs())) return makeResult(res->first, std::move(res->second)); } @@ -288,7 +288,7 @@ struct GitInputScheme : InputScheme if (!input.getRef()) input.attrs.insert_or_assign("ref", isLocal ? readHead(actualUrl) : "master"); - Attrs mutableAttrs({ + Attrs unlockedAttrs({ {"type", cacheType}, {"name", name}, {"url", actualUrl}, @@ -307,7 +307,7 @@ struct GitInputScheme : InputScheme } else { - if (auto res = getCache()->lookup(store, mutableAttrs)) { + if (auto res = getCache()->lookup(store, unlockedAttrs)) { auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), htSHA1); if (!input.getRev() || input.getRev() == rev2) { input.attrs.insert_or_assign("rev", rev2.gitRev()); @@ -404,7 +404,7 @@ struct GitInputScheme : InputScheme /* Now that we know the ref, check again whether we have it in the store. */ - if (auto res = getCache()->lookup(store, getImmutableAttrs())) + if (auto res = getCache()->lookup(store, getLockedAttrs())) return makeResult(res->first, std::move(res->second)); Path tmpDir = createTempDir(); @@ -476,14 +476,14 @@ struct GitInputScheme : InputScheme if (!_input.getRev()) getCache()->add( store, - mutableAttrs, + unlockedAttrs, infoAttrs, storePath, false); getCache()->add( store, - getImmutableAttrs(), + getLockedAttrs(), infoAttrs, storePath, true); diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 2b3705b1b..70622bf79 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -193,12 +193,12 @@ struct GitArchiveInputScheme : InputScheme input.attrs.erase("ref"); input.attrs.insert_or_assign("rev", rev->gitRev()); - Attrs immutableAttrs({ + Attrs lockedAttrs({ {"type", "git-tarball"}, {"rev", rev->gitRev()}, }); - if (auto res = getCache()->lookup(store, immutableAttrs)) { + if (auto res = getCache()->lookup(store, lockedAttrs)) { input.attrs.insert_or_assign("lastModified", getIntAttr(res->first, "lastModified")); return {std::move(res->second), input}; } @@ -211,7 +211,7 @@ struct GitArchiveInputScheme : InputScheme getCache()->add( store, - immutableAttrs, + lockedAttrs, { {"rev", rev->gitRev()}, {"lastModified", uint64_t(lastModified)} diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 5123bcda4..798369c7a 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -199,7 +199,7 @@ struct MercurialInputScheme : InputScheme if (!input.getRef()) input.attrs.insert_or_assign("ref", "default"); - auto getImmutableAttrs = [&]() + auto getLockedAttrs = [&]() { return Attrs({ {"type", "hg"}, @@ -218,20 +218,20 @@ struct MercurialInputScheme : InputScheme }; if (input.getRev()) { - if (auto res = getCache()->lookup(store, getImmutableAttrs())) + if (auto res = getCache()->lookup(store, getLockedAttrs())) return makeResult(res->first, std::move(res->second)); } auto revOrRef = input.getRev() ? input.getRev()->gitRev() : *input.getRef(); - Attrs mutableAttrs({ + Attrs unlockedAttrs({ {"type", "hg"}, {"name", name}, {"url", actualUrl}, {"ref", *input.getRef()}, }); - if (auto res = getCache()->lookup(store, mutableAttrs)) { + if (auto res = getCache()->lookup(store, unlockedAttrs)) { auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), htSHA1); if (!input.getRev() || input.getRev() == rev2) { input.attrs.insert_or_assign("rev", rev2.gitRev()); @@ -277,7 +277,7 @@ struct MercurialInputScheme : InputScheme auto revCount = std::stoull(tokens[1]); input.attrs.insert_or_assign("ref", tokens[2]); - if (auto res = getCache()->lookup(store, getImmutableAttrs())) + if (auto res = getCache()->lookup(store, getLockedAttrs())) return makeResult(res->first, std::move(res->second)); Path tmpDir = createTempDir(); @@ -297,14 +297,14 @@ struct MercurialInputScheme : InputScheme if (!_input.getRev()) getCache()->add( store, - mutableAttrs, + unlockedAttrs, infoAttrs, storePath, false); getCache()->add( store, - getImmutableAttrs(), + getLockedAttrs(), infoAttrs, storePath, true); diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index 74c8097ff..dde0ad761 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -13,7 +13,7 @@ DownloadFileResult downloadFile( ref store, const std::string & url, const std::string & name, - bool immutable, + bool locked, const Headers & headers) { // FIXME: check store @@ -88,7 +88,7 @@ DownloadFileResult downloadFile( inAttrs, infoAttrs, *storePath, - immutable); + locked); if (url != res.effectiveUri) getCache()->add( @@ -100,7 +100,7 @@ DownloadFileResult downloadFile( }, infoAttrs, *storePath, - immutable); + locked); return { .storePath = std::move(*storePath), @@ -113,7 +113,7 @@ std::pair downloadTarball( ref store, const std::string & url, const std::string & name, - bool immutable, + bool locked, const Headers & headers) { Attrs inAttrs({ @@ -130,7 +130,7 @@ std::pair downloadTarball( getIntAttr(cached->infoAttrs, "lastModified") }; - auto res = downloadFile(store, url, name, immutable, headers); + auto res = downloadFile(store, url, name, locked, headers); std::optional unpackedStorePath; time_t lastModified; @@ -160,7 +160,7 @@ std::pair downloadTarball( inAttrs, infoAttrs, *unpackedStorePath, - immutable); + locked); return { Tree { .actualPath = store->toRealPath(*unpackedStorePath), .storePath = std::move(*unpackedStorePath) }, @@ -202,7 +202,7 @@ struct TarballInputScheme : InputScheme Input input; input.attrs = attrs; - //input.immutable = (bool) maybeGetStrAttr(input.attrs, "hash"); + //input.locked = (bool) maybeGetStrAttr(input.attrs, "hash"); return input; } diff --git a/src/nix/profile.cc b/src/nix/profile.cc index 508cbd336..0e8dc4380 100644 --- a/src/nix/profile.cc +++ b/src/nix/profile.cc @@ -415,7 +415,7 @@ struct CmdProfileUpgrade : virtual SourceExprCommand, MixDefaultProfile, MixProf for (size_t i = 0; i < manifest.elements.size(); ++i) { auto & element(manifest.elements[i]); if (element.source - && !element.source->originalRef.input.isImmutable() + && !element.source->originalRef.input.isLocked() && matches(*store, element, i, matchers)) { upgradedCount++; diff --git a/src/nix/repl.cc b/src/nix/repl.cc index 60454471d..575eb0c4c 100644 --- a/src/nix/repl.cc +++ b/src/nix/repl.cc @@ -627,8 +627,8 @@ void NixRepl::loadFlake(const std::string & flakeRefS) throw Error("cannot use ':load-flake' without a path specified. (Use '.' for the current working directory.)"); auto flakeRef = parseFlakeRef(flakeRefS, absPath("."), true); - if (evalSettings.pureEval && !flakeRef.input.isImmutable()) - throw Error("cannot use ':load-flake' on mutable flake reference '%s' (use --impure to override)", flakeRefS); + if (evalSettings.pureEval && !flakeRef.input.isLocked()) + throw Error("cannot use ':load-flake' on locked flake reference '%s' (use --impure to override)", flakeRefS); Value v;