From 32c7a5e0469e220b716188d4cc16aff7f143a7d1 Mon Sep 17 00:00:00 2001 From: phaer Date: Wed, 22 Apr 2026 11:49:31 +0200 Subject: [PATCH 1/3] pkgs-lib/formats: add regression tests for toml generator Add two shouldPass tests that catch known yj regressions: - tomlHeterogeneousArray: arrays mixing scalars and attrsets crash yj with 'unexpected primitive type' (NixOS/nixpkgs#511970) - tomlCommaInKey: keys containing commas are silently truncated because yj stores TOML keys in Go struct tags where commas are option separators (sclevine/yj#52) Expected values are taken from go-toml's jsontoml output. Both tests fail under the current yj backend. --- pkgs/pkgs-lib/tests/formats.nix | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pkgs/pkgs-lib/tests/formats.nix b/pkgs/pkgs-lib/tests/formats.nix index d51b5d2f272b..40c096bd88f7 100644 --- a/pkgs/pkgs-lib/tests/formats.nix +++ b/pkgs/pkgs-lib/tests/formats.nix @@ -708,6 +708,41 @@ runBuildTests { ''; }; + # 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' + ''; + }; + cdnAtoms = shouldPass { format = formats.cdn { }; input = { From d5551849a5cc759afc706f87feef4a3f28d3ac6a Mon Sep 17 00:00:00 2001 From: phaer Date: Wed, 22 Apr 2026 11:49:32 +0200 Subject: [PATCH 2/3] go-toml: drop erroneous allowGoReference allowGoReference was added in 5a69b0b3c4a (2024-04-29) with the comment 'allowGoReference adds the flag -trimpath'. This is backwards: allowGoReference = true *disables* -trimpath and *allows* the Go compiler to remain in the runtime closure (257 MiB). The package builds and passes all tests without it. Dropping it re-enables -trimpath and shrinks the runtime closure from 263.6 MiB to 8.6 MiB. --- pkgs/by-name/go/go-toml/package.nix | 4 ---- 1 file changed, 4 deletions(-) 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" From e23ad3bd2739af8ac41d5338fb389029f551cde9 Mon Sep 17 00:00:00 2001 From: phaer Date: Wed, 22 Apr 2026 11:49:33 +0200 Subject: [PATCH 3/3] pkgs-lib/formats: switch toml generator from yj to go-toml (jsontoml) Fixes NixOS/nixpkgs#511970, sclevine/yj#52. Replace yj with go-toml's jsontoml for JSON-to-TOML conversion. Update tomlAtoms expected output for go-toml's literal-string style. --- pkgs/pkgs-lib/formats.nix | 8 +++++--- pkgs/pkgs-lib/tests/formats.nix | 6 +++--- 2 files changed, 8 insertions(+), 6 deletions(-) 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 40c096bd88f7..49b9ac4c8a30 100644 --- a/pkgs/pkgs-lib/tests/formats.nix +++ b/pkgs/pkgs-lib/tests/formats.nix @@ -695,16 +695,16 @@ 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' ''; };