mirror of
https://github.com/NixOS/nix
synced 2025-06-30 03:23:16 +02:00
Backward compatibility hack for dealing with dir
in URL-style flakerefs
This commit is contained in:
parent
1e822bd414
commit
d00682beb2
5 changed files with 117 additions and 1 deletions
|
@ -595,7 +595,7 @@ LockedFlake lockFlake(
|
|||
oldLock = *oldLock3;
|
||||
|
||||
if (oldLock
|
||||
&& oldLock->originalRef == *input.ref
|
||||
&& oldLock->originalRef.canonicalize() == input.ref->canonicalize()
|
||||
&& oldLock->parentInputAttrPath == overridenParentPath
|
||||
&& !hasCliOverride)
|
||||
{
|
||||
|
|
|
@ -289,6 +289,55 @@ std::pair<ref<SourceAccessor>, FlakeRef> FlakeRef::lazyFetch(ref<Store> store) c
|
|||
return {accessor, FlakeRef(std::move(lockedInput), subdir)};
|
||||
}
|
||||
|
||||
FlakeRef FlakeRef::canonicalize() const
|
||||
{
|
||||
auto flakeRef(*this);
|
||||
|
||||
/* Backward compatibility hack: In old versions of Nix, if you had
|
||||
a flake input like
|
||||
|
||||
inputs.foo.url = "git+https://foo/bar?dir=subdir";
|
||||
|
||||
it would result in a lock file entry like
|
||||
|
||||
"original": {
|
||||
"dir": "subdir",
|
||||
"type": "git",
|
||||
"url": "https://foo/bar?dir=subdir"
|
||||
}
|
||||
|
||||
New versions of Nix remove `?dir=subdir` from the `url` field,
|
||||
since the subdirectory is intended for `FlakeRef`, not the
|
||||
fetcher (and specifically the remote server), that is, the
|
||||
flakeref is parsed into
|
||||
|
||||
"original": {
|
||||
"dir": "subdir",
|
||||
"type": "git",
|
||||
"url": "https://foo/bar"
|
||||
}
|
||||
|
||||
However, this causes new versions of Nix to consider the lock
|
||||
file entry to be stale since the `original` ref no longer
|
||||
matches exactly.
|
||||
|
||||
For this reason, we canonicalise the `original` ref by
|
||||
filtering the `dir` query parameter from the URL. */
|
||||
if (auto url = fetchers::maybeGetStrAttr(flakeRef.input.attrs, "url")) {
|
||||
try {
|
||||
auto parsed = parseURL(*url);
|
||||
if (auto dir2 = get(parsed.query, "dir")) {
|
||||
if (flakeRef.subdir != "" && flakeRef.subdir == *dir2)
|
||||
parsed.query.erase("dir");
|
||||
}
|
||||
flakeRef.input.attrs.insert_or_assign("url", parsed.to_string());
|
||||
} catch (BadURL &) {
|
||||
}
|
||||
}
|
||||
|
||||
return flakeRef;
|
||||
}
|
||||
|
||||
std::tuple<FlakeRef, std::string, ExtendedOutputsSpec> parseFlakeRefWithFragmentAndExtendedOutputsSpec(
|
||||
const fetchers::Settings & fetchSettings,
|
||||
const std::string & url,
|
||||
|
|
|
@ -72,6 +72,12 @@ struct FlakeRef
|
|||
const fetchers::Attrs & attrs);
|
||||
|
||||
std::pair<ref<SourceAccessor>, FlakeRef> lazyFetch(ref<Store> store) const;
|
||||
|
||||
/**
|
||||
* Canonicalize a flakeref for the purpose of comparing "old" and
|
||||
* "new" `original` fields in lock files.
|
||||
*/
|
||||
FlakeRef canonicalize() const;
|
||||
};
|
||||
|
||||
std::ostream & operator << (std::ostream & str, const FlakeRef & flakeRef);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue