1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-12-10 11:01:03 +01:00

Add position info to path values

(Actually, this adds a position field to *all* values.)

This allows improving the "inefficient double copy" warning by showing
where the source path came from in the source, e.g.

  warning: Performing inefficient double copy of path '/home/eelco/Dev/patchelf/' to the store at /home/eelco/Dev/patchelf/flake.nix:30:17. This can typically be avoided by rewriting an attribute like `src = ./.` to `src = builtins.path { path = ./.; name = "source"; }`.
This commit is contained in:
Eelco Dolstra 2025-05-30 17:31:34 +02:00
parent 8ff43c29ef
commit 3e45b40d66
9 changed files with 33 additions and 20 deletions

View file

@ -149,6 +149,8 @@ PosIdx Value::determinePos(const PosIdx pos) const
// Allow selecting a subset of enum values
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-enum"
if (this->pos != 0)
return PosIdx(this->pos);
switch (internalType) {
case tAttrs: return attrs()->pos;
case tLambda: return payload.lambda.fun->pos;
@ -906,7 +908,7 @@ void Value::mkStringMove(const char * s, const NixStringContext & context)
void Value::mkPath(const SourcePath & path)
{
mkPath(&*path.accessor, makeImmutableString(path.path.abs()));
mkPath(&*path.accessor, makeImmutableString(path.path.abs()), noPos.get());
}
@ -2356,7 +2358,7 @@ BackedStringView EvalState::coerceToString(
// slash, as in /foo/${x}.
v.payload.path.path
: copyToStore
? store->printStorePath(copyPathToStore(context, v.path()))
? store->printStorePath(copyPathToStore(context, v.path(), v.determinePos(pos)))
: ({
auto path = v.path();
if (path.accessor == rootFS && store->isInStore(path.path.abs())) {
@ -2434,7 +2436,7 @@ BackedStringView EvalState::coerceToString(
}
StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePath & path)
StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePath & path, PosIdx pos)
{
if (nix::isDerivation(path.path.abs()))
error<EvalError>("file names are not allowed to end in '%1%'", drvExtension).debugThrow();
@ -2448,7 +2450,7 @@ StorePath EvalState::copyPathToStore(NixStringContext & context, const SourcePat
*store,
path.resolveSymlinks(SymlinkResolution::Ancestors),
settings.readOnlyMode ? FetchMode::DryRun : FetchMode::Copy,
computeBaseName(path),
computeBaseName(path, pos),
ContentAddressMethod::Raw::NixArchive,
nullptr,
repair);