Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/libfetchers/fetchers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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};
Expand Down
57 changes: 57 additions & 0 deletions src/libutil/include/nix/util/forwarding-source-accessor.hh
Original file line number Diff line number Diff line change
@@ -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);
}
};

}
1 change: 1 addition & 0 deletions src/libutil/include/nix/util/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ headers = files(
'file-system.hh',
'finally.hh',
'fmt.hh',
'forwarding-source-accessor.hh',
'fs-sink.hh',
'git.hh',
'hash.hh',
Expand Down