diff --git a/tests/functional/flakes/flake-metadata.sh b/tests/functional/flakes/flake-metadata.sh deleted file mode 100644 index ab5a69b3a..000000000 --- a/tests/functional/flakes/flake-metadata.sh +++ /dev/null @@ -1,36 +0,0 @@ -source ./common.sh - -flakeDir=$TEST_ROOT/flake -mkdir -p "$flakeDir" - -cat > "$flakeDir/flake.nix" <<-'EOF' -{ - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small"; - flake-utils.url = "github:numtide/flake-utils"; - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; - lanzaboote = { - url = "github:nix-community/lanzaboote"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows = "flake-utils"; - inputs.flake-compat.follows = "flake-compat"; - }; - }; - - outputs = { ... }: {}; -} -EOF - -cp flake-metadata/flake.lock "$flakeDir" -touch -d @1000 "$flakeDir/flake.nix" "$flakeDir/flake.lock" "$flakeDir" - -# For some reason we use NIX_STORE_DIR which causes unstable paths. This is -# goofy. We can just use --store, which sets rootDir and does not have this -# problem. -actualStore=$NIX_STORE_DIR -unset NIX_STORE_DIR -NOCOLOR=1 TZ=UTC LC_ALL=C.UTF-8 nix flake metadata --store "$actualStore" "$flakeDir" | grep -v -e 'Locked URL:' -e 'Resolved URL:' > "$TEST_ROOT/metadata.out.actual" -diff -u flake-metadata/metadata.out.expected "$TEST_ROOT/metadata.out.actual" diff --git a/tests/functional/meson.build b/tests/functional/meson.build index b97f8aefc..0077de1e6 100644 --- a/tests/functional/meson.build +++ b/tests/functional/meson.build @@ -39,7 +39,6 @@ functional_tests_scripts = [ 'flakes/follow-paths.sh', 'flakes/build-paths.sh', 'flakes/flake-in-submodule.sh', - 'flakes/flake-metadata.sh', 'flakes/flake-registry.sh', 'gc.sh', 'nix-collect-garbage-d.sh', diff --git a/tests/functional/flakes/flake-metadata/flake.lock b/tests/functional2/flakes/assets/metadata/flake/flake.lock similarity index 100% rename from tests/functional/flakes/flake-metadata/flake.lock rename to tests/functional2/flakes/assets/metadata/flake/flake.lock diff --git a/tests/functional2/flakes/assets/metadata/flake/flake.nix b/tests/functional2/flakes/assets/metadata/flake/flake.nix new file mode 100644 index 000000000..ff186e0f2 --- /dev/null +++ b/tests/functional2/flakes/assets/metadata/flake/flake.nix @@ -0,0 +1,18 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable-small"; + flake-utils.url = "github:numtide/flake-utils"; + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + lanzaboote = { + url = "github:nix-community/lanzaboote"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.flake-utils.follows = "flake-utils"; + inputs.flake-compat.follows = "flake-compat"; + }; + }; + + outputs = { ... }: {}; +} diff --git a/tests/functional/flakes/flake-metadata/metadata.out.expected b/tests/functional2/flakes/assets/metadata/metadata.out similarity index 94% rename from tests/functional/flakes/flake-metadata/metadata.out.expected rename to tests/functional2/flakes/assets/metadata/metadata.out index 72e57eca7..ccd3b7bbf 100644 --- a/tests/functional/flakes/flake-metadata/metadata.out.expected +++ b/tests/functional2/flakes/assets/metadata/metadata.out @@ -1,3 +1,5 @@ +Resolved URL: path:$root/flake +Locked URL: path:$root/flake?lastModified=1000&narHash=sha256-V/Gp5MFC5UehsIwWzL2prFyG2j8jz5r4aLZIlvBzTjw%3D Path: /nix/store/gaxb42z68bcr8lch467shvmnhjjzgd8b-source Last modified: 1970-01-01 00:16:40 Inputs: diff --git a/tests/functional2/flakes/test_metadata.py b/tests/functional2/flakes/test_metadata.py new file mode 100644 index 000000000..82c7b3df1 --- /dev/null +++ b/tests/functional2/flakes/test_metadata.py @@ -0,0 +1,31 @@ +from testlib.fixtures.nix import Nix +from testlib.fixtures.file_helper import with_files, CopyTree, AssetSymlink +from testlib.fixtures.snapshot import Snapshot +from pathlib import Path +import os + + +@with_files( + { + "flake": CopyTree("assets/metadata/flake"), + "metadata.out": AssetSymlink("assets/metadata/metadata.out"), + } +) +def test_metadata(nix: Nix, files: Path, snapshot: Snapshot): + nix.settings.add_xp_feature("nix-command", "flakes") + nix.env.dirs.nix_store_dir = "/nix/store" + nix.env["TZ"] = "UTC" + nix.env["LC_ALL"] = "C.UTF-8" + + os.utime(files / "flake/flake.nix", (1000, 1000)) + os.utime(files / "flake/flake.lock", (1000, 1000)) + os.utime(files / "flake", (1000, 1000)) + + # We use NIX_STORE_DIR which causes unstable paths. This is goofy. We can + # just use `--store` which sets `rootDir` and does not have this problem. + result = ( + nix.nix(["flake", "metadata", "--store", nix.env.dirs.real_store_dir, files / "flake"]) + .run() + .ok() + ) + assert snapshot("metadata.out") == result.stdout_s.replace(str(files), "$root")