mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
Merge pull request #14269 from roberth/json-schema
Add a JSON Schema for `Derivation`
This commit is contained in:
commit
b56e456b0d
25 changed files with 480 additions and 124 deletions
1
src/json-schema-checks/.version
Symbolic link
1
src/json-schema-checks/.version
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../.version
|
||||
1
src/json-schema-checks/derivation
Symbolic link
1
src/json-schema-checks/derivation
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../src/libstore-tests/data/derivation
|
||||
76
src/json-schema-checks/meson.build
Normal file
76
src/json-schema-checks/meson.build
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# Run with:
|
||||
# meson test --suite json-schema
|
||||
# Run with: (without shell / configure)
|
||||
# nix build .#nix-json-schema-checks
|
||||
|
||||
project(
|
||||
'nix-json-schema-checks',
|
||||
version : files('.version'),
|
||||
meson_version : '>= 1.1',
|
||||
license : 'LGPL-2.1-or-later',
|
||||
)
|
||||
|
||||
fs = import('fs')
|
||||
|
||||
# Note: The 'jsonschema' package provides the 'jv' command
|
||||
jv = find_program('jv', required : true)
|
||||
|
||||
# The schema directory is a committed symlink to the actual schema location
|
||||
schema_dir = meson.current_source_dir() / 'schema'
|
||||
|
||||
# Get all example files
|
||||
schemas = [
|
||||
{
|
||||
'stem' : 'derivation',
|
||||
'schema' : schema_dir / 'derivation-v3.yaml',
|
||||
'files' : [
|
||||
'dyn-dep-derivation.json',
|
||||
'simple-derivation.json',
|
||||
],
|
||||
},
|
||||
# # Not sure how to make subschema work
|
||||
# {
|
||||
# 'stem': 'derivation',
|
||||
# 'schema': schema_dir / 'derivation-v3.yaml#output',
|
||||
# 'files' : [
|
||||
# 'output-caFixedFlat.json',
|
||||
# 'output-caFixedNAR.json',
|
||||
# 'output-caFixedText.json',
|
||||
# 'output-caFloating.json',
|
||||
# 'output-deferred.json',
|
||||
# 'output-impure.json',
|
||||
# 'output-inputAddressed.json',
|
||||
# ],
|
||||
# },
|
||||
]
|
||||
|
||||
# Validate each example against the schema
|
||||
foreach schema : schemas
|
||||
stem = schema['stem']
|
||||
schema_file = schema['schema']
|
||||
if '#' not in schema_file
|
||||
# Validate the schema itself against JSON Schema Draft 04
|
||||
test(
|
||||
stem + '-schema-valid',
|
||||
jv,
|
||||
args : [
|
||||
'--map',
|
||||
'./hash-v1.yaml=' + schema_dir / 'hash-v1.yaml',
|
||||
'http://json-schema.org/draft-04/schema',
|
||||
schema_file,
|
||||
],
|
||||
suite : 'json-schema',
|
||||
)
|
||||
endif
|
||||
foreach example : schema['files']
|
||||
test(
|
||||
stem + '-example-' + fs.stem(example),
|
||||
jv,
|
||||
args : [
|
||||
schema_file,
|
||||
files(stem / example),
|
||||
],
|
||||
suite : 'json-schema',
|
||||
)
|
||||
endforeach
|
||||
endforeach
|
||||
50
src/json-schema-checks/package.nix
Normal file
50
src/json-schema-checks/package.nix
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
# Run with: nix build .#nix-json-schema-checks
|
||||
{
|
||||
lib,
|
||||
mkMesonDerivation,
|
||||
|
||||
meson,
|
||||
ninja,
|
||||
jsonschema,
|
||||
|
||||
# Configuration Options
|
||||
|
||||
version,
|
||||
}:
|
||||
|
||||
mkMesonDerivation (finalAttrs: {
|
||||
pname = "nix-json-schema-checks";
|
||||
inherit version;
|
||||
|
||||
workDir = ./.;
|
||||
fileset = lib.fileset.unions [
|
||||
../../.version
|
||||
../../doc/manual/source/protocols/json/schema
|
||||
../../src/libstore-tests/data/derivation
|
||||
./.
|
||||
];
|
||||
|
||||
outputs = [ "out" ];
|
||||
|
||||
passthru.externalNativeBuildInputs = [
|
||||
jsonschema
|
||||
];
|
||||
|
||||
nativeBuildInputs = [
|
||||
meson
|
||||
ninja
|
||||
]
|
||||
++ finalAttrs.passthru.externalNativeBuildInputs;
|
||||
|
||||
doCheck = true;
|
||||
|
||||
mesonCheckFlags = [ "--print-errorlogs" ];
|
||||
|
||||
postInstall = ''
|
||||
touch $out
|
||||
'';
|
||||
|
||||
meta = {
|
||||
platforms = lib.platforms.all;
|
||||
};
|
||||
})
|
||||
1
src/json-schema-checks/schema
Symbolic link
1
src/json-schema-checks/schema
Symbolic link
|
|
@ -0,0 +1 @@
|
|||
../../doc/manual/source/protocols/json/schema
|
||||
|
|
@ -12,8 +12,7 @@ a Nix expression evaluates.
|
|||
|
||||
[store derivation]: @docroot@/glossary.md#gloss-store-derivation
|
||||
|
||||
`nix derivation add` takes a single derivation in the following format:
|
||||
|
||||
{{#include ../../protocols/json/derivation.md}}
|
||||
`nix derivation add` takes a single derivation in the JSON format.
|
||||
See [the manual](@docroot@/protocols/json/derivation.md) for a documentation of this format.
|
||||
|
||||
)""
|
||||
|
|
|
|||
|
|
@ -48,10 +48,9 @@ By default, this command only shows top-level derivations, but with
|
|||
|
||||
[store derivation]: @docroot@/glossary.md#gloss-store-derivation
|
||||
|
||||
`nix derivation show` outputs a JSON map of [store path]s to derivations in the following format:
|
||||
`nix derivation show` outputs a JSON map of [store path]s to derivations in JSON format.
|
||||
See [the manual](@docroot@/protocols/json/derivation.md) for a documentation of this format.
|
||||
|
||||
[store path]: @docroot@/store/store-path.md
|
||||
|
||||
{{#include ../../protocols/json/derivation.md}}
|
||||
|
||||
)""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue