nix-community / bundix

Generates a Nix expression for your Bundler-managed application. [maintainer=@manveru]
160 stars 54 forks source link

Failing at gdal gem installation (native extensions) #111

Closed pcboy closed 8 months ago

pcboy commented 8 months ago

I'm sure this is likely stupid, but I completely fail at installing gdal.

I have this simple flake:

{
  description = "A basic flake with a shell";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = {
    self,
    nixpkgs,
    flake-utils,
  }:
    flake-utils.lib.eachDefaultSystem (system: let
      pkgs = nixpkgs.legacyPackages.${system};
      bundleEnv = pkgs.bundlerEnv {
        name = "beef-env";
        ruby = pkgs.ruby;
        gemdir = ./.;
      };
    in {
      devShells.default = pkgs.mkShell {
        packages = with pkgs; [bashInteractive bundleEnv gcc gdal which];
      };
    });
}

In my gemset.nix:

{
  gdal = {
    groups = ["default"];
    platforms = [];
    source = {
      remotes = ["https://rubygems.org"];
      sha256 = "0axd2grw2sl53anl4flygq8vcqi3cbn9klg6q1mk38qyspyg4l1v";
      type = "gem";
    };
    version = "3.0.0";
  };
}

Every time I try to load the shell, I get:

error: builder for '/nix/store/a33phgkxbzv4xrkww90g9sg4g8fc752j-ruby3.1.4-gdal-3.0.0.drv' failed with exit code 1;
       last 10 log lines:
       >   --srcdir=.
       >     --curdir
       >       --ruby=/nix/store/5xbwwbyjmc1xvjzhghk6r89rn4ylidv8-ruby-3.1.4/bin/$(RUBY_BASE_NAME)
       > extconf.rb:6:in ``': No such file or directory - which (Errno::ENOENT)
       >    from extconf.rb:6:in `<main>'
       >
       > extconf failed, exit code 1
       >
       > Gem files will remain installed in /nix/store/r9zgc83p953zwzgni8i9q7ly7xjm23bk-ruby3.1.4-gdal-3.0.0/lib/ruby/gems/3.1.0/gems/gdal-3.0.0 for inspection.
       > Results logged to /nix/store/r9zgc83p953zwzgni8i9q7ly7xjm23bk-ruby3.1.4-gdal-3.0.0/lib/ruby/gems/3.1.0/extensions/x86_64-linux/3.1.0/gdal-3.0.0/gem_make.out
       For full logs, run 'nix log /nix/store/a33phgkxbzv4xrkww90g9sg4g8fc752j-ruby3.1.4-gdal-3.0.0.drv'.
error: 1 dependencies of derivation '/nix/store/myz6yac53rwhkq343082v85x12hg9bwx-beef-env.drv' failed to build
error: 1 dependencies of derivation '/nix/store/z3z3h3c9dfp7d5ah1i7mpqx2fswwnsmi-nix-shell-env.drv' failed to build

If I manually do:

/nix/store/5xbwwbyjmc1xvjzhghk6r89rn4ylidv8-ruby-3.1.4/bin/ruby /nix/store/r9zgc83p953zwzgni8i9q7ly7xjm23bk-ruby3.1.4-gdal-3.0.0/lib/ruby/gems/3.1.0/gems/gdal-3.0.0/ext/gdal-ruby/gdal/extconf.rb

It actually runs fine and generate a Makefile…
And if I do make, it compiles fine. I think it's because I have gcc already on my machine, but it's also supposed to be in the devShell.

I also tried to make a derivation instead, and added gcc in the nativeBuildInputs before adding bundleEnv in the buildInputs, but same issue.

The logs at nix log /nix/store/a33phgkxbzv4xrkww90g9sg4g8fc752j-ruby3.1.4-gdal-3.0.0.drv show:

@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "configurePhase" }
configuring
no configure script, doing nothing
@nix { "action": "setPhase", "phase": "installPhase" }
installing
buildFlags: 
WARNING:  You build with buildroot.
  Build root: /
  Bin dir: /nix/store/r9zgc83p953zwzgni8i9q7ly7xjm23bk-ruby3.1.4-gdal-3.0.0/lib/ruby/gems/3.1.0/bin
  Gem home: /nix/store/r9zgc83p953zwzgni8i9q7ly7xjm23bk-ruby3.1.4-gdal-3.0.0/lib/ruby/gems/3.1.0
  Plugins dir: /nix/store/r9zgc83p953zwzgni8i9q7ly7xjm23bk-ruby3.1.4-gdal-3.0.0/lib/ruby/gems/3.1.0/plugins
Building native extensions. This could take a while...
ERROR:  Error installing /nix/store/k4n4lpa4cf1593snkic4a1d6b1qjm2b9-gdal-3.0.0.gem:
        ERROR: Failed to build gem native extension.

    current directory: /nix/store/r9zgc83p953zwzgni8i9q7ly7xjm23bk-ruby3.1.4-gdal-3.0.0/lib/ruby/gems/3.1.0/gems/gdal-3.0.0/ext/gdal-ruby/gdal
/nix/store/5xbwwbyjmc1xvjzhghk6r89rn4ylidv8-ruby-3.1.4/bin/ruby extconf.rb
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/nix/store/5xbwwbyjmc1xvjzhghk6r89rn4ylidv8-ruby-3.1.4/bin/$(RUBY_BASE_NAME)
extconf.rb:6:in ``': No such file or directory - which (Errno::ENOENT)
        from extconf.rb:6:in `<main>'

extconf failed, exit code 1

What am I missing?
I do have gdal-config, I tried to remove bundleEnv from the list of packages in the shell, and tried to do which gdal-config in the shell, and it's there.

pcboy commented 8 months ago

I think I just found the issue. :facepalm:

      bundleEnv = pkgs.bundlerEnv {
        name = "beef-env";
        ruby = pkgs.ruby;
        gemdir = ./.;

        gemConfig =
          pkgs.defaultGemConfig
          // {
            gdal = attrs: {
              nativeBuildInputs = [pkgs.gdal pkgs.which];
            };
          };
      };

I had to add a custom gemConfig with this set of nativeBuildInputs directly. And it seems to be compiling fine now.