diff options
author | Anderson Torres <torres.anderson.85@protonmail.com> | 2024-03-29 15:49:50 -0300 |
---|---|---|
committer | Anderson Torres <torres.anderson.85@protonmail.com> | 2024-03-29 15:49:50 -0300 |
commit | 4653fbade9b5b242da3deedf9430f2c40685709a (patch) | |
tree | b713973b3758fea961c1ea4dfa4f41e3a3784f14 /pkgs/by-name/cu | |
parent | 1861d88ec84e9a918480ec36eedaaa789fa3b964 (diff) |
cue: migrate to by-name
Diffstat (limited to 'pkgs/by-name/cu')
-rw-r--r-- | pkgs/by-name/cu/cue/package.nix | 54 | ||||
-rw-r--r-- | pkgs/by-name/cu/cue/tests/001-all-good.nix | 11 | ||||
-rw-r--r-- | pkgs/by-name/cu/cue/validator.nix | 17 |
3 files changed, 82 insertions, 0 deletions
diff --git a/pkgs/by-name/cu/cue/package.nix b/pkgs/by-name/cu/cue/package.nix new file mode 100644 index 0000000000000..6f86bd745a242 --- /dev/null +++ b/pkgs/by-name/cu/cue/package.nix @@ -0,0 +1,54 @@ +{ buildGoModule +, fetchFromGitHub +, lib +, installShellFiles +, testers +, cue +, callPackage +}: + +buildGoModule rec { + pname = "cue"; + version = "0.8.0"; + + src = fetchFromGitHub { + owner = "cue-lang"; + repo = "cue"; + rev = "v${version}"; + hash = "sha256-7gn8/35rpbyzSP4ZM21ig6Wsq5Tp18x1Ex/IVb2iE7k="; + }; + + vendorHash = "sha256-0OZtKIDdEnQLnSj109EpGvaZvMIy7gPAZ+weHzYKGSg="; + + subPackages = [ "cmd/*" ]; + + nativeBuildInputs = [ installShellFiles ]; + + ldflags = [ "-s" "-w" "-X cuelang.org/go/cmd/cue/cmd.version=${version}" ]; + + postInstall = '' + installShellCompletion --cmd cue \ + --bash <($out/bin/cue completion bash) \ + --fish <($out/bin/cue completion fish) \ + --zsh <($out/bin/cue completion zsh) + ''; + + passthru = { + writeCueValidator = callPackage ./validator.nix { }; + tests = { + test-001-all-good = callPackage ./tests/001-all-good.nix { }; + version = testers.testVersion { + package = cue; + command = "cue version"; + }; + }; + }; + + meta = with lib; { + description = "A data constraint language which aims to simplify tasks involving defining and using data"; + homepage = "https://cuelang.org/"; + license = lib.licenses.asl20; + maintainers = with maintainers; [ aaronjheng ]; + mainProgram = "cue"; + }; +} diff --git a/pkgs/by-name/cu/cue/tests/001-all-good.nix b/pkgs/by-name/cu/cue/tests/001-all-good.nix new file mode 100644 index 0000000000000..d9919cd7fee45 --- /dev/null +++ b/pkgs/by-name/cu/cue/tests/001-all-good.nix @@ -0,0 +1,11 @@ +{ lib +, cue +, runCommand +}: + +runCommand "cue-test-001-all-good-${cue.version}" { + nativeBuildInputs = [ cue ]; + meta.timeout = 10; +} '' + cue eval - <<<'a: "all good"' > $out + '' diff --git a/pkgs/by-name/cu/cue/validator.nix b/pkgs/by-name/cu/cue/validator.nix new file mode 100644 index 0000000000000..cddc3fe342b72 --- /dev/null +++ b/pkgs/by-name/cu/cue/validator.nix @@ -0,0 +1,17 @@ +{ cue, writeShellScript, lib }: +# `document` must be a fragment of definition or structure that the input data will be matched against. +# `document` must exist in the Cue schema file provided (`cueSchemaFile`). +# The result is a script that can be used to validate the input data (JSON/YAML and more can be supported depending on Cue) +# against the fragment described by `document` or the whole definition. +# The script will be strict and enforce concrete values, i.e. partial documents are not supported. +cueSchemaFile: { document ? null }: + writeShellScript "validate-using-cue" + ''${cue}/bin/cue \ + --all-errors \ + --strict \ + vet \ + --concrete \ + "$1" \ + ${cueSchemaFile} \ + ${lib.optionalString (document != null) "-d \"${document}\""} + '' |