Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
e146abd
Merge branch 'master' of github.com:NixOS/nix into HEAD
Ericson2314 Jun 25, 2020
263fcdb
Merge remote-tracking branch 'obsidian/path-info' into HEAD
Ericson2314 Jun 25, 2020
a24ebd2
Use `FixedOutputHash` in parameters for `makeFixedOutputPath`
Ericson2314 Jun 24, 2020
69fe58c
Use `PathReferences` in a few more places
Ericson2314 Jun 25, 2020
783e262
CA: Distingish Full vs Mini content addresses
Ericson2314 Jun 25, 2020
c8cd66f
Fix syntax
matthewbauer Jun 26, 2020
bff0743
Add order for FullContentAddress
matthewbauer Jun 26, 2020
1db393f
Fix referencesPossiblyToSelf
matthewbauer Jun 29, 2020
9cd79c5
Merge branch 'path-info' of github.com:obsidiansystems/nix into store…
Ericson2314 Jun 29, 2020
43ba4a8
Merge branch 'path-info' of github.com:obsidiansystems/nix into store…
Ericson2314 Jun 29, 2020
ebba7f3
Fix nar info parsing
Ericson2314 Jun 29, 2020
4f6f771
Merge branch 'path-info' of github.com:obsidiansystems/nix into store…
Ericson2314 Jun 29, 2020
e83f02c
Merge branch 'substitute-other-storedir' of github.com:matthewbauer/n…
Ericson2314 Jun 30, 2020
83f743b
Fix perl bindings
Ericson2314 Jun 30, 2020
5a8e8fa
Use some named designators again with braces for base class
Ericson2314 Jul 1, 2020
7dacd78
Fix more initialization warnings
Ericson2314 Jul 1, 2020
b2e0ec8
Try to avoid include problem in perl
Ericson2314 Jul 1, 2020
c77f6c9
Rename FullContentAddress to ContentAddress
matthewbauer Jul 1, 2020
c7383c7
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Jul 3, 2020
fd40971
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Jul 5, 2020
7271778
See if setting -std=c++17 for PERL helps
Ericson2314 Jul 5, 2020
97234c1
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Jul 6, 2020
ff07296
Rename ContentAddress to StorePathDescriptor
meditans Jul 13, 2020
ade0f1a
Rename functions related to ContentAddress
meditans Jul 14, 2020
08bf6c4
Rename LegacyContentAddress and related functions
meditans Jul 14, 2020
1f6a3c2
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Jul 16, 2020
1d52449
Merge commit 'c3c7aedbb5ac869b7c454e90683f77b9c527a75a' into ipfs-dev…
Ericson2314 Jul 19, 2020
d0eaf2b
Rename ContentAddress to StorePathDescriptor
meditans Jul 13, 2020
1cf131f
Rename functions related to ContentAddress
meditans Jul 14, 2020
74de4c7
Rename LegacyContentAddress and related functions
meditans Jul 14, 2020
db7f05c
Merge branch 'store-path-or-ca-reconcile' of github.com:obsidiansyste…
Ericson2314 Jul 19, 2020
11a4ae4
Merge commit '36a124260361ba8dfa43bf43a067dcc48064c93f' into store-pa…
Ericson2314 Jul 19, 2020
713d574
Merge branch 'store-path-or-ca-reconcile' of github.com:obsidiansyste…
Ericson2314 Jul 19, 2020
f8a1403
Merge commit 'c466cb2091b7a382aba1739c0320f2b6c0a04c1e' into store-pa…
Ericson2314 Jul 21, 2020
ecf65a6
Use StorePathDescriptor more widely
Ericson2314 Jul 21, 2020
f4918ec
Merge branch 'store-path-or-ca' of github.com:obsidiansystems/nix int…
Ericson2314 Jul 21, 2020
c9f83f2
Fix issues with store path descriptor round trip
Ericson2314 Jul 21, 2020
c4b0184
Merge pull request #68 from obsidiansystems/store-path-or-ca-reconcile
Ericson2314 Jul 22, 2020
7decfd0
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Jul 22, 2020
367cba6
Merge remote-tracking branch 'obsidian/better-ca-parse-errors' into s…
Ericson2314 Jul 31, 2020
bf042cc
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Aug 1, 2020
b224c9b
Merge branch 'master' of github.com:NixOS/nix into store-path-or-ca
meditans Aug 4, 2020
8d01e9f
Move back code to minimize diff size
meditans Aug 4, 2020
07f9134
Remove unused imports
meditans Aug 4, 2020
b9cdbe3
Merge remote-tracking branch 'obsidian/drv-outputs-map-allow-missing'…
Ericson2314 Aug 4, 2020
b0ede14
Merge branch 'templated-daemon-protocol' into store-path-or-ca
Ericson2314 Aug 4, 2020
3d17a6b
Merge remote-tracking branch 'obsidian/templated-daemon-protocol' int…
Ericson2314 Aug 5, 2020
74318cc
Merge branch 'templated-daemon-protocol' of github.com:obsidiansystem…
Ericson2314 Aug 7, 2020
535ad25
Fix perl bindings build
Ericson2314 Aug 7, 2020
a1ccec5
Merge branch 'templated-daemon-protocol' of github.com:obsidiansystem…
Ericson2314 Aug 7, 2020
c5e6da3
Merge branch 'templated-daemon-protocol' of github.com:obsidiansystem…
Ericson2314 Aug 19, 2020
fa247e2
Merge remote-tracking branch 'obsidian/templated-daemon-protocol' int…
Ericson2314 Aug 20, 2020
d16d90f
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Aug 27, 2020
f31e1a4
Merge remote-tracking branch 'obsidian/templated-daemon-protocol' int…
Ericson2314 Sep 22, 2020
e04cf6b
Allow `copyPaths` and `queryValidPaths` to work with StorePathDesc
Ericson2314 Sep 9, 2020
956e488
Merge remote-tracking branch 'obsidian/templated-daemon-protocol' int…
Ericson2314 Sep 22, 2020
971bc0e
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Sep 23, 2020
884a049
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Sep 23, 2020
c5e4f51
Merge remote-tracking branch 'upstream/master' into store-path-or-ca
Ericson2314 Oct 5, 2020
fdbaca8
Fix improperly-merged revert from upstream
Ericson2314 Oct 5, 2020
cea07c9
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Oct 6, 2020
6f6b3bb
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Oct 7, 2020
6547357
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Oct 12, 2020
57601f8
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Oct 13, 2020
50eb913
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Oct 13, 2020
aa09e1d
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Oct 15, 2020
26a0c66
Merge remote-tracking branch 'upstream/master' into path-info
Ericson2314 Feb 25, 2021
554f006
Merge remote-tracking branch 'obsidian/path-info' into store-path-or-ca
Ericson2314 Feb 25, 2021
7f50ecf
Merge commit 'f0ad29acc1f2c9e82679c3af434a8bf185f36b94' into store-pa…
Ericson2314 Mar 25, 2022
f1bcb73
Fill in missing comparison operators for content addresses
Ericson2314 Mar 25, 2022
37ab189
Fix bug in `copyPaths`
Ericson2314 Mar 26, 2022
4a55c7b
Remove pointless copy
Ericson2314 Mar 26, 2022
e6ad490
Merge commit 'e12308dd63f0ad27b22dcdb3da89c411eebcad2b' into store-pa…
Ericson2314 Mar 26, 2022
8f0b757
Merge commit 'd5cef6c33a051dfc672cb1e5f4739948b167315b' into store-pa…
Ericson2314 Mar 26, 2022
27ef76a
Merge commit '1b6cf0d5f56e166a1cbbf38142375b7a92fc88f2' into store-pa…
Ericson2314 Mar 27, 2022
8106a67
Merge commit 'f4f3203aa7c2fc9225a8ae220db25593066fb397' into store-pa…
Ericson2314 Mar 27, 2022
4ed2f42
Merge commit '13b6b645897fd2edaa0f09fa48d6fe8dd6287b55' into store-pa…
Ericson2314 Apr 19, 2022
5e87f08
Merge commit '8ba089597fa19bfd49ba5f22a5e821740ca4eb5d' into store-pa…
Ericson2314 Apr 20, 2022
230c771
Merge commit '0dc2974930df57cac6673c02e9bc6eb6fd16ba48' into store-pa…
Ericson2314 Apr 20, 2022
56be25a
Merge commit '2c21cb672043fcf3c3fd19f89618b37693c0dc62' into store-pa…
Ericson2314 Apr 20, 2022
fa1e9ea
Merge commit '13c669105ca93d28ca1a78321f07fd4ddbb445b1' into store-pa…
Ericson2314 Apr 20, 2022
daa760d
Merge branch 'path-info' into store-path-or-ca
Ericson2314 Apr 20, 2022
6601ac8
Revert "Make `ValidPathInfo` have plain `StorePathSet` references lik…
Ericson2314 Jan 14, 2023
b21dd38
Revert "Don't add `StorePathDescriptor` for now"
Ericson2314 Jan 23, 2023
91baf7f
Merge remote-tracking branch 'upstream/master' into store-path-descri…
Ericson2314 Sep 3, 2023
4ed87aa
Merge commit 'e9fc1e4fdb0ab5adb6b163c3db361b86a4f5c69b' into store-pa…
Ericson2314 Sep 3, 2023
50803f2
Merge commit '8623143921f8683b88d46aaebe9f707e5b9a912b' into store-pa…
Ericson2314 Sep 3, 2023
1731340
Merge commit '6a168254ce068c067259c913ee7d6ee2e0d1dc7e' into store-pa…
Ericson2314 Sep 3, 2023
554158c
Merge commit '9cfa78e58a92b4bf034867bc1296a200bdc3f12a' into store-pa…
Ericson2314 Sep 3, 2023
c08971b
Merge commit '46e942ff9e65755689ee72f93846d7118e1b8d45' into store-pa…
Ericson2314 Sep 3, 2023
3a43680
Merge commit '91617f80ec03ff4580a656310959ce2e31e0d177' into store-pa…
Ericson2314 Sep 3, 2023
9faa690
Merge commit '2e7be46e73293f729358eefc5b464dcb7e2d76bf' into store-pa…
Ericson2314 Sep 3, 2023
6305b77
Merge commit '056cc1c1b903114f59c536dd9821b46f68516f4e' into store-pa…
Ericson2314 Sep 3, 2023
6208375
Merge commit '6601ac86421fb05377f113aa52c55da7b9cbe658' into store-pa…
Ericson2314 Sep 3, 2023
7cac155
Merge commit 'c67e0cc58c5a74121d74a3f5cf9f9c2199a87093' into store-pa…
Ericson2314 Sep 3, 2023
f7f1be6
Merge commit 'b21dd384235bc9863c89ef249bbc1ca58f4ec3fd' into store-pa…
Ericson2314 Sep 3, 2023
57bf738
Merge branch 'store-path-descriptor' into store-path-or-ca
Ericson2314 Sep 3, 2023
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
17 changes: 11 additions & 6 deletions perl/lib/Nix/Store.xs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void setVerbosity(int level)
int isValidPath(char * path)
CODE:
try {
RETVAL = store()->isValidPath(store()->parseStorePath(path));
auto storePath = store()->parseStorePath(path);
RETVAL = store()->isValidPath(storePath);
} catch (Error & e) {
croak("%s", e.what());
}
Expand All @@ -68,7 +69,8 @@ int isValidPath(char * path)
SV * queryReferences(char * path)
PPCODE:
try {
for (auto & i : store()->queryPathInfo(store()->parseStorePath(path))->references)
auto storePath = store()->parseStorePath(path);
for (auto & i : store()->queryPathInfo(storePath)->referencesPossiblyToSelf())
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(i).c_str(), 0)));
} catch (Error & e) {
croak("%s", e.what());
Expand All @@ -78,7 +80,8 @@ SV * queryReferences(char * path)
SV * queryPathHash(char * path)
PPCODE:
try {
auto s = store()->queryPathInfo(store()->parseStorePath(path))->narHash.to_string(Base32, true);
auto storePath = store()->parseStorePath(path);
auto s = store()->queryPathInfo(storePath)->narHash.to_string(Base32, true);
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
} catch (Error & e) {
croak("%s", e.what());
Expand All @@ -88,7 +91,8 @@ SV * queryPathHash(char * path)
SV * queryDeriver(char * path)
PPCODE:
try {
auto info = store()->queryPathInfo(store()->parseStorePath(path));
auto storePath = store()->parseStorePath(path);
auto info = store()->queryPathInfo(storePath);
if (!info->deriver) XSRETURN_UNDEF;
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(*info->deriver).c_str(), 0)));
} catch (Error & e) {
Expand All @@ -99,7 +103,8 @@ SV * queryDeriver(char * path)
SV * queryPathInfo(char * path, int base32)
PPCODE:
try {
auto info = store()->queryPathInfo(store()->parseStorePath(path));
auto storePath = store()->parseStorePath(path);
auto info = store()->queryPathInfo(storePath);
if (!info->deriver)
XPUSHs(&PL_sv_undef);
else
Expand All @@ -109,7 +114,7 @@ SV * queryPathInfo(char * path, int base32)
mXPUSHi(info->registrationTime);
mXPUSHi(info->narSize);
AV * refs = newAV();
for (auto & i : info->references)
for (auto & i : info->referencesPossiblyToSelf())
av_push(refs, newSVpv(store()->printStorePath(i).c_str(), 0));
XPUSHs(sv_2mortal(newRV((SV *) refs)));
AV * sigs = newAV();
Expand Down
3 changes: 2 additions & 1 deletion src/libcmd/command.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ ref<Store> StoreCommand::createStore()

void StoreCommand::run()
{
run(getStore());
auto store = getStore();
run(store);
}

CopyCommand::CopyCommand()
Expand Down
8 changes: 5 additions & 3 deletions src/libcmd/common-eval-args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,15 +167,17 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
SourcePath lookupFileArg(EvalState & state, std::string_view s)
{
if (EvalSettings::isPseudoUrl(s)) {
auto storePath = fetchers::downloadTarball(
state.store, EvalSettings::resolvePseudoUrl(s), "source", false).tree.storePath;
auto storePath = state.store->makeFixedOutputPathFromCA(
fetchers::downloadTarball(
state.store, EvalSettings::resolvePseudoUrl(s), "source", false).tree.storePath);
return state.rootPath(CanonPath(state.store->toRealPath(storePath)));
}

else if (hasPrefix(s, "flake:")) {
experimentalFeatureSettings.require(Xp::Flakes);
auto flakeRef = parseFlakeRef(std::string(s.substr(6)), {}, true, false);
auto storePath = flakeRef.resolve(state.store).fetchTree(state.store).first.storePath;
auto storePath = state.store->makeFixedOutputPathFromCA(
flakeRef.resolve(state.store).fetchTree(state.store).first.storePath);
return state.rootPath(CanonPath(state.store->toRealPath(storePath)));
}

Expand Down
2 changes: 1 addition & 1 deletion src/libcmd/installables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ ref<eval_cache::EvalCache> openEvalCache(
EvalState & state,
std::shared_ptr<flake::LockedFlake> lockedFlake)
{
auto fingerprint = lockedFlake->getFingerprint();
auto fingerprint = lockedFlake->getFingerprint(*state.store);
return make_ref<nix::eval_cache::EvalCache>(
evalSettings.useEvalCache && evalSettings.pureEval
? std::optional { std::cref(fingerprint) }
Expand Down
13 changes: 8 additions & 5 deletions src/libexpr/flake/flake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ static std::tuple<fetchers::Tree, FlakeRef, FlakeRef> fetchOrSubstituteTree(

auto [tree, lockedRef] = *fetched;

auto storePath = state.store->makeFixedOutputPathFromCA(tree.storePath);

debug("got tree '%s' from '%s'",
state.store->printStorePath(tree.storePath), lockedRef);
state.store->printStorePath(storePath), lockedRef);

state.allowPath(tree.storePath);
state.allowPath(storePath);

assert(!originalRef.input.getNarHash() || tree.storePath == originalRef.input.computeStorePath(*state.store));

Expand Down Expand Up @@ -210,7 +212,8 @@ static Flake getFlake(
auto flakeFile = canonPath(flakeDir + "/flake.nix", true);
if (!isInDir(flakeFile, sourceInfo.actualPath))
throw Error("'flake.nix' file of flake '%s' escapes from '%s'",
lockedRef, state.store->printStorePath(sourceInfo.storePath));
lockedRef,
state.store->printStorePath(state.store->makeFixedOutputPathFromCA(sourceInfo.storePath)));

Flake flake {
.originalRef = originalRef,
Expand Down Expand Up @@ -891,14 +894,14 @@ static RegisterPrimOp r4({

}

Fingerprint LockedFlake::getFingerprint() const
Fingerprint LockedFlake::getFingerprint(const Store & store) const
{
// FIXME: as an optimization, if the flake contains a lock file
// and we haven't changed it, then it's sufficient to use
// flake.sourceInfo.storePath for the fingerprint.
return hashString(htSHA256,
fmt("%s;%s;%d;%d;%s",
flake.sourceInfo->storePath.to_string(),
store.makeFixedOutputPathFromCA(flake.sourceInfo->storePath).to_string(),
flake.lockedRef.subdir,
flake.lockedRef.input.getRevCount().value_or(0),
flake.lockedRef.input.getLastModified().value_or(0),
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/flake/flake.hh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ struct LockedFlake
Flake flake;
LockFile lockFile;

Fingerprint getFingerprint() const;
Fingerprint getFingerprint(const Store & store) const;
};

struct LockFlags
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/flake/lockfile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LockedNode::LockedNode(const nlohmann::json & json)
fetchers::attrsToJSON(lockedRef.input.toAttrs()));
}

StorePath LockedNode::computeStorePath(Store & store) const
StorePathDescriptor LockedNode::computeStorePath(Store & store) const
{
return lockedRef.input.computeStorePath(store);
}
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr/flake/lockfile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
///@file

#include "flakeref.hh"
#include "content-address.hh"

#include <nlohmann/json_fwd.hpp>

Expand Down Expand Up @@ -47,7 +48,7 @@ struct LockedNode : Node

LockedNode(const nlohmann::json & json);

StorePath computeStorePath(Store & store) const;
StorePathDescriptor computeStorePath(Store & store) const;
};

struct LockFile
Expand Down
11 changes: 8 additions & 3 deletions src/libexpr/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,12 @@ std::optional<std::string> EvalState::resolveSearchPathPath(const SearchPath::Pa

if (EvalSettings::isPseudoUrl(value)) {
try {
auto storePath = fetchers::downloadTarball(
store, EvalSettings::resolvePseudoUrl(value), "source", false).tree.storePath;
auto storePath = store->makeFixedOutputPathFromCA(
fetchers::downloadTarball(
store,
EvalSettings::resolvePseudoUrl(value),
"source",
false).tree.storePath);
res = { store->toRealPath(storePath) };
} catch (FileTransferError & e) {
logWarning({
Expand All @@ -796,7 +800,8 @@ std::optional<std::string> EvalState::resolveSearchPathPath(const SearchPath::Pa
experimentalFeatureSettings.require(Xp::Flakes);
auto flakeRef = parseFlakeRef(value.substr(6), {}, true, false);
debug("fetching flake search path element '%s''", value);
auto storePath = flakeRef.resolve(store).fetchTree(store).first.storePath;
auto storePath = store->makeFixedOutputPathFromCA(
flakeRef.resolve(store).fetchTree(store).first.storePath);
res = { store->toRealPath(storePath) };
}

Expand Down
5 changes: 3 additions & 2 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1618,8 +1618,9 @@ static void prim_readFile(EvalState & state, const PosIdx pos, Value * * args, V
state.debugThrowLastTrace(Error("the contents of the file '%1%' cannot be represented as a Nix string", path));
StorePathSet refs;
if (state.store->isInStore(path.path.abs())) {
auto p = state.store->toStorePath(path.path.abs()).first;
try {
refs = state.store->queryPathInfo(state.store->toStorePath(path.path.abs()).first)->references;
refs = state.store->queryPathInfo(p)->referencesPossiblyToSelf();
} catch (Error &) { // FIXME: should be InvalidPathError
}
// Re-scan references to filter down to just the ones that actually occur in the file.
Expand Down Expand Up @@ -2188,7 +2189,7 @@ static void addPath(
try {
auto [storePath, subPath] = state.store->toStorePath(path);
// FIXME: we should scanForReferences on the path before adding it
refs = state.store->queryPathInfo(storePath)->references;
refs = state.store->queryPathInfo(storePath)->referencesPossiblyToSelf();
path = state.store->toRealPath(storePath) + subPath;
} catch (Error &) { // FIXME: should be InvalidPathError
}
Expand Down
3 changes: 2 additions & 1 deletion src/libexpr/primops/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,9 @@ static void prim_appendContext(EvalState & state, const PosIdx pos, Value * * ar
.errPos = state.positions[i.pos]
});
auto namePath = state.store->parseStorePath(name);
if (!settings.readOnlyMode)
if (!settings.readOnlyMode) {
state.store->ensurePath(namePath);
}
state.forceAttrs(*i.value, i.pos, "while evaluating the value of a string context");
auto iter = i.value->attrs->find(sPath);
if (iter != i.value->attrs->end()) {
Expand Down
5 changes: 3 additions & 2 deletions src/libexpr/primops/fetchMercurial.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a
auto [tree, input2] = input.fetch(state.store);

auto attrs2 = state.buildBindings(8);
state.mkStorePathString(tree.storePath, attrs2.alloc(state.sOutPath));
auto storePath = state.store->makeFixedOutputPathFromCA(tree.storePath);
state.mkStorePathString(storePath, attrs2.alloc(state.sOutPath));
if (input2.getRef())
attrs2.alloc("branch").mkString(*input2.getRef());
// Backward compatibility: set 'rev' to
Expand All @@ -86,7 +87,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a
attrs2.alloc("revCount").mkInt(*revCount);
v.mkAttrs(attrs2);

state.allowPath(tree.storePath);
state.allowPath(state.store->makeFixedOutputPathFromCA(tree.storePath));
}

static RegisterPrimOp r_fetchMercurial({
Expand Down
28 changes: 21 additions & 7 deletions src/libexpr/primops/fetchTree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ void emitTreeAttrs(

auto attrs = state.buildBindings(10);

auto storePath = state.store->makeFixedOutputPathFromCA(tree.storePath);

state.mkStorePathString(tree.storePath, attrs.alloc(state.sOutPath));
state.mkStorePathString(storePath, attrs.alloc(state.sOutPath));

// FIXME: support arbitrary input attributes.

Expand Down Expand Up @@ -188,7 +189,7 @@ static void fetchTree(

auto [tree, input2] = input.fetch(state.store);

state.allowPath(tree.storePath);
state.allowPath(state.store->makeFixedOutputPathFromCA(tree.storePath));

emitTreeAttrs(state, tree, input2, v, params.emptyRevFallback, false);
}
Expand Down Expand Up @@ -250,12 +251,14 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
if (evalSettings.pureEval && !expectedHash)
state.debugThrowLastTrace(EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who));

// early exit if pinned and already in the store
if (expectedHash && expectedHash->type == htSHA256) {
// early exit if pinned and already in the store, or substituted successfully
if (expectedHash) {
auto method = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;

auto expectedPath = state.store->makeFixedOutputPath(
name,
FixedOutputInfo {
.method = unpack ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat,
.method = method,
.hash = *expectedHash,
.references = {}
});
Expand All @@ -264,6 +267,15 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
state.allowAndSetStorePathString(expectedPath, v);
return;
}

// try to substitute if we can

auto substitutableStorePath = fetchers::trySubstitute(state.store, method, *expectedHash, name);

if (substitutableStorePath) {
state.allowAndSetStorePathString(*substitutableStorePath, v);
return;
}
}

// TODO: fetching may fail, yet the path may be substitutable.
Expand All @@ -273,16 +285,18 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
? fetchers::downloadTarball(state.store, *url, name, (bool) expectedHash).tree.storePath
: fetchers::downloadFile(state.store, *url, name, (bool) expectedHash).storePath;

auto actualStorePath = state.store->makeFixedOutputPathFromCA(storePath);

if (expectedHash) {
auto hash = unpack
? state.store->queryPathInfo(storePath)->narHash
: hashFile(htSHA256, state.store->toRealPath(storePath));
: hashFile(htSHA256, state.store->toRealPath(actualStorePath));
if (hash != *expectedHash)
state.debugThrowLastTrace(EvalError((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
*url, expectedHash->to_string(Base32, true), hash.to_string(Base32, true)));
}

state.allowAndSetStorePathString(storePath, v);
state.allowAndSetStorePathString(actualStorePath, v);
}

static void prim_fetchurl(EvalState & state, const PosIdx pos, Value * * args, Value & v)
Expand Down
12 changes: 7 additions & 5 deletions src/libfetchers/cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,19 @@ struct CacheImpl : Cache
ref<Store> store,
const Attrs & inAttrs,
const Attrs & infoAttrs,
const StorePath & storePath,
const StorePathDescriptor & storePathDesc,
bool locked) override
{
_state.lock()->add.use()
(attrsToJSON(inAttrs).dump())
(attrsToJSON(infoAttrs).dump())
(store->printStorePath(storePath))
// FIXME should use JSON for store path descriptor
(renderStorePathDescriptor(storePathDesc))
(locked)
(time(0)).exec();
}

std::optional<std::pair<Attrs, StorePath>> lookup(
std::optional<std::pair<Attrs, StorePathDescriptor>> lookup(
ref<Store> store,
const Attrs & inAttrs) override
{
Expand Down Expand Up @@ -90,9 +91,10 @@ struct CacheImpl : Cache
}

auto infoJSON = stmt.getStr(0);
auto storePath = store->parseStorePath(stmt.getStr(1));
auto storePathDesc = parseStorePathDescriptor(stmt.getStr(1));
auto locked = stmt.getInt(2) != 0;
auto timestamp = stmt.getInt(3);
auto storePath = store->makeFixedOutputPathFromCA(storePathDesc);

store->addTempRoot(storePath);
if (!store->isValidPath(storePath)) {
Expand All @@ -107,7 +109,7 @@ struct CacheImpl : Cache
return Result {
.expired = !locked && (settings.tarballTtl.get() == 0 || timestamp + settings.tarballTtl < time(0)),
.infoAttrs = jsonToAttrs(nlohmann::json::parse(infoJSON)),
.storePath = std::move(storePath)
.storePath = std::move(storePathDesc)
};
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/libfetchers/cache.hh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ struct Cache
ref<Store> store,
const Attrs & inAttrs,
const Attrs & infoAttrs,
const StorePath & storePath,
const StorePathDescriptor & storePath,
bool locked) = 0;

virtual std::optional<std::pair<Attrs, StorePath>> lookup(
virtual std::optional<std::pair<Attrs, StorePathDescriptor>> lookup(
ref<Store> store,
const Attrs & inAttrs) = 0;

struct Result
{
bool expired = false;
Attrs infoAttrs;
StorePath storePath;
StorePathDescriptor storePath;
};

virtual std::optional<Result> lookupExpired(
Expand Down
Loading