How to add a create a a environment with the R package data.table with Nix

57 Views Asked by At
 {   description = "virtual environment with Rstudio, R, Shiny";  
 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";  
 inputs.flake-utils.url = "github:numtide/flake-utils";
 
   outputs = { self, nixpkgs, flake-utils }:
     flake-utils.lib.eachDefaultSystem (system:
       let
         pkgs = nixpkgs.legacyPackages.${system};
 
         rWrapper=pkgs.rWrapper;
         rstudioWrapper=pkgs.rstudioWrapper;
         rstudioServerWrapper=pkgs.rstudioServerWrapper;
         Rpackages=with pkgs.rPackages;[
           shiny
           data.table
         ];
 
         RwithPackages=   rWrapper.override{ packages =  Rpackages;};
         RStudio-with-my-packages = rstudioWrapper.override{ packages = Rpackages; };
 
 
         myDevTools = [
           #qtbase #patch
           RwithPackages
           RStudio-with-my-packages
         ];
       in {
         devShells.default = pkgs.mkShell {
           buildInputs = myDevTools;
         };
       }); }

This doesn't work

error: undefined variable 'data'

the problem is that nix doesn't accept name with . in the middle. The package data.table has been stored under another name.

How to find it

1

There are 1 best solutions below

0
On

If somebody has a quicker solution, please say it.

This work but this is a little cubersome.

All nix packages are defined there:

https://github.com/NixOS/nixpkgs/blob/master/pkgs/top-level/all-packages.nix

search rpackage in this file

rPackages = dontRecurseIntoAttrs (callPackage ../development/r-modules { overrides = (config.rPackageOverrides or (_: {})) pkgs; });

use the github search bar with development/r-modules cran-package looks like a good match https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/r-modules/cran-packages.nix

search for data.table

data_table = derive2 { name="data.table"; version="1.14.8"; sha256="1z9rf5anjvg3bmbbajb12nf65jsxdw35ad9piysrp76zcx9wxchl"; depends=[]; };

This line give the information. Now it should work

 {   description = "virtual environment with Rstudio, R, Shiny";  
 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";  
 inputs.flake-utils.url = "github:numtide/flake-utils";
 
   outputs = { self, nixpkgs, flake-utils }:
     flake-utils.lib.eachDefaultSystem (system:
       let
         pkgs = nixpkgs.legacyPackages.${system};
 
         rWrapper=pkgs.rWrapper;
         rstudioWrapper=pkgs.rstudioWrapper;
         rstudioServerWrapper=pkgs.rstudioServerWrapper;
         Rpackages=with pkgs.rPackages;[
           shiny
           data_table
         ];
 
         RwithPackages=   rWrapper.override{ packages =  Rpackages;};
         RStudio-with-my-packages = rstudioWrapper.override{ packages = Rpackages; };
 
 
         myDevTools = [
           #qtbase #patch
           RwithPackages
           RStudio-with-my-packages
         ];
       in {
         devShells.default = pkgs.mkShell {
           buildInputs = myDevTools;
         };
       }); }