1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-13 14:02:42 +01:00

Merge remote-tracking branch 'origin/detsys-main' into flakehub-inputs

This commit is contained in:
Luc Perkins 2025-06-07 10:12:17 -07:00
commit 6898f04a32
No known key found for this signature in database
GPG key ID: C86EE5D85EE4DDA5
3 changed files with 77 additions and 1 deletions

View file

@ -5,6 +5,7 @@
#include "nix/util/json-utils.hh" #include "nix/util/json-utils.hh"
#include "nix/fetchers/store-path-accessor.hh" #include "nix/fetchers/store-path-accessor.hh"
#include "nix/fetchers/fetch-settings.hh" #include "nix/fetchers/fetch-settings.hh"
#include "nix/util/forwarding-source-accessor.hh"
#include <nlohmann/json.hpp> #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 std::pair<ref<SourceAccessor>, Input> Input::getAccessorUnchecked(ref<Store> store) const
{ {
// FIXME: cache the accessor // 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'", debug("using substituted/cached input '%s' in '%s'",
to_string(), store->printStorePath(storePath)); to_string(), store->printStorePath(storePath));
auto accessor = makeStorePathAccessor(store, storePath); auto accessor = make_ref<SubstitutedSourceAccessor>(makeStorePathAccessor(store, storePath));
accessor->fingerprint = getFingerprint(store); accessor->fingerprint = getFingerprint(store);
// FIXME: ideally we would use the `showPath()` of the
// "real" accessor for this fetcher type.
accessor->setPathDisplay("«" + to_string() + "»"); accessor->setPathDisplay("«" + to_string() + "»");
return {accessor, *this}; return {accessor, *this};

View file

@ -0,0 +1,57 @@
#pragma once
#include "source-accessor.hh"
namespace nix {
/**
* A source accessor that just forwards every operation to another
* accessor. This is not useful in itself but can be used as a
* superclass for accessors that do change some operations.
*/
struct ForwardingSourceAccessor : SourceAccessor
{
ref<SourceAccessor> next;
ForwardingSourceAccessor(ref<SourceAccessor> next)
: next(next)
{
}
std::string readFile(const CanonPath & path) override
{
return next->readFile(path);
}
void readFile(const CanonPath & path, Sink & sink, std::function<void(uint64_t)> sizeCallback) override
{
next->readFile(path, sink, sizeCallback);
}
std::optional<Stat> maybeLstat(const CanonPath & path) override
{
return next->maybeLstat(path);
}
DirEntries readDirectory(const CanonPath & path) override
{
return next->readDirectory(path);
}
std::string readLink(const CanonPath & path) override
{
return next->readLink(path);
}
std::string showPath(const CanonPath & path) override
{
return next->showPath(path);
}
std::optional<std::filesystem::path> getPhysicalPath(const CanonPath & path) override
{
return next->getPhysicalPath(path);
}
};
}

View file

@ -34,6 +34,7 @@ headers = files(
'file-system.hh', 'file-system.hh',
'finally.hh', 'finally.hh',
'fmt.hh', 'fmt.hh',
'forwarding-source-accessor.hh',
'fs-sink.hh', 'fs-sink.hh',
'git.hh', 'git.hh',
'hash.hh', 'hash.hh',