mirror of
https://github.com/NixOS/nix
synced 2025-06-29 06:21:14 +02:00
Fix support for relative non-flake inputs (path:./bla)
This commit is contained in:
parent
20a0a74f49
commit
fa5af1e583
2 changed files with 34 additions and 13 deletions
|
@ -424,17 +424,24 @@ LockedFlake lockFlake(
|
||||||
? std::optional<InputPath>(hasOverride ? std::get<2>(i->second) : inputPathPrefix)
|
? std::optional<InputPath>(hasOverride ? std::get<2>(i->second) : inputPathPrefix)
|
||||||
: std::nullopt;
|
: std::nullopt;
|
||||||
|
|
||||||
|
auto resolveRelativePath = [&]() -> std::optional<SourcePath>
|
||||||
|
{
|
||||||
|
if (auto relativePath = input.ref->input.isRelative()) {
|
||||||
|
return SourcePath {
|
||||||
|
overridenSourcePath.accessor,
|
||||||
|
CanonPath(*relativePath, *overridenSourcePath.path.parent())
|
||||||
|
};
|
||||||
|
} else
|
||||||
|
return std::nullopt;
|
||||||
|
};
|
||||||
|
|
||||||
/* Get the input flake, resolve 'path:./...'
|
/* Get the input flake, resolve 'path:./...'
|
||||||
flakerefs relative to the parent flake. */
|
flakerefs relative to the parent flake. */
|
||||||
auto getInputFlake = [&]()
|
auto getInputFlake = [&]()
|
||||||
{
|
{
|
||||||
if (auto relativePath = input.ref->input.isRelative()) {
|
if (auto resolvedPath = resolveRelativePath())
|
||||||
SourcePath inputSourcePath {
|
return readFlake(state, *input.ref, *input.ref, *input.ref, *resolvedPath, inputPath);
|
||||||
overridenSourcePath.accessor,
|
else
|
||||||
CanonPath(*relativePath, *overridenSourcePath.path.parent())
|
|
||||||
};
|
|
||||||
return readFlake(state, *input.ref, *input.ref, *input.ref, inputSourcePath, inputPath);
|
|
||||||
} else
|
|
||||||
return getFlake(state, *input.ref, useRegistries, inputPath);
|
return getFlake(state, *input.ref, useRegistries, inputPath);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -575,13 +582,21 @@ LockedFlake lockFlake(
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
auto resolvedRef = maybeResolve(state, *input.ref, useRegistries);
|
auto [path, lockedRef] = [&]() -> std::tuple<SourcePath, FlakeRef>
|
||||||
|
{
|
||||||
auto [accessor, lockedRef] = resolvedRef.lazyFetch(state.store);
|
// Handle non-flake 'path:./...' inputs.
|
||||||
|
if (auto resolvedPath = resolveRelativePath()) {
|
||||||
|
return {*resolvedPath, *input.ref};
|
||||||
|
} else {
|
||||||
|
auto resolvedRef = maybeResolve(state, *input.ref, useRegistries);
|
||||||
|
auto [accessor, lockedRef] = resolvedRef.lazyFetch(state.store);
|
||||||
|
return {accessor->root(), lockedRef};
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
auto childNode = make_ref<LockedNode>(lockedRef, ref, false, overridenParentPath);
|
auto childNode = make_ref<LockedNode>(lockedRef, ref, false, overridenParentPath);
|
||||||
|
|
||||||
nodePaths.emplace(childNode, accessor->root());
|
nodePaths.emplace(childNode, path);
|
||||||
|
|
||||||
node->inputs.insert_or_assign(id, childNode);
|
node->inputs.insert_or_assign(id, childNode);
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,15 +124,21 @@ cat > $flakeFollowsA/flake.nix <<EOF
|
||||||
description = "Flake A";
|
description = "Flake A";
|
||||||
inputs = {
|
inputs = {
|
||||||
B.url = "path:../flakeB";
|
B.url = "path:../flakeB";
|
||||||
|
E.flake = false;
|
||||||
|
E.url = "path:./foo.nix";
|
||||||
};
|
};
|
||||||
outputs = { ... }: {};
|
outputs = { E, ... }: { e = import E; };
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
git -C $flakeFollowsA add flake.nix
|
echo 123 > $flakeFollowsA/foo.nix
|
||||||
|
|
||||||
|
git -C $flakeFollowsA add flake.nix foo.nix
|
||||||
|
|
||||||
nix flake lock $flakeFollowsA
|
nix flake lock $flakeFollowsA
|
||||||
|
|
||||||
|
[[ $(nix eval --json $flakeFollowsA#e) = 123 ]]
|
||||||
|
|
||||||
# Non-existant follows should print a warning.
|
# Non-existant follows should print a warning.
|
||||||
cat >$flakeFollowsA/flake.nix <<EOF
|
cat >$flakeFollowsA/flake.nix <<EOF
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue