/nix/store/ap7nr6hb3q9zhphcy2s2bmxvvv
g1yzcq-nim-unwrapped-1.4.8/nim/lib/pu
re/dynlib.nim(110, 25) Error: undecla
red identifier:
"getEnv'
This might be caused by a recursive m
odule dependency:
/nix/store/ap7nr6hb3q9zhphcy2s2bmxvvV
g1yzcq-nim-unwrapped-1.4.8/nim/lib/pu
re/os.nim imports /nix/store/ap7nr6hb
3q9zhphcy2s2bmxvvvg1yzcq-nim-unwrappe
d-1.4.8/nim/lib/windows/winlean.nim
/nix/store/ap7nr6hb3q9zhphcy2s2bmxvVV
g1yzcq-nim-unwrapped-1.4.8/nim/lib/wi
ndows/winlean.nim imports /nix/store/
ap7nr6hb3q9zhphcy2s2bmxvvvg1yzcq-nim-
unwrapped-1.4.8/nim/lib/pure/dynlib.nim
/nix/store/ap7nr6hb3q9zhphcy2s2bmxvVV
g1yzcq-nim-unwrapped-1.4.8/nim/lib/pu
re/dynlib.nim imports /nix/store/ap7n
r6hb3q9zhphcy2s2bmxvvvg1yzcq-nim-unwr
apped-1.4.8/nim/lib/pure/os.nim
When compiling with this cmd:
nim compile -d:mingw path/to/myfile
My imports in my file are:
import std/httpclient
import std/json
import std/strformat
import std/strutils
import std/tables
import std/os
Why would this happen? This only affects cross-compiling, normal compiling works fine. Any help would be appreciated.
This is a problem that apparently is caused by a local patch that the NixOS devs are applying to nim.
From a high-level view, it seems that the patch is trying to call getEnv while trying to resolve the mingw dynlib dependencies.
To demonstrate you can give it a try with (this will compile nim without the patch):
nix-shell -p 'nim-unwrapped.overrideAttrs (old: {patches = []; })' pkgsCross.mingwW64.buildPackages.gcc`
Add a nim.cfg with the path to the bin dir of the mingw gcc: dirname $(which x86_64-w64-mingw32-gcc), resulting in something like:
amd64.windows.gcc.path = "/nix/store/x4x1gjdxcfln8jprf6vfnkqplb361822-x86_64-w64-mingw32-stage-final-gcc-debug-wrapper-11.3.0/bin"
And then compile as usual nim c -d:mingw <file.nim>