I’m trying to get setup to use the “nim” compiler (https://nim-lang.org/).
I’ve got a nix-shell setup with niv to use nixpkgs-unstable get the latest nim compiler (1.4.2).
I’ve got a test nim script from their site that I’m trying to compile.
When I run nim compile test.nim
, I get unresolved errors:
$ nim compile test.nim
Hint: used config file '/nix/store/92r6yp0i2n3wb5mv1fr6wfpv57dm5h8q-x86_64-unknown-linux-gnu-nim-wrapper-1.4.2/etc/nim/nim.cfg' [Conf]
....CC: stdlib_io.nim
CC: stdlib_system.nim
/bin/sh: symbol lookup error: /nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libc.so.6: undefined symbol: _dl_fatal_printf, version GLIBC_PRIVATE
CC: test.nim
/bin/sh: symbol lookup error: /nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libc.so.6: undefined symbol: _dl_fatal_printf, version GLIBC_PRIVATE
Error: execution of an external compiler program 'gcc -c -w -fmax-errors=3 -I/nix/store/impyg4875ygammahsaa73s7w6h91wpmz-nim-unwrapped-1.4.2/nim/lib -I/home/adam/Workspace/nim-test -o /home/adam/.cache/nim/test_d/stdlib_io.nim.c.o /home/adam/.cache/nim/test_d/stdlib_io.nim.c' failed with exit code: 127
/bin/sh: symbol lookup error: /nix/store/m0xa5bz7vw7p43wi0jppvvi3c9vgqvp7-glibc-2.32-25/lib/libc.so.6: undefined symbol: _dl_fatal_printf, version GLIBC_PRIVATE
If I run the GCC command manually, it appears to succeed.
$ gcc -c -w -fmax-errors=3 -I/nix/store/impyg4875ygammahsaa73s7w6h91wpmz-nim-unwrapped-1.4.2/nim/lib -I/home/adam/Workspace/nim-test -o /home/adam/.cache/nim/test_d/stdlib_io.nim.c.o /home/adam/.cache/nim/test_d/stdlib_io.nim.c
$ ls ~/.cache/nim/test_d/stdlib_io.nim.c
/home/adam/.cache/nim/test_d/stdlib_io.nim.c
This makes me suspect that nim isn’t running an environment aware gcc.
I’ve tried adding gcc and glibc to the buildInputs
.
I’ve also tried exporting the NIX_* compiler variables that I’m aware of.
shell.nix
# shell.nix
let
sources = import ./nix/sources.nix;
pkgs = import sources.nixpkgs {};
in
pkgs.mkShell {
nativeBuildInputs = [
];
buildInputs = [
pkgs.bashInteractive
pkgs.nim
pkgs.gcc
pkgs.glibc
];
NIMBLE_DIR = toString ./.nimble;
shellHooks = ''
export CFLAGS_COMPILE=$NIX_CFLAGS_COMPILE
export LDFLAGS=$NIX_LDFLAGS
export LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH
'';
}
test.nim
$ cat test.nim
echo "What's your name? "
var name: string = readLine(stdin)
echo "Hi, ", name, "!"