mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
skip ifds in nix flake show instead of throwing
This commit is contained in:
parent
77f22db567
commit
fcf5966488
6 changed files with 69 additions and 15 deletions
|
@ -110,5 +110,6 @@ template class EvalErrorBuilder<UndefinedVarError>;
|
|||
template class EvalErrorBuilder<MissingArgumentError>;
|
||||
template class EvalErrorBuilder<InfiniteRecursionError>;
|
||||
template class EvalErrorBuilder<InvalidPathError>;
|
||||
template class EvalErrorBuilder<IFDError>;
|
||||
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ MakeError(TypeError, EvalError);
|
|||
MakeError(UndefinedVarError, EvalError);
|
||||
MakeError(MissingArgumentError, EvalError);
|
||||
MakeError(InfiniteRecursionError, EvalError);
|
||||
MakeError(IFDError, EvalBaseError);
|
||||
|
||||
struct InvalidPathError : public EvalError
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,6 +88,19 @@ writeDependentFlake() {
|
|||
EOF
|
||||
}
|
||||
|
||||
writeIfdFlake() {
|
||||
local flakeDir="$1"
|
||||
cat > "$flakeDir/flake.nix" <<EOF
|
||||
{
|
||||
outputs = { self }: {
|
||||
packages.$system.default = import ./ifd.nix;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
||||
cp -n ../ifd.nix ../dependencies.nix ../dependencies.builder0.sh "${config_nix}" "$flakeDir/"
|
||||
}
|
||||
|
||||
writeTrivialFlake() {
|
||||
local flakeDir="$1"
|
||||
cat > "$flakeDir/flake.nix" <<EOF
|
||||
|
|
|
@ -6,7 +6,7 @@ flakeDir=$TEST_ROOT/flake
|
|||
mkdir -p "$flakeDir"
|
||||
|
||||
writeSimpleFlake "$flakeDir"
|
||||
cd "$flakeDir"
|
||||
pushd "$flakeDir"
|
||||
|
||||
|
||||
# By default: Only show the packages content for the current system and no
|
||||
|
@ -87,3 +87,18 @@ assert show_output.legacyPackages.${builtins.currentSystem}.AAAAAASomeThingsFail
|
|||
assert show_output.legacyPackages.${builtins.currentSystem}.simple.name == "simple";
|
||||
true
|
||||
'
|
||||
|
||||
# Test that nix flake show doesn't fail if one of the outputs contains
|
||||
# an IFD
|
||||
popd
|
||||
writeIfdFlake $flakeDir
|
||||
pushd $flakeDir
|
||||
|
||||
|
||||
nix flake show --json > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output.packages.${builtins.currentSystem}.default == { };
|
||||
true
|
||||
'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue