sakalli
sakalli

Reputation: 93

How to install R and packages through configuration.nix and how to add packages from github?

Two related questions:
1. How does one install R and selected packages in the configuration.nix?
2. How does one add packages not only from CRAN but also from Gitub or at least locally stored?

In the wiki you will find instructions like these to install R packages. https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/r.section.md . Have it working when using nix-shell but I'm stuck while trying to do the installation from configuration.nix.

Regarding building R packages and I have found this example regarding building packages:

let
  pkgs = import <nixpkgs> {};
  buildRPackage = import <nixpkgs/pkgs/development/r-modules/generic-builder.nix> pkgs.R;
 in
 with pkgs.rPackages;
 {
   foobar = buildRPackage {
     name = "your-package-name-1.0";
     src = ./.;
     propagatedBuildInputs = [/* required dependencies go here */];
   };
 }

The command "nix-build . -A foobar" would then compile it.

But would like to run all from configuration.nix in order to the machine configuration in one place.

Upvotes: 3

Views: 2035

Answers (1)

sakalli
sakalli

Reputation: 93

Ok, with the help of Bulats pointer above I managed to find a solution. A complete example was found here: https://github.com/NixOS/nixpkgs/issues/44290

For future reference here is one way of adding r packages both from CRAN and Github inline in configuration.nix:

environment.systemPackages = with pkgs;
   [(pkgs.rWrapper.override {
     packages = with pkgs.rPackages; let
       llr = buildRPackage {
       name = "llr";
       src = pkgs.fetchFromGitHub {
        owner = "dirkschumacher";
        repo = "llr";
        rev = "0a654d469af231e9017e1100f00df47bae212b2c";
        sha256 = "0ks96m35z73nf2sb1cb8d7dv8hq8dcmxxhc61dnllrwxqq9m36lr";};
     propagatedBuildInputs = [ rlang  knitr];
     nativeBuildInputs = [ rlang knitr ];};
    in [knitr
        rlang
        llr
        tidyverse
        ## the rest of your R packages here
        devtools];})
    pkgs.postgresql
    pkgs.isync
    pkgs.msmtp
    pkgs.notmuch
    gnupg
    ## the rest of your Nixos packages (derivations) here
    ];

Upvotes: 5

Related Questions