placeybordeaux
placeybordeaux

Reputation: 2216

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

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?

Upvotes: 4

Views: 410

Answers (1)

placeybordeaux
placeybordeaux

Reputation: 2216

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!

Upvotes: 5

Related Questions