mirror of
https://github.com/NixOS/nix.git
synced 2025-11-30 06:01:00 +01:00
Make rootFS's showPath() render the paths from the original accessors
This makes paths in error messages behave similar to lazy-trees,
e.g. instead of store paths like
error: attribute 'foobar' missing
at /nix/store/ddzfiipzqlrh3gnprmqbadnsnrxsmc9i-source/machine/configuration.nix:209:7:
208|
209| pkgs.foobar
| ^
210| ];
you now get
error: attribute 'foobar' missing
at /home/eelco/Misc/eelco-configurations/machine/configuration.nix:209:7:
208|
209| pkgs.foobar
| ^
210| ];
This commit is contained in:
parent
5506428e67
commit
b28bc7ae64
10 changed files with 122 additions and 22 deletions
|
|
@ -14,6 +14,7 @@
|
|||
#include "profiles.hh"
|
||||
#include "print.hh"
|
||||
#include "filtering-source-accessor.hh"
|
||||
#include "forwarding-source-accessor.hh"
|
||||
#include "memory-source-accessor.hh"
|
||||
#include "gc-small-vector.hh"
|
||||
#include "url.hh"
|
||||
|
|
@ -180,6 +181,34 @@ static Symbol getName(const AttrName & name, EvalState & state, Env & env)
|
|||
}
|
||||
}
|
||||
|
||||
struct PathDisplaySourceAccessor : ForwardingSourceAccessor
|
||||
{
|
||||
ref<EvalState::StorePathAccessors> storePathAccessors;
|
||||
|
||||
PathDisplaySourceAccessor(
|
||||
ref<SourceAccessor> next,
|
||||
ref<EvalState::StorePathAccessors> storePathAccessors)
|
||||
: ForwardingSourceAccessor(next)
|
||||
, storePathAccessors(storePathAccessors)
|
||||
{
|
||||
}
|
||||
|
||||
std::string showPath(const CanonPath & path) override
|
||||
{
|
||||
/* Find the accessor that produced `path`, if any, and use it
|
||||
to render a more informative path
|
||||
(e.g. `«github:foo/bar»/flake.nix` rather than
|
||||
`/nix/store/hash.../flake.nix`). */
|
||||
auto ub = storePathAccessors->upper_bound(path);
|
||||
if (ub != storePathAccessors->begin())
|
||||
ub--;
|
||||
if (ub != storePathAccessors->end() && path.isWithin(ub->first))
|
||||
return ub->second->showPath(path.removePrefix(ub->first));
|
||||
else
|
||||
return next->showPath(path);
|
||||
}
|
||||
};
|
||||
|
||||
static constexpr size_t BASE_ENV_SIZE = 128;
|
||||
|
||||
EvalState::EvalState(
|
||||
|
|
@ -245,6 +274,7 @@ EvalState::EvalState(
|
|||
}
|
||||
, repair(NoRepair)
|
||||
, emptyBindings(0)
|
||||
, storePathAccessors(make_ref<StorePathAccessors>())
|
||||
, rootFS(
|
||||
({
|
||||
/* In pure eval mode, we provide a filesystem that only
|
||||
|
|
@ -270,6 +300,8 @@ EvalState::EvalState(
|
|||
: makeUnionSourceAccessor({accessor, storeFS});
|
||||
}
|
||||
|
||||
accessor = make_ref<PathDisplaySourceAccessor>(accessor, storePathAccessors);
|
||||
|
||||
/* Apply access control if needed. */
|
||||
if (settings.restrictEval || settings.pureEval)
|
||||
accessor = AllowListSourceAccessor::create(accessor, {},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue