1
0
Fork 0
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:
Eelco Dolstra 2023-01-12 16:16:30 +01:00
parent 20a0a74f49
commit fa5af1e583
2 changed files with 34 additions and 13 deletions

View file

@ -424,17 +424,24 @@ LockedFlake lockFlake(
? std::optional<InputPath>(hasOverride ? std::get<2>(i->second) : inputPathPrefix)
: 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:./...'
flakerefs relative to the parent flake. */
auto getInputFlake = [&]()
{
if (auto relativePath = input.ref->input.isRelative()) {
SourcePath inputSourcePath {
overridenSourcePath.accessor,
CanonPath(*relativePath, *overridenSourcePath.path.parent())
};
return readFlake(state, *input.ref, *input.ref, *input.ref, inputSourcePath, inputPath);
} else
if (auto resolvedPath = resolveRelativePath())
return readFlake(state, *input.ref, *input.ref, *input.ref, *resolvedPath, inputPath);
else
return getFlake(state, *input.ref, useRegistries, inputPath);
};
@ -575,13 +582,21 @@ LockedFlake lockFlake(
}
else {
auto [path, lockedRef] = [&]() -> std::tuple<SourcePath, FlakeRef>
{
// 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);
nodePaths.emplace(childNode, accessor->root());
nodePaths.emplace(childNode, path);
node->inputs.insert_or_assign(id, childNode);
}

View file

@ -124,15 +124,21 @@ cat > $flakeFollowsA/flake.nix <<EOF
description = "Flake A";
inputs = {
B.url = "path:../flakeB";
E.flake = false;
E.url = "path:./foo.nix";
};
outputs = { ... }: {};
outputs = { E, ... }: { e = import E; };
}
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 eval --json $flakeFollowsA#e) = 123 ]]
# Non-existant follows should print a warning.
cat >$flakeFollowsA/flake.nix <<EOF
{