1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-18 16:29:36 +01:00

Fix display of paths in substituted source trees

These got displayed as e.g.

  «github:NixOS/nixpkgs/adaa24fbf46737f3f1b5497bf64bae750f82942e?narHash=sha256-qhFMmDkeJX9KJwr5H32f1r7Prs7XbQWtO0h3V0a0rFY%3D»/nix/store/x9wnkly3k1gkq580m90jjn32q9f05q2v-source/pkgs/stdenv/generic/source-stdenv.sh

Now we get

  «github:NixOS/nixpkgs/adaa24fbf46737f3f1b5497bf64bae750f82942e?narHash=sha256-qhFMmDkeJX9KJwr5H32f1r7Prs7XbQWtO0h3V0a0rFY%3D»/pkgs/stdenv/generic/source-stdenv.sh
This commit is contained in:
Eelco Dolstra 2025-06-06 19:41:12 +02:00
parent a69b99ade0
commit e18b1637dc

View file

@ -5,6 +5,7 @@
#include "nix/util/json-utils.hh"
#include "nix/fetchers/store-path-accessor.hh"
#include "nix/fetchers/fetch-settings.hh"
#include "nix/util/forwarding-source-accessor.hh"
#include <nlohmann/json.hpp>
@ -293,6 +294,21 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessor(ref<Store> store) const
}
}
/**
* Helper class that ensures that paths in substituted source trees
* are rendered as `«input»/path` rather than
* `«input»/nix/store/<hash>-source/path`.
*/
struct SubstitutedSourceAccessor : ForwardingSourceAccessor
{
using ForwardingSourceAccessor::ForwardingSourceAccessor;
std::string showPath(const CanonPath & path) override
{
return displayPrefix + path.abs() + displaySuffix;;
}
};
std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> store) const
{
// FIXME: cache the accessor
@ -320,10 +336,12 @@ std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> sto
debug("using substituted/cached input '%s' in '%s'",
to_string(), store->printStorePath(storePath));
auto accessor = makeStorePathAccessor(store, storePath);
auto accessor = make_ref<SubstitutedSourceAccessor>(makeStorePathAccessor(store, storePath));
accessor->fingerprint = getFingerprint(store);
// FIXME: ideally we would use the `showPath()` of the
// "real" accessor for this fetcher type.
accessor->setPathDisplay("«" + to_string() + "»");
return {accessor, *this};