diff --git a/pkgs/by-name/go/go-toml/package.nix b/pkgs/by-name/go/go-toml/package.nix index e18ac104f70d..5ea5e58c51ea 100644 --- a/pkgs/by-name/go/go-toml/package.nix +++ b/pkgs/by-name/go/go-toml/package.nix @@ -25,10 +25,6 @@ buildGoModule { "cmd/tomltestgen" ]; - # allowGoReference adds the flag `-trimpath` which is also denoted by, go-toml's goreleaser config - # - allowGoReference = true; - ldflags = [ "-s" "-w" diff --git a/pkgs/pkgs-lib/formats.nix b/pkgs/pkgs-lib/formats.nix index 9478a11f83f6..0e0c9368fab1 100644 --- a/pkgs/pkgs-lib/formats.nix +++ b/pkgs/pkgs-lib/formats.nix @@ -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" '' ) { }; diff --git a/pkgs/pkgs-lib/tests/formats.nix b/pkgs/pkgs-lib/tests/formats.nix index d51b5d2f272b..49b9ac4c8a30 100644 --- a/pkgs/pkgs-lib/tests/formats.nix +++ b/pkgs/pkgs-lib/tests/formats.nix @@ -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' ''; };