I’m new to nix, and am trying to get a Haskell program depending on inline-r running. During compliation, this requires libR.so, and I’m having some difficulty getting this to be found in the environment.
default.nix
let
config = {
packageOverrides = pkgs: rec {
haskellPackages = pkgs.haskellPackages.override {
overrides = haskellPackagesNew: haskellPackagesOld: rec {
nix-mwe =
haskellPackagesNew.callPackage ./cabal.nix {
R = pkgs.rWrapper.override {
packages = with pkgs.rPackages; [ dplyr ];
};
};
};
};
};
};
pkgs = import <nixpkgs> { inherit config; };
in
pkgs.haskellPackages.nix-mwe
cabal.nix (generated from package.yaml by cabal2nix)
{ mkDerivation, base, hpack, inline-r, pkgconfig, R, stdenv }:
mkDerivation {
pname = "nix-mwe";
version = "0.0.0";
src = ./.;
isLibrary = true;
isExecutable = true;
libraryHaskellDepends = [ base inline-r ];
libraryPkgconfigDepends = [ R ];
libraryToolDepends = [ hpack pkgconfig ];
executableHaskellDepends = [ base ];
prePatch = "hpack";
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;
}
Running nix-build fails with the following message:
CallStack (from HasCallStack):
die', called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:1508:37 in Cabal-2.4.0.1:Distribution.Simple.Configure
configurePkgconfigPackages, called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:579:7 in Cabal-2.4.0.1:Distribution.Simple.Configure
configure, called at libraries/Cabal/Cabal/Distribution/Simple.hs:596:20 in Cabal-2.4.0.1:Distribution.Simple
confHook, called at libraries/Cabal/Cabal/Distribution/Simple/UserHooks.hs:67:5 in Cabal-2.4.0.1:Distribution.Simple.UserHooks
configureAction, called at libraries/Cabal/Cabal/Distribution/Simple.hs:178:19 in Cabal-2.4.0.1:Distribution.Simple
defaultMainHelper, called at libraries/Cabal/Cabal/Distribution/Simple.hs:115:27 in Cabal-2.4.0.1:Distribution.Simple
defaultMain, called at Setup.hs:7:8 in main:Main
Setup: The pkg-config package 'libR' version >3.0 is required but it could not
be found.
I’ve tried introducing buildInputs = [ R ]
, but mkDerivation as called by haskellPackages doesn’t recognise this field. I can get around this problem by calling nix-shell with the R package directly
nix-shell -p R --run "cabal build --extra-lib-dirs='$(nix-build "<nixpkgs>" -A R)/lib'"
however this just punts the error another step down the line.
<command line>: can't load .so/.DLL for: /home/user/.cabal/store/ghc-8.6.5/inline-r-0.10.2-79ba24b2c29ca38b632c248984628abd2639c607774acf4f036765dfab08bf0f/lib/libHSinline-r-0.10.2-79ba24b2c29ca38b632c248984628abd2639c607774acf4f036765dfab08bf0f-ghc8.6.5.so (libR.so: cannot open shared object file: No such file or directory)
Adding more -p
arguments including pkgconfig, haskellPackages.inline-r, and adding --extra-lib-dirs='$(nix-build "<nixpkgs>" -A haskellPackages.inline-r)/lib
doesn’t change the result.
So my questions are:
- How can I help cabal find the relevant libraries inside the nix-shell
- How can I include this information in the derivation itself, so I don’t have to append a large number of --extra-lib-dirs to by cabal call every time.
More details:
- I am using not on NixOS, and am just using nix as a build tool
- I’m using nixpkgs-unstable, but I got the same results when I tried using nixos-19.09
In case it’s relevant, the Haskell code follows.
Summary
{-# LANGUAGE QuasiQuotes #-}
module MWE where
import Language.R
import Language.R.QQ
main :: IO ()
main = withEmbeddedR def $ void
[r| library(dplyr)
print("Test")
|]
and the package.yaml is
name: nix-mwe
extra-source-files:
- package.yaml
library:
dependencies:
- base
- inline-r >=0.9 && <0.11
pkg-config-dependencies:
- libR >3.0
system-build-tools:
- pkg-config
source-dirs: library
executables:
hledger-report:
source-dirs: executable
main: Main.hs
dependencies:
- base
- nix-mwe