Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add a local R package using Nix package manager

Tags:

r

nix

Let's say that I have a local R package that lives at /home/placey/messyverse.tar.gz

I'd like to start up a nix shell that contains my package as well as ggplot. How do I do that?

like image 617
placeybordeaux Avatar asked Oct 26 '25 09:10

placeybordeaux


1 Answers

First we need to create a nix package that contains the necessary information for your local package.

Lets call it

messverse.nix

with import <nixpkgs> {};

{
  messverse = rPackages.buildRPackage rec {
      name = "messverse";
      version = "0.1";
      src = /home/placey/messverse.tar.gz;
      buildInputs = with rPackages; [
        R
        stringr
      ];
  };
}

Then in the same folder we will create the default.nix that defnes what is needed for the nix shell.

default.nix

with import <nixpkgs> {};
with import ./messyverse.nix;
{
    myProject = stdenv.mkDerivation {
      name = "myProject";
      version = "1";
      src = if pkgs.lib.inNixShell then null else nix;

      buildInputs = with rPackages; with messyverse; [
        R
        ggplot2
        messyverse
      ];
    };
}

now we can execute nix-shell .

and we have a shell which contains R & our locally specified R package!

like image 115
placeybordeaux Avatar answered Oct 27 '25 23:10

placeybordeaux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!