Linking a compiled library for perlPackages

I’m working through [WIP] perlPackages.TclpTk: init at 1.09 by willcohen · Pull Request #175775 · NixOS/nixpkgs · GitHub and running into a linking error with perlPackages.Tcl. It builds correctly when testing on darwin, and when running Nix on Debian. However, when trying to build the Tcl perl package on NixOS, or when trying to use that PR’s branch as the nixpkgs input on a flake, the package fails to build:

$ nix-build . -A perlPackages.Tcl
this derivation will be built:
building '/nix/store/2ywybyjgjl135fm3gag09y6vm0sj4adb-perl5.34.1-Tcl-1.27.drv'...
unpacking sources
unpacking source archive /nix/store/szhzqhm5fx4nwb14zzpaahvc6h50bn2b-Tcl-1.27.tar.gz
source root is Tcl-1.27
setting SOURCE_DATE_EPOCH to timestamp 1534927502 of file Tcl-1.27/MANIFEST
patching sources
LIBS   = /nix/store/mbj5zlg9sg9ndrayjfs6w4plgac86gxc-tcl-8.6.11
INC    = /nix/store/mbj5zlg9sg9ndrayjfs6w4plgac86gxc-tcl-8.6.11
Checking if your kit is complete...
Looks good
Unrecognized argument in LIBS ignored: '/nix/store/mbj5zlg9sg9ndrayjfs6w4plgac86gxc-tcl-8.6.11'
Generating a Unix-style Makefile
Writing Makefile for Tcl
Writing MYMETA.yml and MYMETA.json
no configure script, doing nothing
build flags: SHELL=/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash
cp blib/lib/
Running Mkbootstrap for Tcl ()
chmod 644 ""
"/nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- blib/arch/auto/Tcl/ 644
"/nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/bin/perl" "/nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/lib/perl5/5.34.1/ExtUtils/xsubpp"  -typemap '/nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/lib/perl5/5.34.1/ExtUtils/typemap' -typemap '/build/Tcl-1.27/typemap'  Tcl.xs > Tcl.xsc
Please specify prototyping behavior for Tcl.xs (see perlxs manual)
mv Tcl.xsc Tcl.c
cc -c  /nix/store/mbj5zlg9sg9ndrayjfs6w4plgac86gxc-tcl-8.6.11 -D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/no-such-path/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2   -DVERSION=\"1.27\" -DXS_VERSION=\"1.27\" -fPIC "-I/nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/lib/perl5/5.34.1/x86_64-linux-thread-multi/CORE"  -DUSE_TCL_STUBS Tcl.c
gcc: warning: /nix/store/mbj5zlg9sg9ndrayjfs6w4plgac86gxc-tcl-8.6.11: linker input file unused because linking not done
rm -f blib/arch/auto/Tcl/
cc  -shared -O2 -L/nix/store/lyl6nysc3i3aqhj6shizjgj0ibnf1pvg-glibc-2.34-210/lib -fstack-protector-strong  Tcl.o  -o blib/arch/auto/Tcl/  \

chmod 755 blib/arch/auto/Tcl/
Manifying 1 pod document
running tests
check flags: SHELL=/nix/store/0d3wgx8x6dxdb2cpnq105z23hah07z7l-bash-5.1-p16/bin/bash VERBOSE=y test
"/nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- blib/arch/auto/Tcl/ 644
PERL_DL_NONLAZY=1 "/nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/bin/perl" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/call.t ............. Can't load '/build/Tcl-1.27/blib/arch/auto/Tcl/' for module Tcl: /build/Tcl-1.27/blib/arch/auto/Tcl/ undefined symbol: tclStubsPtr at /nix/store/hpppiam2slc5x9jbf7g67051bygf0bzi-perl-5.34.1/lib/perl5/5.34.1/x86_64-linux-thread-multi/ line 193.
 at t/call.t line 6.
Compilation failed in require at t/call.t line 6.
BEGIN failed--compilation aborted at t/call.t line 6.
t/call.t ............. Dubious, test returned 255 (wstat 65280, 0xff00)
No subtests run

Per the CPAN Makefile.PL, I’m trying to include --library and --include, and --tclsh for good measure, in makeMakerFlags, but gcc is now erroring out with “linker input file unused because linking not done.”

I assume that clang is less ornery about the darwin dylibs, but I’m at a loss for how to get this to build successfully on Linux. Any ideas?

In the end, simpler than I thought:

makeMakerFlags = lib.optionalString stdenv.isLinux
      "--tclsh=${pkgs.tcl}/bin/tclsh --nousestubs";