NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.51k stars 13.69k forks source link

can't install kernel with JuniperKernel #38733

Open krey opened 6 years ago

krey commented 6 years ago

Issue description

When JuniperKernel installs the kernelspec, it uses $R_HOME to figure out where the R executable lives. $R_HOME is set to unwrapped R (see below) which doesn't have any of the packages, so the kernelspec produced is wrong. When used inside jupyter, it will not be able to find Juniper and the kernel will not work.

Related: https://github.com/NixOS/nixpkgs/issues/16485#issuecomment-259832281

Steps to reproduce

> nix-shell -p "rWrapper.override{ packages = with rPackages; [JuniperKernel]; }" 
> R --slave -e "JuniperKernel::installJuniper(prefix='/tmp')"
...
> cat /tmp/share/jupyter/kernels/juniper_r3.4.3/kernel.json 
{
  "argv": ["/nix/store/lkf89b6lpkzp96cahswcsfs83qxy759z-R-3.4.3/lib/R/bin/R", "--slave", "-e", "JuniperKernel::bootKernel()", "--args", "{connection_file}"],
  "display_name": "R 3.4.3 (Juniper)",
  "language": "R"
}

but that's the wrong R (the unwrapped one). The right one is:

> readlink -f `which R`
/nix/store/s39mhjww2wvk4v6gmlmcjydxr379mq0s-R-3.4.3-wrapper/bin/R
> JUPYTER_PATH=/tmp/share/jupyter jupyter notebook
...open a notebook...
Error in loadNamespace(name) : there is no package called ‘JuniperKernel’
Calls: :: ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

Further thoughts

One of the key things rWrapper does is to set $R_LIBS_SITE:

> cat `which R`
#! /nix/store/zqh3l3lyw32q1ayb15bnvg9f24j5v2p0-bash-4.4-p12/bin/bash -e
export R_LIBS_SITE='/nix/store/ab4w1rfq4say1vk5mahplf6bp8na9dna-r-boot-1.3-20/library:/nix/store/r2zns9ivqrbjw53596rlals4ayfi1l1r-r-class-7.3-14/library:/nix/store/bdf7ppplrqnr145c8bxasqk37ab7xqz9-r-MASS-7.3-48/library:/nix/store/2da5qfiyccw3lvyd80p627hqw5qs7a1r-r-cluster-2.0.6/library:/nix/store/9ri478zvkr2siq8vimy28dpp5q04xvdw-r-codetools-0.2-15/library:/nix/store/nycfvgspc97qglyws2mv1iim68njwg9q-r-foreign-0.8-69/library:/nix/store/fmbsp9x2p164k8czdkpphas9hi9qfwiv-r-KernSmooth-2.23-15/library:/nix/store/8gp36fycay244hj3h35ny8zlj4darp55-r-lattice-0.20-35/library:/nix/store/b77qwvmppjihy7q48yn4vzfq8p5yanqs-r-Matrix-1.2-12/library:/nix/store/jyw37m97qvn5gzdlzjk28sd09bv1r84g-r-mgcv-1.8-23/library:/nix/store/s6an1j4am6fpvgjlmqb1hfvnhgkvzas1-r-nlme-3.1-131.1/library:/nix/store/s6an1j4am6fpvgjlmqb1hfvnhgkvzas1-r-nlme-3.1-131.1/library:/nix/store/nwi1zpm1lrpjvj9khlihcr19nnky11id-r-nnet-7.3-12/library:/nix/store/8vdgf29isw98bb11lx5v1j5m98gzza5d-r-rpart-4.1-12/library:/nix/store/9v7sjln0bm4ml31byk81zlj7a78044hm-r-spatial-7.3-11/library:/nix/store/1garhfa7g4nasxs40shlqb5dy9fbljrn-r-survival-2.41-3/library:/nix/store/wv2nfs2nhvni654sw9lrqyw26qzq19f4-r-JuniperKernel-1.2.3.0/library:/nix/store/x4c1vjqyjc2a3n1mwv043wk6r0f37icg-r-data.table-1.10.4-3/library:/nix/store/mp5gf8ci592w9zw4rry0gqfm1wxdpvj3-r-gdtools-0.1.6/library:/nix/store/s92s0msxjc9sd8gz3lgzkb6ji23c7x7r-r-Rcpp-0.12.15/library:/nix/store/pc0mb8m71108l9kcn5bdzjwzwj8fz6dw-r-withr-2.1.1/library:/nix/store/q2mzbyx2fxg6lplycbmr55m9697r2zzb-r-jsonlite-1.5/library:/nix/store/q9a4mp105ayqd67pdlycj44ljii97812-r-pbdZMQ-0.3-2/library:/nix/store/rws0lq3fa674gin89c3w08jxsjmn1pmi-r-repr-0.12.0/library'${R_LIBS_SITE:+':'}$R_LIBS_SITE
exec "/nix/store/lkf89b6lpkzp96cahswcsfs83qxy759z-R-3.4.3/bin/R"  "${extraFlagsArray[@]}" "$@"

It would be cool if this was exposed in some way and I could do source ${my-R-env}/bin/activate.

My current workaround is unpleasant

> JUPYTER_PATH=/tmp/share/jupyter R --slave -e "system2('jupyter', 'notebook')"

Technical details

teto commented 6 years ago

hopefully https://github.com/NixOS/nixpkgs/pull/33673 will improve the situation

krey commented 6 years ago

@teto: I see. So in that framework you write the kernels by hand, rather than relying on the installer.

teto commented 6 years ago

It's not complete yet. Some packages provide kernels (sage for instance) so the framework could accept a list of packages instead. (easier than writing the kernels by oneself)

stale[bot] commented 4 years ago

Thank you for your contributions.

This has been automatically marked as stale because it has had no activity for 180 days.

If this is still important to you, we ask that you leave a comment below. Your comment can be as simple as "still important to me". This lets people see that at least one person still cares about this. Someone will have to do this at most twice a year if there is no other activity.

Here are suggestions that might help resolve this more quickly:

  1. Search for maintainers and people that previously touched the related code and @ mention them in a comment.
  2. Ask on the NixOS Discourse.
  3. Ask on the #nixos channel on irc.freenode.net.
alexvorobiev commented 3 years ago

This is still important to me.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

alexvorobiev commented 3 years ago

This is still important to me.

stale[bot] commented 2 years ago

I marked this as stale due to inactivity. → More info

alexvorobiev commented 2 years ago

Still important