diff --git a/src/libfetchers/fetchers.cc b/src/libfetchers/fetchers.cc index 8e7999157..e3232ce1d 100644 --- a/src/libfetchers/fetchers.cc +++ b/src/libfetchers/fetchers.cc @@ -24,12 +24,8 @@ static void fixupInput(Input & input) // Check common attributes. input.getType(); input.getRef(); - if (input.getRev()) - input.locked = true; input.getRevCount(); input.getLastModified(); - if (input.getNarHash()) - input.locked = true; } Input Input::fromURL(const ParsedURL & url) @@ -94,6 +90,11 @@ bool Input::isDirect() const return !scheme || scheme->isDirect(*this); } +bool Input::isLocked() const +{ + return scheme && scheme->isLocked(*this); +} + std::optional Input::isRelative() const { assert(scheme); @@ -172,8 +173,6 @@ void Input::checkLocks(Input & input) const // FIXME #if 0 - input.locked = true; - assert(input.hasAllInfo()); #endif } diff --git a/src/libfetchers/fetchers.hh b/src/libfetchers/fetchers.hh index bb7fa04e6..85214af12 100644 --- a/src/libfetchers/fetchers.hh +++ b/src/libfetchers/fetchers.hh @@ -27,7 +27,6 @@ struct Input std::shared_ptr scheme; // note: can be null Attrs attrs; - bool locked = false; public: static Input fromURL(const std::string & url); @@ -50,7 +49,7 @@ public: /* Check whether this is a "locked" input, that is, one that contains a commit hash or content hash. */ - bool isLocked() const { return locked; } + bool isLocked() const; /* Only for relative path flakes, i.e. 'path:./foo', returns the relative path, i.e. './foo'. */ @@ -140,6 +139,9 @@ struct InputScheme virtual bool isDirect(const Input & input) const { return true; } + virtual bool isLocked(const Input & input) const + { return false; } + virtual std::optional isRelative(const Input & input) const { return std::nullopt; } diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index a072a6cd0..697e87f28 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -482,7 +482,6 @@ struct GitInputScheme : InputScheme //input.attrs.erase("narHash"); auto narHash = store->queryPathInfo(storePath)->narHash; input.attrs.insert_or_assign("narHash", narHash.to_string(SRI, true)); - input.locked = true; return storePath; }; @@ -732,8 +731,6 @@ struct GitInputScheme : InputScheme input.attrs.insert_or_assign( "revCount", getRevCount(repoInfo, repoInfo.url, *input.getRev())); - - input.locked = true; } // FIXME: maybe we should use the timestamp of the last @@ -744,6 +741,11 @@ struct GitInputScheme : InputScheme return {makeFSInputAccessor(CanonPath(repoInfo.url), listFiles(repoInfo), std::move(makeNotAllowedError)), input}; } + + bool isLocked(const Input & input) const override + { + return (bool) input.getRev(); + } }; static auto rGitInputScheme = OnStartup([] { registerInputScheme(std::make_unique()); }); diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index d101de433..9f61c0331 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -194,8 +194,6 @@ struct GitArchiveInputScheme : InputScheme auto rev = input.getRev(); if (!rev) rev = getRevFromRef(store, input); - input.locked = true; - input.attrs.erase("ref"); input.attrs.insert_or_assign("rev", rev->gitRev()); @@ -240,6 +238,11 @@ struct GitArchiveInputScheme : InputScheme return {accessor, input2}; } + + bool isLocked(const Input & input) const override + { + return (bool) input.getRev(); + } }; struct GitHubInputScheme : GitArchiveInputScheme diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 416be7412..7139abdcb 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -229,7 +229,6 @@ struct MercurialInputScheme : InputScheme assert(input.getRev()); assert(!origRev || origRev == input.getRev()); input.attrs.insert_or_assign("revCount", getIntAttr(infoAttrs, "revCount")); - input.locked = true; return storePath; }; @@ -336,6 +335,11 @@ struct MercurialInputScheme : InputScheme return {makeStorePathAccessor(store, storePath), input}; } + + bool isLocked(const Input & input) const override + { + return (bool) input.getRev(); + } }; static auto rMercurialInputScheme = OnStartup([] { registerInputScheme(std::make_unique()); }); diff --git a/src/libfetchers/path.cc b/src/libfetchers/path.cc index 1acac82a6..831e15a77 100644 --- a/src/libfetchers/path.cc +++ b/src/libfetchers/path.cc @@ -43,7 +43,10 @@ struct PathInputScheme : InputScheme /* Allow the user to pass in "fake" tree info attributes. This is useful for making a pinned tree work the same as the repository from which is exported - (e.g. path:/nix/store/...-source?lastModified=1585388205&rev=b0c285...). */ + (e.g. path:/nix/store/...-source?lastModified=1585388205&rev=b0c285...). + FIXME: remove this hack once we have a prepopulated + flake input cache mechanism. + */ if (name == "type" || name == "rev" || name == "revCount" || name == "lastModified" || name == "narHash" || name == "path") // checked in Input::fromAttrs ; @@ -76,6 +79,11 @@ struct PathInputScheme : InputScheme return CanonPath(path); } + bool isLocked(const Input & input) const override + { + return (bool) input.getNarHash(); + } + bool hasAllInfo(const Input & input) const override { return true; diff --git a/src/libfetchers/tarball.cc b/src/libfetchers/tarball.cc index cb4772547..010d71dba 100644 --- a/src/libfetchers/tarball.cc +++ b/src/libfetchers/tarball.cc @@ -237,6 +237,10 @@ struct CurlInputScheme : InputScheme return true; } + bool isLocked(const Input & input) const override + { + return (bool) input.getNarHash(); + } }; struct FileInputScheme : CurlInputScheme @@ -261,7 +265,6 @@ struct FileInputScheme : CurlInputScheme // FIXME: remove? auto narHash = store->queryPathInfo(file.storePath)->narHash; input.attrs.insert_or_assign("narHash", narHash.to_string(SRI, true)); - input.locked = true; return {makeStorePathAccessor(store, file.storePath), input}; } @@ -290,7 +293,6 @@ struct TarballInputScheme : CurlInputScheme // FIXME: remove? auto narHash = store->queryPathInfo(storePath)->narHash; input.attrs.insert_or_assign("narHash", narHash.to_string(SRI, true)); - input.locked = true; return {makeStorePathAccessor(store, storePath), input}; }