testing: migrate flakes/flake-metadata.sh

Change-Id: I8370a279bbfa224f27cdba0cf9e79ade6d58644f
This commit is contained in:
eldritch horrors
2026-02-18 11:32:33 +00:00
parent fedb4d5ead
commit 03b8a6dcc2
6 changed files with 51 additions and 37 deletions
-36
View File
@@ -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"
-1
View File
@@ -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',
@@ -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 = { ... }: {};
}
@@ -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:
+31
View File
@@ -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")