mirror of
https://github.com/NixOS/nix
synced 2025-06-25 06:31:14 +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<MissingArgumentError>;
|
||||||
template class EvalErrorBuilder<InfiniteRecursionError>;
|
template class EvalErrorBuilder<InfiniteRecursionError>;
|
||||||
template class EvalErrorBuilder<InvalidPathError>;
|
template class EvalErrorBuilder<InvalidPathError>;
|
||||||
|
template class EvalErrorBuilder<IFDError>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ MakeError(TypeError, EvalError);
|
||||||
MakeError(UndefinedVarError, EvalError);
|
MakeError(UndefinedVarError, EvalError);
|
||||||
MakeError(MissingArgumentError, EvalError);
|
MakeError(MissingArgumentError, EvalError);
|
||||||
MakeError(InfiniteRecursionError, EvalError);
|
MakeError(InfiniteRecursionError, EvalError);
|
||||||
|
MakeError(IFDError, EvalBaseError);
|
||||||
|
|
||||||
struct InvalidPathError : public EvalError
|
struct InvalidPathError : public EvalError
|
||||||
{
|
{
|
||||||
|
|
|
@ -91,7 +91,7 @@ StringMap EvalState::realiseContext(const NixStringContext & context, StorePathS
|
||||||
if (drvs.empty()) return {};
|
if (drvs.empty()) return {};
|
||||||
|
|
||||||
if (isIFD && !settings.enableImportFromDerivation)
|
if (isIFD && !settings.enableImportFromDerivation)
|
||||||
error<EvalBaseError>(
|
error<IFDError>(
|
||||||
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
"cannot build '%1%' during evaluation because the option 'allow-import-from-derivation' is disabled",
|
||||||
drvs.begin()->to_string(*store)
|
drvs.begin()->to_string(*store)
|
||||||
).debugThrow();
|
).debugThrow();
|
||||||
|
|
|
@ -1329,18 +1329,34 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
||||||
logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS)));
|
logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (visitor.isDerivation())
|
try {
|
||||||
showDerivation();
|
if (visitor.isDerivation())
|
||||||
else
|
showDerivation();
|
||||||
throw Error("expected a derivation");
|
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") {
|
else if (attrPath.size() > 0 && attrPathS[0] == "hydraJobs") {
|
||||||
if (visitor.isDerivation())
|
try {
|
||||||
showDerivation();
|
if (visitor.isDerivation())
|
||||||
else
|
showDerivation();
|
||||||
recurse();
|
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") {
|
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)));
|
logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (visitor.isDerivation())
|
try {
|
||||||
showDerivation();
|
if (visitor.isDerivation())
|
||||||
else if (attrPath.size() <= 2)
|
showDerivation();
|
||||||
// FIXME: handle recurseIntoAttrs
|
else if (attrPath.size() <= 2)
|
||||||
recurse();
|
// 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
|
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() {
|
writeTrivialFlake() {
|
||||||
local flakeDir="$1"
|
local flakeDir="$1"
|
||||||
cat > "$flakeDir/flake.nix" <<EOF
|
cat > "$flakeDir/flake.nix" <<EOF
|
||||||
|
|
|
@ -6,7 +6,7 @@ flakeDir=$TEST_ROOT/flake
|
||||||
mkdir -p "$flakeDir"
|
mkdir -p "$flakeDir"
|
||||||
|
|
||||||
writeSimpleFlake "$flakeDir"
|
writeSimpleFlake "$flakeDir"
|
||||||
cd "$flakeDir"
|
pushd "$flakeDir"
|
||||||
|
|
||||||
|
|
||||||
# By default: Only show the packages content for the current system and no
|
# 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";
|
assert show_output.legacyPackages.${builtins.currentSystem}.simple.name == "simple";
|
||||||
true
|
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