r-lib / pkgbuild

Find tools needed to build R packages
https://pkgbuild.r-lib.org
Other
65 stars 33 forks source link

pkgbuild::has_compiler fails on NixOS #101

Closed richardfergie closed 2 years ago

richardfergie commented 4 years ago

When running pkgbuild::has_compiler(debug=TRUE) on NixOS I get the following error:

Trying to compile a simple C file
Running /nix/store/1dv1hi5sc3kqgyb52dlik8s7czfmls9b-R-3.6.1/lib/R/bin/R CMD \
  SHLIB foo.c
*** buffer overflow detected ***: /nix/store/1dv1hi5sc3kqgyb52dlik8s7czfmls9b-R-3.6.1/lib/R/bin/exec/R terminated
/nix/store/1dv1hi5sc3kqgyb52dlik8s7czfmls9b-R-3.6.1/lib/R/bin/SHLIB: line 4: 30946 Done                    echo 'tools:::.SHLIB()'
     30947 Aborted                 (core dumped) | R_DEFAULT_PACKAGES=NULL "${R_HOME}/bin/R" --no-restore --slave --no-site-file --no-init-file --args $@

However, running R CMD SHLIB foo.c with foo.c as defined at https://github.com/r-lib/pkgbuild/blob/7b3f1420b97be9821e19a789574e8ecfc491825e/R/compiler.R#L23 I do not get an error.

I've tried manually running the call to rcmd_safe at https://github.com/r-lib/pkgbuild/blob/7b3f1420b97be9821e19a789574e8ecfc491825e/R/compiler.R#L30 and I get the same error.

Changing rcmd_safe to rcmd or rcmd_copycat gives the same error message so I'm not really sure how to proceed.

jimhester commented 3 years ago

Sorry I don't know anything about NixOS, nor why this would occur there.

richardfergie commented 3 years ago

https://discourse.mc-stan.org/t/rstan-on-nixos/17048/11 suggests that it because NixOS sets env vars that are excessively long.

Sounds like this is a fix that will happen in Nix rather than in pkgbuild