From ba7be2f0512d71474b2ee5715b886efb3321dd3c Mon Sep 17 00:00:00 2001 From: Francesco Gazzetta Date: Fri, 10 Apr 2026 22:01:03 +0200 Subject: [PATCH] tcl.tclRequiresCheckHook: use structuredAttrs... structurally Preserve the structure of tclRequiresCheck when using structuredAttrs instead of relying on it being a space-separated string. Shouldn't be necessary since package names don't usually contain spaces or braces, but you never know. --- .../tcl/tcl-requires-check-hook.sh | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/pkgs/development/interpreters/tcl/tcl-requires-check-hook.sh b/pkgs/development/interpreters/tcl/tcl-requires-check-hook.sh index 9cf55c1f72c2..76c5901f2a33 100644 --- a/pkgs/development/interpreters/tcl/tcl-requires-check-hook.sh +++ b/pkgs/development/interpreters/tcl/tcl-requires-check-hook.sh @@ -5,9 +5,28 @@ tclRequiresCheckPhase () { echo "Executing tclRequiresCheckPhase" if [ -n "$tclRequiresCheck" ]; then - echo "Check whether the following packages can be required: ${tclRequiresCheck[*]}" export TCLLIBPATH="$out/lib $TCLLIBPATH" # Redundant if tcl-package-hook is also used - tclRequiresCheck="${tclRequiresCheck[@]}" tclsh <<<'exit [catch {foreach req $env(tclRequiresCheck) {package require $req}}]' + tclsh <<'EOF' + if {[info exists env(NIX_ATTRS_JSON_FILE)]} { + set nix_attrs_json_file [open $env(NIX_ATTRS_JSON_FILE)] + set nix_attrs_json [read $nix_attrs_json_file] + close $nix_attrs_json_file + # Normally we'd use one of tcllib/tdom/rl_json/yajl-tcl to parse JSON, + # however we don't want to introduce a circular dependency, + # so we rely on the JSON capabilities of the builtin sqlite package + # https://wiki.tcl-lang.org/page/SQLite+extension+JSON1 + package require sqlite3 + sqlite3 db :memory: -readonly 1 + set packages_to_check [db eval { + select value from json_each(jsonb_extract($nix_attrs_json, '$.tclRequiresCheck')) + }] + db close + } else { + set packages_to_check $env(tclRequiresCheck) + } + puts "Check whether the following packages can be required: $packages_to_check" + exit [catch {foreach pkg $packages_to_check {package require $pkg}}] +EOF fi }