Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic import errors #30

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions src/libexpr/nixexpr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MakeError(ThrownError, AssertionError)
MakeError(Abort, EvalError)
MakeError(TypeError, EvalError)
MakeError(ImportError, EvalError) // error building an imported derivation
MakeError(ImportReadOnlyError, EvalError) // error when trying to import a derivation in read-only mode


/* Position objects. */
Expand Down
47 changes: 32 additions & 15 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,41 @@ static void prim_import(EvalState & state, Value * * args, Value & v)

foreach (PathSet::iterator, i, context) {
Path ctx = decodeContext(*i).first;
string outputName = decodeContext(*i).second;
assert(isStorePath(ctx));
if (!store->isValidPath(ctx))
throw EvalError(format("cannot import `%1%', since path `%2%' is not valid")
% path % ctx);
if (isDerivation(ctx))
try {
/* For performance, prefetch all substitute info. */
PathSet willBuild, willSubstitute, unknown;
unsigned long long downloadSize, narSize;
queryMissing(*store, singleton<PathSet>(ctx),
willBuild, willSubstitute, unknown, downloadSize, narSize);
if (!store->isValidPath(ctx)) {
if (outputName.empty())
throw EvalError(format("cannot import `%1%', since path `%2%' is not valid")
% path % ctx);
else
throw ImportReadOnlyError(format("cannot import `%1%', since path `%2%' cannot be written to the store in read-only mode")
% path % ctx);
}
if (isDerivation(ctx)) {
Derivation drv = derivationFromPath(*store, ctx);

if (outputName.empty() ||
!store->isValidPath(drv.outputs[outputName].path)) {
if (settings.readOnlyMode)
foreach (DerivationOutputs::iterator, j, drv.outputs)
if (!store->isValidPath(j->second.path))
throw ImportReadOnlyError(format("cannot import `%1%', since derivation `%2%' cannot be realised in read-only mode")
% path % ctx);
try {
/* For performance, prefetch all substitute info. */
PathSet willBuild, willSubstitute, unknown;
unsigned long long downloadSize, narSize;
queryMissing(*store, singleton<PathSet>(ctx),
willBuild, willSubstitute, unknown, downloadSize, narSize);

/* !!! If using a substitute, we only need to fetch
the selected output of this derivation. */
store->buildPaths(singleton<PathSet>(ctx));
} catch (Error & e) {
throw ImportError(e.msg());
/* !!! If using a substitute, we only need to fetch
the selected output of this derivation. */
store->buildPaths(singleton<PathSet>(ctx));
} catch (Error & e) {
throw ImportError(e.msg());
}
}
}
}

if (isStorePath(path) && store->isValidPath(path) && isDerivation(path)) {
Expand Down