tweag / opam-nix

Turn opam-based OCaml projects into Nix derivations
MIT License
111 stars 33 forks source link

Fail to compile `raylib-ocaml` #74

Closed ethanthoma closed 9 months ago

ethanthoma commented 10 months ago

Describe the bug I want to use the raylib-ocaml library (github and opam) in my dune project. Trying to build it fails for conf-libxcursor.

To Reproduce

  1. nix-shell -p dune opam
  2. opam exec -- dune init proj hello
  3. cd hello
  4. nix flake init -t github:tweag/opam-nix
  5. edit the flake.nix
    1. change buildOpamProject to buildDuneProject
    2. add raylib = "*"; to scope
    3. add ${package} = prev.${package}.overrideAttrs (oa: { buildInputs = oa.buildInputs ++ [ final.raylib ]; }); to overlay
  6. nix build

Expected behavior Successful build.

Environment

Additional context Add any other context about the problem here. The full flake is:

{
    inputs = {
        opam-nix.url = "github:tweag/opam-nix";
        flake-utils.url = "github:numtide/flake-utils";
        nixpkgs.follows = "opam-nix/nixpkgs";
    };

    outputs = { self, flake-utils, opam-nix, nixpkgs }@inputs:
    let 
        package = "hello";
    in flake-utils.lib.eachDefaultSystem (system:
        let
            pkgs = nixpkgs.legacyPackages.${system};
            on = opam-nix.lib.${system};
            scope = on.buildDuneProject { } package ./. { 
                ocaml-base-compiler = "*"; 
                raylib = "*";
            };
            overlay = final: prev: {
                ${package} = prev.${package}.overrideAttrs (oa: {
                    buildInputs = oa.buildInputs ++ [ final.raylib ];
                    buildPhase = "dune build --release"; 
                });
            };
        in {
            legacyPackages = scope.overrideScope' overlay;
            packages.default = self.legacyPackages.${system}.${package};
        }
    );
}

Full output from build:

❯ nix build
error: builder for '/nix/store/j5j86cs6ckhrh5fs4hbrslf4814rhpvr-conf-libxcursor-1.drv' failed with exit code 1;
       last 7 log lines:
       > unpacking sources
       > unpacking source archive /nix/store/4d0ix5djms3n2jnjdc58l916cwack1rp-empty-directory
       > source root is empty-directory
       > patching sources
       > configuring
       > patching script interpreter paths in .
       > building
       For full logs, run 'nix log /nix/store/j5j86cs6ckhrh5fs4hbrslf4814rhpvr-conf-libxcursor-1.drv'.
error: 1 dependencies of derivation '/nix/store/if85wf0mgkf7plxd54mw4vgzdkh6jgrx-raylib-1.1.0.drv' failed to build
error (ignored): error: cannot unlink '/tmp/nix-build-ocaml-base-compiler-5.1.1_rc1.drv-6/ocaml-5.1.1-rc1': Directory not empty
error: 1 dependencies of derivation '/nix/store/alklyc02s7jz2gadg4bhvgwd8crhz48i-hello-dev.drv' failed to build
balsoft commented 10 months ago

Hi! I think it needs a couple of overrides. I'll take a look.

balsoft commented 9 months ago

Should be fixed in 9f03f7e0664c369f25e614d3f3be74ea78b647fa

ethanthoma commented 9 months ago

Thank you so much, I will try later today.

ethanthoma commented 9 months ago

Hello, sorry for the late reply. I tried to reply earlier but my internet died. It builds successfully now but fails to run. I copied this example from the raylib-ocaml github. It runs fine with dune exec hello and builds fine with nix build but running ./result/bin/hello fails with

INFO: Initializing raylib 4.5
INFO: Supported raylib modules:
INFO:     > rcore:..... loaded (mandatory)
INFO:     > rlgl:...... loaded (mandatory)
INFO:     > rshapes:... loaded (optional)
INFO:     > rtextures:. loaded (optional)
INFO:     > rtext:..... loaded (optional)
INFO:     > rmodels:... loaded (optional)
INFO:     > raudio:.... loaded (optional)
WARNING: GLFW: Error: 65542 Description: GLX: No GLXFBConfigs returned
WARNING: GLFW: Error: 65545 Description: GLX: Failed to find a suitable GLXFBConfig
WARNING: GLFW: Failed to initialize Window
FATAL: Failed to initialize Graphic Device

I tried searching online for solutions. Most places refer to driver issues but that wouldn't make sense as to why I can run it with dune but not with opamnix.

balsoft commented 9 months ago

Hm, could you try with nix-gl?

ethanthoma commented 9 months ago

I ran the command nix run --impure github:guibou/nixGL -- ./result/bin/hello and it worked. Thank you!