forked from lix-project/lix
Merge pull request #6988 from max-privatevoid/pr-flake-show-foreign
nix flake show: don't evaluate derivations for foreign systems by default
This commit is contained in:
commit
575d0aea5d
|
@ -966,6 +966,7 @@ struct CmdFlakeArchive : FlakeCommand, MixJSON, MixDryRun
|
|||
struct CmdFlakeShow : FlakeCommand, MixJSON
|
||||
{
|
||||
bool showLegacy = false;
|
||||
bool showAllSystems = false;
|
||||
|
||||
CmdFlakeShow()
|
||||
{
|
||||
|
@ -974,6 +975,11 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
.description = "Show the contents of the `legacyPackages` output.",
|
||||
.handler = {&showLegacy, true}
|
||||
});
|
||||
addFlag({
|
||||
.longName = "all-systems",
|
||||
.description = "Show the contents of outputs for all systems.",
|
||||
.handler = {&showAllSystems, true}
|
||||
});
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
|
@ -994,6 +1000,7 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
|
||||
auto state = getEvalState();
|
||||
auto flake = std::make_shared<LockedFlake>(lockFlake());
|
||||
auto localSystem = std::string(settings.thisSystem.get());
|
||||
|
||||
std::function<nlohmann::json(
|
||||
eval_cache::AttrCursor & visitor,
|
||||
|
@ -1084,11 +1091,19 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
|| (attrPath.size() == 3 && (attrPathS[0] == "checks" || attrPathS[0] == "packages" || attrPathS[0] == "devShells"))
|
||||
)
|
||||
{
|
||||
if (!showAllSystems && std::string(attrPathS[1]) != localSystem) {
|
||||
if (!json)
|
||||
logger->cout(fmt("%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--all-systems' to show)", headerPrefix));
|
||||
else {
|
||||
logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS)));
|
||||
}
|
||||
} else {
|
||||
if (visitor.isDerivation())
|
||||
showDerivation();
|
||||
else
|
||||
throw Error("expected a derivation");
|
||||
}
|
||||
}
|
||||
|
||||
else if (attrPath.size() > 0 && attrPathS[0] == "hydraJobs") {
|
||||
if (visitor.isDerivation())
|
||||
|
@ -1106,6 +1121,12 @@ struct CmdFlakeShow : FlakeCommand, MixJSON
|
|||
else {
|
||||
logger->warn(fmt("%s omitted (use '--legacy' to show)", concatStringsSep(".", attrPathS)));
|
||||
}
|
||||
} else if (!showAllSystems && std::string(attrPathS[1]) != localSystem) {
|
||||
if (!json)
|
||||
logger->cout(fmt("%s " ANSI_WARNING "omitted" ANSI_NORMAL " (use '--all-systems' to show)", headerPrefix));
|
||||
else {
|
||||
logger->warn(fmt("%s omitted (use '--all-systems' to show)", concatStringsSep(".", attrPathS)));
|
||||
}
|
||||
} else {
|
||||
if (visitor.isDerivation())
|
||||
showDerivation();
|
||||
|
|
|
@ -20,9 +20,13 @@ writeSimpleFlake() {
|
|||
foo = import ./simple.nix;
|
||||
default = foo;
|
||||
};
|
||||
packages.someOtherSystem = rec {
|
||||
foo = import ./simple.nix;
|
||||
default = foo;
|
||||
};
|
||||
|
||||
# To test "nix flake init".
|
||||
legacyPackages.x86_64-linux.hello = import ./simple.nix;
|
||||
legacyPackages.$system.hello = import ./simple.nix;
|
||||
};
|
||||
}
|
||||
EOF
|
||||
|
|
|
@ -41,8 +41,8 @@ cat > $templatesDir/trivial/flake.nix <<EOF
|
|||
description = "A flake for building Hello World";
|
||||
|
||||
outputs = { self, nixpkgs }: {
|
||||
packages.x86_64-linux = rec {
|
||||
hello = nixpkgs.legacyPackages.x86_64-linux.hello;
|
||||
packages.$system = rec {
|
||||
hello = nixpkgs.legacyPackages.$system.hello;
|
||||
default = hello;
|
||||
};
|
||||
};
|
||||
|
|
39
tests/flakes/show.sh
Normal file
39
tests/flakes/show.sh
Normal file
|
@ -0,0 +1,39 @@
|
|||
source ./common.sh
|
||||
|
||||
flakeDir=$TEST_ROOT/flake
|
||||
mkdir -p "$flakeDir"
|
||||
|
||||
writeSimpleFlake "$flakeDir"
|
||||
cd "$flakeDir"
|
||||
|
||||
|
||||
# By default: Only show the packages content for the current system and no
|
||||
# legacyPackages at all
|
||||
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.someOtherSystem.default == {};
|
||||
assert show_output.packages.${builtins.currentSystem}.default.name == "simple";
|
||||
assert show_output.legacyPackages.${builtins.currentSystem} == {};
|
||||
true
|
||||
'
|
||||
|
||||
# With `--all-systems`, show the packages for all systems
|
||||
nix flake show --json --all-systems > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output.packages.someOtherSystem.default.name == "simple";
|
||||
assert show_output.legacyPackages.${builtins.currentSystem} == {};
|
||||
true
|
||||
'
|
||||
|
||||
# With `--legacy`, show the legacy packages
|
||||
nix flake show --json --legacy > show-output.json
|
||||
nix eval --impure --expr '
|
||||
let show_output = builtins.fromJSON (builtins.readFile ./show-output.json);
|
||||
in
|
||||
assert show_output.legacyPackages.${builtins.currentSystem}.hello.name == "simple";
|
||||
true
|
||||
'
|
|
@ -113,6 +113,7 @@ nix_tests = \
|
|||
store-ping.sh \
|
||||
fetchClosure.sh \
|
||||
completions.sh \
|
||||
flakes/show.sh \
|
||||
impure-derivations.sh \
|
||||
path-from-hash-part.sh \
|
||||
toString-path.sh
|
||||
|
|
Loading…
Reference in a new issue