Overlay to fix package in rPackages

I needed the R package quantreg but its dependency SparseM would fail to build on my machine because the linker was failing to find iconv.

ld: library not found for -liconv

So I peeked at the current HEAD of nixpkgs and it indeed specified iconv as a buildInput. I tried to do the same through an overlay (and many other ways) but I kept getting random type errors

.config/nixpkgs/overlays.nix:

[
    (self: super:
    {
        rPackages = super.rPackages.override {
            SparseM = (super.rPackages.SparseM.overrideDerivation (attrs: { buildInputs = attrs.buildInputs ++ [ self.libiconv ]; }));
        };
    })
]

the above overlay rises:

error: anonymous function at /nix/store/9bhqkb14ca7rl1a8sfyidlr5yl475iyl-nixpkgs/nixpkgs/pkgs/development/r-modules/default.nix:3:1 called with unexpected argument 'SparseM', at /nix/store/9bhqkb14ca7rl1a8sfyidlr5yl475iyl-nixpkgs/nixpkgs/lib/customisation.nix:69:12
(use '--show-trace' to show detailed location information)

I ended up making it work by manually by adding the keys:

quantreg = lib.optionals stdenv.isDarwin [ pkgs.libiconv ];
SparseM = lib.optionals stdenv.isDarwin [ pkgs.libiconv ];

to packagesWithBuildInputs in ~/.nix-defexpr/channels/nixpkgs/pkgs/development/r-modules/default.nix.

This feels quite dirty though so I would prefer if I could get the overlay to work.

The function you are referencing takes three arguments, R, pkgs, overrides and as such you almost had it already. You just got to take the attribute set, where you are overriding a package, and pass it to the function in the form of another overrides = { ... } attribute set. This is what I have in one of my files:

{
  pkgs = import sources.nixpkgs {
    overlays = [
      (self: super: {

        rPackages = super.rPackages.override {
          overrides = {
            RcppArmadillo = super.rPackages.RcppArmadillo.overrideDerivation (attrs: {
              buildInputs = attrs.buildInputs ++ [ pkgs.libiconv ];
            });
          };
        };
      })
    ];
  };
}
1 Like