ropensci / rix

Reproducible Data Science environments for R with Nix
https://docs.ropensci.org/rix/
GNU General Public License v3.0
181 stars 15 forks source link

`rix(r_pkgs = "<rpkg@version>")` Nix expression should assign to `cran_build_pkgs` instead of `git_archive_pkgs` variable #348

Open philipp-baumann opened 1 month ago

philipp-baumann commented 1 month ago
library("rix")

rix(
  r_ver = "latest",
  r_pkgs = "rlang@1.1.3",
  project_path = ".",
  overwrite = TRUE
)

nix_build(project_path = ".")

currently produces this Nix expression

# This file was generated by the {rix} R package v0.12.4 on 2024-10-03
# with following call:
# >rix(r_ver = "1839883cd0068572aed75fb9442b508bbd9ef09c",
#  > r_pkgs = "rlang@1.1.3",
#  > project_path = "_test",
#  > overwrite = TRUE)
# It uses nixpkgs' revision 1839883cd0068572aed75fb9442b508bbd9ef09c for reproducibility purposes
# which will install R version latest.
# Report any issues to https://github.com/ropensci/rix
let
 pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/1839883cd0068572aed75fb9442b508bbd9ef09c.tar.gz") {};

  git_archive_pkgs = [ 
    (pkgs.rPackages.buildRPackage {
      name = "rlang";
      src = pkgs.fetchzip {
       url = "https://cran.r-project.org/src/contrib/Archive/rlang/rlang_1.1.3.tar.gz";
       sha256 = "sha256-+xSUK2YpQHE0sezKMngihHVKG0r63b6OuJb6136qgRM=";
      };
      propagatedBuildInputs = builtins.attrValues {
        inherit (pkgs.rPackages) ;
      };
    })
  ];

  system_packages = builtins.attrValues {
    inherit (pkgs) 
      glibcLocales
      nix
      R;
  };

in

pkgs.mkShell {
  LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocales}/lib/locale/locale-archive" else "";
  LANG = "en_US.UTF-8";
   LC_ALL = "en_US.UTF-8";
   LC_TIME = "en_US.UTF-8";
   LC_MONETARY = "en_US.UTF-8";
   LC_PAPER = "en_US.UTF-8";
   LC_MEASUREMENT = "en_US.UTF-8";

  buildInputs = [ git_archive_pkgs   system_packages   ];

}

It should be tagged under cran_build_pkgs. Its the same hashing procedure, but semantically its not a git archive.

b-rodrigues commented 1 month ago

Right, but I wonder if this will not be removed anyways with what we’re planning to do with renv2nix(). If we go that route, then something like rlang@1.1.3 would be pulled from its specific nixpkgs revision instead like so:

let
 pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/019f5c29c5afeb215587e17bf1ec31dc1913595b.tar.gz") {};
 old_dplyr = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/a4684b5462b6c66dd7ad2a7dfb2e5c1fca5582e4.tar.gz") {};

  rpkgs = builtins.attrValues {
    inherit (pkgs.rPackages) 
      ggplot2
      languageserver;
  };

  system_packages = builtins.attrValues {
    inherit (pkgs) 
      glibcLocales
      nix
      R;
  };

in

pkgs.mkShell {
  LOCALE_ARCHIVE = if pkgs.system == "x86_64-linux" then "${pkgs.glibcLocales}/lib/locale/locale-archive" else "";
  LANG = "en_US.UTF-8";
   LC_ALL = "en_US.UTF-8";
   LC_TIME = "en_US.UTF-8";
   LC_MONETARY = "en_US.UTF-8";
   LC_PAPER = "en_US.UTF-8";
   LC_MEASUREMENT = "en_US.UTF-8";

  buildInputs = [  rpkgs  system_packages old_dplyr.rPackages.dplyr  ];

}

so maybe we can just leave this for now, because we would end up removing it once we start using dedicated nixpkgs revisions for individual packages.