pkgs-lib/formats: use go-toml instead of yj for toml.generate, go-toml: drop allowGoReference (#512319)

This commit is contained in:
Paul Haerle
2026-04-22 10:41:19 +00:00
committed by GitHub
3 changed files with 43 additions and 10 deletions
-4
View File
@@ -25,10 +25,6 @@ buildGoModule {
"cmd/tomltestgen"
];
# allowGoReference adds the flag `-trimpath` which is also denoted by, go-toml's goreleaser config
# <https://github.com/pelletier/go-toml/blob/a3d5a0bb530b5206c728eed9cb57323061922bcb/.goreleaser.yaml#L13>
allowGoReference = true;
ldflags = [
"-s"
"-w"
+5 -3
View File
@@ -461,16 +461,18 @@ optionalAttrs allowAliases aliases
generate =
name: value:
pkgs.callPackage (
{ runCommand, yj }:
{ runCommand, go-toml }:
runCommand name
{
nativeBuildInputs = [ yj ];
nativeBuildInputs = [ go-toml ];
value = builtins.toJSON value;
passAsFile = [ "value" ];
preferLocalBuild = true;
}
# -use-json-number: preserve JSON ints as TOML ints
# (Go's json.Decoder defaults to float64 for all numbers)
''
yj -jt < "$valuePath" > "$out"
jsontoml -use-json-number < "$valuePath" > "$out"
''
) { };
+38 -3
View File
@@ -695,16 +695,51 @@ runBuildTests {
float = 3.141
int = 10
list = [1, 2]
str = "foo"
str = 'foo'
true = true
[attrs]
foo = "foo"
foo = 'foo'
[level1]
[level1.level2]
[level1.level2.level3]
level4 = "deep"
level4 = 'deep'
'';
};
# Regression test for https://github.com/NixOS/nixpkgs/issues/511970
# yj crashes on arrays mixing scalars and attrsets (heterogeneous arrays),
# e.g. Helix language-server configs like ["bash-ls", {name = "ts-ls"; ...}].
# TOML 1.0 allows mixed-type arrays; the converter must emit them as
# inline arrays with inline tables.
tomlHeterogeneousArray = shouldPass {
format = formats.toml { };
input = {
language-server = [
"bash-language-server"
{
name = "typescript-language-server";
except-features = [ "diagnostics" ];
}
];
};
expected = ''
language-server = ['bash-language-server', {except-features = ['diagnostics'], name = 'typescript-language-server'}]
'';
};
# Regression test for https://github.com/sclevine/yj/issues/52
# yj truncates keys at the first comma because it stores TOML keys in Go
# struct tags, where commas are option separators.
# e.g. "stack(x,n)" is emitted as "stack(x" — silently losing data.
tomlCommaInKey = shouldPass {
format = formats.toml { };
input = {
"stack(x,n)" = "foobar";
};
expected = ''
'stack(x,n)' = 'foobar'
'';
};