R package gifski doesn't build

nix-shell -p rPackages.gifski

Results in

this derivation will be built:
  /nix/store/z1h6vf5hz8g3clmbv1qkpwgbkymifxpi-r-gifski-1.4.3-1.drv
building '/nix/store/z1h6vf5hz8g3clmbv1qkpwgbkymifxpi-r-gifski-1.4.3-1.drv'...
unpacking sources
unpacking source archive /nix/store/22nkrf9ampbqczsgwlwqmfp80xwi2pky-gifski_1.4.3-1.tar.gz
source root is gifski
setting SOURCE_DATE_EPOCH to timestamp 1619929802 of file gifski/MD5
patching sources
configuring
building
running tests
installing
* installing *source* package 'gifski' ...
** package 'gifski' successfully unpacked and MD5 sums checked
** using staged installation
./configure: line 5: cargo: not found
------------------ RUST COMPILER NOT FOUND --------------------

Cargo was not found on the PATH. Please install cargo / rustc:

 - yum install cargo         (Fedora/CentOS)
 - apt-get install cargo     (Debian/Ubuntu)
 - brew install rust         (MacOS)

Alternatively install Rust from: <https://www.rust-lang.org>
...

I see that rPackages.gifski uses a generic builder:

Does anyone have any ideas on if, as a quick fix, there a way to pass the rust compiler to the rPackages.gifski derivation?

Thanks,

To check whether an override of build inputs and derivation arguments might solve the problem:

git clone --depth=1 https://github.com/nixos/nixpkgs

Edit
~/repos/nixpkgs/pkgs/development/r-modules/generic-builder such that these two lines

{ stdenv, lib, R, libcxx, xvfb-run, util-linux, Cocoa, Foundation, gettext, gfortran }
...
buildInputs = buildInputs ++ [R gettext] ++ 

become

{ stdenv, lib, R, libcxx, xvfb-run, util-linux, Cocoa, Foundation, gettext, gfortran, cargo, rustc }
...
buildInputs = buildInputs ++ [R gettext] ++ [cargo rustc] ++

Now the builder steps:

mkdir -p tmpdev && cd tmpdev
nix-shell $HOME/repos/nixpkgs -A rPackages.gifski
export out=out
genericBuild

run successfully.

So far, so good. However, trying:

nix-shell -p rPackages.gifski -I nixpkgs=$HOME/repos/nixpkgs

… fails with

...
    Updating crates.io index
warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
error: Unable to update registry `crates-io`

Caused by:
  failed to fetch `https://github.com/rust-lang/crates.io-index`

Caused by:
  network failure seems to have happened
  if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
  https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
  [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
make: *** [Makevars:13: myrustlib/target/release/libmyrustlib.a] Error 101
ERROR: compilation failed for package 'gifski'
* removing '/nix/store/n0j4yf4snq699g4mffkpwsx5lnqmg0vb-r-gifski-1.6.6-1/library/gifski'
error: builder for '/nix/store/jzj8jxkgk7wi1nic001sn8aff7wz51jk-r-gifski-1.6.6-1.drv' failed with exit code 1;
       last 10 log lines:
       > Caused by:
       >   network failure seems to have happened
       >   if a proxy or similar is necessary `net.git-fetch-with-cli` may help here
       >   https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli
       >
       > Caused by:
       >   [6] Couldn't resolve host name (Could not resolve host: github.com); class=Net (12)
       > make: *** [Makevars:13: myrustlib/target/release/libmyrustlib.a] Error 101
       > ERROR: compilation failed for package 'gifski'
       > * removing '/nix/store/n0j4yf4snq699g4mffkpwsx5lnqmg0vb-r-gifski-1.6.6-1/library/gifski'
       For full logs, run 'nix log /nix/store/jzj8jxkgk7wi1nic001sn8aff7wz51jk-r-gifski-1.6.6-1.drv'.

I am not sure what to do now. Any suggestions welcome.

Just adding cargo and rust won’t solve the problem since cargo needs to fetch dependencies usually through the network (which is disabled in the build environment). This is usually worked around by performing also providing a hash for the dependencies (which I think uses a fixed output derivation) [rust section].

The Compiling non-Rust packages that include Rust code section of that same document may be helpful here.

Edit: Linked wrong section

1 Like

https://github.com/NixOS/nixpkgs/pull/178147

1 Like

@hqurve Thanks for both the doc link and advice … AND for doing the fix!

1 Like

Incidentally, I tried copying your changes to the r-modules/default.nix into the small shell.nix below, and got a successful build but the R terminal command library(gifski) returned Error in library(gifski) : there is no package called ‘gifski’… no cigar for being close :frowning:

If would be grateful if you are able to provide any further guidance, but if not that is fine too.

{pkgs ? import (fetchTarball("https://github.com/NixOS/nixpkgs/archive/bbd64cbe3ca10ab12244eeb535766ba3e524f29f.tar.gz")){}}:
with pkgs;
let 
  our-gifski = gifski.overrideDerivation( attrs: rec {
    cargoDeps = pkgs.rustPlatform.fetchCargoTarball {
      src = attrs.src;
      #hash = "sha256-NRI3SWwyY/iCjE5MEKeLi6e5sm2+UK7pkoAMFeCPbdw=";
      hash = "sha256-LR1AALg347k/pzDw4w67ThutoNrGZ+uK4wqhOtxTyCs="; # 11-03-2022
      sourceRoot = "gifski/src/myrustlib";
    };
    
    patchPhase = ''
    mkdir -p src/myrustlib
    '';

    cargoRoot = "src/myrustlib";
    
    nativeBuildInputs = attrs.nativeBuildInputs ++ [
      pkgs.rustPlatform.cargoSetupHook
      pkgs.cargo
      pkgs.rustc
    ];
  });
  
  our-packages = with rPackages; [
    our-gifski
  ];
  R-with-our-packages = rWrapper.override{ packages =  our-packages; };
in
pkgs.mkShell {
  buildInputs = [
    R-with-our-packages
  ];
}

Many thanks

You are accidentally overriding the gifski package instead of rPackages.gifski (nixos search). I’m sort of surprised that this built at all

Ooops, shame! Thank you soooo much for that one! Success with:

{pkgs ? import (fetchTarball("https://github.com/NixOS/nixpkgs/archive/bbd64cbe3ca10ab12244eeb535766ba3e524f29f.tar.gz")){}}:
with pkgs;
let 
  our-gifski = rPackages.gifski.overrideDerivation( attrs: rec {
    cargoDeps = pkgs.rustPlatform.fetchCargoTarball {
      src = attrs.src;
      hash = "sha256-tsOp6AJdcYCjk/uaEjhXyhHefQi8eU+lVyZCwE48BL8=";
      sourceRoot = "gifski/src/myrustlib";
    };

    cargoRoot = "src/myrustlib";
    
    nativeBuildInputs = attrs.nativeBuildInputs ++ [
      pkgs.rustPlatform.cargoSetupHook
      pkgs.cargo
      pkgs.rustc
    ];
  });
  our-packages = [
    our-gifski
  ];
  R-with-our-packages = rWrapper.override{ packages =  our-packages; };
in
pkgs.mkShell {
  buildInputs = [
    R-with-our-packages
  ];
}
1 Like