aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThéophane Hufschmitt <theophane.hufschmitt@tweag.io>2023-01-27 10:13:05 +0100
committerThéophane Hufschmitt <theophane.hufschmitt@tweag.io>2023-01-27 10:15:49 +0100
commit79c084cb598221f5910c429127e8da33cff6a206 (patch)
tree42826377bf667f164ec8396ba25b7f86aa9a48ff
parentab424a39a966e2e3bfb2a34ba5cf4f1c49f86d2d (diff)
Add a test for `nix flake show`
-rw-r--r--tests/flakes/common.sh4
-rw-r--r--tests/flakes/show.sh39
-rw-r--r--tests/local.mk1
3 files changed, 44 insertions, 0 deletions
diff --git a/tests/flakes/common.sh b/tests/flakes/common.sh
index c333733c2..fdcdd4aef 100644
--- a/tests/flakes/common.sh
+++ b/tests/flakes/common.sh
@@ -20,6 +20,10 @@ 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;
diff --git a/tests/flakes/show.sh b/tests/flakes/show.sh
new file mode 100644
index 000000000..995de8dc3
--- /dev/null
+++ b/tests/flakes/show.sh
@@ -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
+'
diff --git a/tests/local.mk b/tests/local.mk
index 5ac1ede32..c8ee82e1a 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -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