1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 14:21:48 +02:00

Merge pull request #12583 from ulucs/ulucs/skip-ifds

`nix flake show`: Skip IFDs instead of throwing
This commit is contained in:
Jörg Thalheim 2025-03-27 11:40:49 +01:00 committed by GitHub
commit ca165f09c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 69 additions and 15 deletions

View file

@ -110,5 +110,6 @@ template class EvalErrorBuilder<UndefinedVarError>;
template class EvalErrorBuilder<MissingArgumentError>;
template class EvalErrorBuilder<InfiniteRecursionError>;
template class EvalErrorBuilder<InvalidPathError>;
template class EvalErrorBuilder<IFDError>;
}

View file

@ -54,6 +54,7 @@ MakeError(TypeError, EvalError);
MakeError(UndefinedVarError, EvalError);
MakeError(MissingArgumentError, EvalError);
MakeError(InfiniteRecursionError, EvalError);
MakeError(IFDError, EvalBaseError);
struct InvalidPathError : public EvalError
{

View file

@ -91,7 +91,7 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
if (drvs.empty()) return {};
if (isIFD && !settings.enableImportFromDerivation)
error<EvalBaseError>(
error<IFDError>(
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
drvs.begin()->to_string(*store)
).debugThrow();

View file

@ -1329,18 +1329,34 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS)));
}
} else {
if (visitor.isDerivation())
showDerivation();
else
throw Error("expected a derivation");
try {
if (visitor.isDerivation())
showDerivation();
else
throw Error("expected a derivation");
} catch (IFDError & e) {
if (!json) {
logger->cout(fmt("%s " ANSI_WARNING "omitted due to use of import from derivation" ANSI_NORMAL, headerPrefix));
} else {
logger->warn(fmt("%s omitted due to use of import from derivation", concatStringsSep(".", attrPathS)));
}
}
}
}
else if (attrPath.size() > 0 && attrPathS[0] == "hydraJobs") {
if (visitor.isDerivation())
showDerivation();
else
recurse();
try {
if (visitor.isDerivation())
showDerivation();
else
recurse();
} catch (IFDError & e) {
if (!json) {
logger->cout(fmt("%s " ANSI_WARNING "omitted due to use of import from derivation" ANSI_NORMAL, headerPrefix));
} else {
logger->warn(fmt("%s omitted due to use of import from derivation", concatStringsSep(".", attrPathS)));
}
}
}
else if (attrPath.size() > 0 && attrPathS[0] == "legacyPackages") {
@ -1359,11 +1375,19 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS)));
}
} else {
if (visitor.isDerivation())
showDerivation();
else if (attrPath.size() <= 2)
// FIXME: handle recurseIntoAttrs
recurse();
try {
if (visitor.isDerivation())
showDerivation();
else if (attrPath.size() <= 2)
// FIXME: handle recurseIntoAttrs
recurse();
} catch (IFDError & e) {
if (!json) {
logger->cout(fmt("%s " ANSI_WARNING "omitted due to use of import from derivation" ANSI_NORMAL, headerPrefix));
} else {
logger->warn(fmt("%s omitted due to use of import from derivation", concatStringsSep(".", attrPathS)));
}
}
}
}