pkgs.formats: add cdn

This commit is contained in:
uku
2025-01-06 11:57:41 +01:00
parent 127ea1b5a8
commit 141f581d6f
3 changed files with 72 additions and 0 deletions
+5
View File
@@ -5,6 +5,7 @@
gradle_8,
jre_headless,
makeBinaryWrapper,
tests,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "json2cdn";
@@ -42,6 +43,10 @@ stdenv.mkDerivation (finalAttrs: {
runHook postInstall
'';
passthru = {
tests.formats-cdn = tests.pkgs-lib.formats.passthru.entries.pass-cdnAtoms;
};
meta = {
description = "Converts a JSON file to dzikoysk's CDN format";
homepage = "https://github.com/uku3lig/json2cdn";
+33
View File
@@ -310,6 +310,39 @@ rec {
};
/* dzikoysk's CDN format, see https://github.com/dzikoysk/cdn
The result is almost identical to YAML when there are no nested properties,
but differs enough in the other case to warrant a separate format.
(see https://github.com/dzikoysk/cdn#supported-formats)
Currently used by Panda, Reposilite, and FunnyGuilds (as per the repo's readme).
*/
cdn = {}: json {} // {
type = let
valueType = nullOr (oneOf [
bool
int
float
str
path
(attrsOf valueType)
(listOf valueType)
]) // {
description = "CDN value";
};
in valueType;
generate = name: value: pkgs.callPackage ({ runCommand, json2cdn }: runCommand name {
nativeBuildInputs = [ json2cdn ];
value = builtins.toJSON value;
passAsFile = [ "value" ];
preferLocalBuild = true;
} ''
json2cdn "$valuePath" > $out
'') {};
};
/* For configurations of Elixir project, like config.exs or runtime.exs
Most Elixir project are configured using the [Config] Elixir DSL
+34
View File
@@ -533,6 +533,40 @@ in runBuildTests {
'';
};
cdnAtoms = shouldPass {
format = formats.cdn { };
input = {
null = null;
false = false;
true = true;
int = 10;
float = 3.141;
str = "foo";
attrs.foo = null;
list = [
1
null
];
path = ./formats.nix;
};
expected = ''
attrs {
"foo": null
}
"false": false
"float": 3.141
"int": 10
list [
1,
null
]
"null": null
"path": "${./formats.nix}"
"str": "foo"
"true": true
'';
};
# This test is responsible for
# 1. testing type coercions
# 2. providing a more readable example test