From c598c6d5762b5c10ef0dd098d7a9feac52f3494a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 21 May 2025 18:09:11 +0200 Subject: [PATCH 1/2] json-schema-catalog-rs: init at 0.1.1 --- .../js/json-schema-catalog-rs/package.nix | 42 +++++++++++++++ .../js/json-schema-catalog-rs/test-run.nix | 54 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 pkgs/by-name/js/json-schema-catalog-rs/package.nix create mode 100644 pkgs/by-name/js/json-schema-catalog-rs/test-run.nix diff --git a/pkgs/by-name/js/json-schema-catalog-rs/package.nix b/pkgs/by-name/js/json-schema-catalog-rs/package.nix new file mode 100644 index 000000000000..5fd10d430fab --- /dev/null +++ b/pkgs/by-name/js/json-schema-catalog-rs/package.nix @@ -0,0 +1,42 @@ +{ + callPackage, + fetchFromGitHub, + lib, + nix-update-script, + rustPlatform, +}: + +rustPlatform.buildRustPackage (finalAttrs: { + pname = "json-schema-catalog-rs"; + version = "0.1.1"; + + src = fetchFromGitHub { + owner = "roberth"; + repo = "json-schema-catalog-rs"; + tag = finalAttrs.version; + hash = "sha256-BbEPpolv2aoKFlfZ6A+CmUlr5sySGIqRlv3rLgf1VkA="; + }; + + cargoHash = "sha256-YI2LN2DBzC1B5wCZOrGAZi/hkKHoAm6xLkdJ+8DDFo8="; + + passthru = { + tests = { + run = callPackage ./test-run.nix { json-schema-catalog-rs = finalAttrs.finalPackage; }; + }; + + updateScript = nix-update-script { }; + }; + + meta = { + description = "CLI for working with JSON Schema Catalogs"; + longDescription = '' + A JSON Schema Catalog file provides a mapping from schema URIs to schema locations. + By constructing and using a catalog, you can avoid the need to download and parse schemas from the internet. + This is particularly useful when working with large schemas or when you need to work, test or build offline. + ''; + homepage = "https://github.com/roberth/json-schema-catalog-rs"; + license = lib.licenses.asl20; + maintainers = [ lib.maintainers.roberth ]; + mainProgram = "json-schema-catalog"; + }; +}) diff --git a/pkgs/by-name/js/json-schema-catalog-rs/test-run.nix b/pkgs/by-name/js/json-schema-catalog-rs/test-run.nix new file mode 100644 index 000000000000..0b2cce62e208 --- /dev/null +++ b/pkgs/by-name/js/json-schema-catalog-rs/test-run.nix @@ -0,0 +1,54 @@ +{ + json-schema-catalog-rs, + runCommand, +}: +let + + sample = builtins.toFile "example-schema.json" ( + builtins.toJSON { + "$schema" = "http://json-schema.org/draft-07/schema#"; + "$id" = "https://example.com/example-2.9.json"; + "title" = "Example Schema"; + } + ); + +in +runCommand "json-schema-catalog-rs-test-run" + { + nativeBuildInputs = [ + json-schema-catalog-rs + ]; + inherit sample; + expectedOutput = '' + { + "groups": [ + { + "baseLocation": "/nix/store", + "name": "Example Schema", + "schemas": [ + { + "id": "https://example.com/example-2.9.json", + "location": "${baseNameOf sample}" + } + ] + } + ], + "name": "Catalog" + } + ''; + passAsFile = [ + "expectedOutput" + ]; + } + '' + set -u + + # Test version + json-schema-catalog --version | grep ${json-schema-catalog-rs.version} + + # Test a simple command + json-schema-catalog new "$sample" > out.json + diff -U3 "$expectedOutputPath" out.json + + touch $out + '' From 72eaf394d30c57cf685f528abe9b6c5c2432284d Mon Sep 17 00:00:00 2001 From: Ethan Carter Edwards Date: Thu, 22 May 2025 23:48:38 +0200 Subject: [PATCH 2/2] json-schema-catalog-rs: add versionCheckHook --- pkgs/by-name/js/json-schema-catalog-rs/package.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/by-name/js/json-schema-catalog-rs/package.nix b/pkgs/by-name/js/json-schema-catalog-rs/package.nix index 5fd10d430fab..00c40f562221 100644 --- a/pkgs/by-name/js/json-schema-catalog-rs/package.nix +++ b/pkgs/by-name/js/json-schema-catalog-rs/package.nix @@ -4,6 +4,7 @@ lib, nix-update-script, rustPlatform, + versionCheckHook, }: rustPlatform.buildRustPackage (finalAttrs: { @@ -19,6 +20,11 @@ rustPlatform.buildRustPackage (finalAttrs: { cargoHash = "sha256-YI2LN2DBzC1B5wCZOrGAZi/hkKHoAm6xLkdJ+8DDFo8="; + doInstallCheck = true; + nativeInstallCheckInputs = [ versionCheckHook ]; + versionCheckProgram = "${placeholder "out"}/bin/json-schema-catalog"; + versionCheckProgramArg = "--version"; + passthru = { tests = { run = callPackage ./test-run.nix { json-schema-catalog-rs = finalAttrs.finalPackage; };