Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to statically build package that depends on dllunix #47

Closed
solomon-b opened this issue Jul 9, 2023 · 4 comments
Closed

Unable to statically build package that depends on dllunix #47

solomon-b opened this issue Jul 9, 2023 · 4 comments

Comments

@solomon-b
Copy link

solomon-b commented Jul 9, 2023

Describe the bug
I'm trying to statically build a project that has a transitive dependency on dllunix.so and am getting the following error:

error: builder for '/nix/store/x4jq8kzc7m7awl74pxyib11sn92fy1lc-jsonrpc-static-x86_64-unknown-linux-musl-1.15.1-5.0.drv' failed with exit code 2;
       last 10 log lines:
       > building
       > File "_none_", line 1:
       > Alert ocaml_deprecated_auto_include:
       > OCaml's lib directory layout changed in 5.0. The unix subdirectory has been
       > automatically added to the search path, but you should add -I +unix to the
       > command-line to silence this alert (e.g. by adding unix to the list of
       > libraries in your dune file, or adding use_unix to your _tags file for
       > ocamlbuild, or using -package unix for ocamlfind).
       > Cannot load required shared library dllunix.
       > Reason: dllunix.so: dynamic loading not supported on this platform.
       For full logs, run 'nix log /nix/store/x4jq8kzc7m7awl74pxyib11sn92fy1lc-jsonrpc-static-x86_64-unknown-linux-musl-1.15.1-5.0.drv'.
error: 1 dependencies of derivation '/nix/store/ym9m7ipv68y04vmw6a9008290y9i4js6-lsp-static-x86_64-unknown-linux-musl-1.15.1-5.0.drv' failed to build
error (ignored): error: cannot unlink '/tmp/nix-build-menhirLib-static-x86_64-unknown-linux-musl-20230415.drv-2': Directory not empty
error: 1 dependencies of derivation '/nix/store/7gv25hzwjg801axwzpm5n6l728x0qxar-asai-static-x86_64-unknown-linux-musl-0.1.0_dev.drv' failed to build
error: 1 dependencies of derivation '/nix/store/18d0sz41m84cliq8w84waj5116rgg32x-polytt-static-x86_64-unknown-linux-musl-dev-env.drv' failed to build

To Reproduce
My project is not public but here is my flake.nix:

{
  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:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        on = opam-nix.lib.${system};

        localPackagesQuery = builtins.mapAttrs (_: pkgs.lib.last)
          (on.listRepo (on.makeOpamRepo ./.));

        query = {
          ocaml-base-compiler = "*";
        };

        scope = on.buildDuneProject { pkgs = pkgs.pkgsStatic; } "polytt" ./. query;

        overlay = self: super: {
          # Prevent unnecessary dependencies on the resulting derivation
          polytt = super.polytt.overrideAttrs (_: {
            removeOcamlReferences = true;
            postFixup = "rm -rf $out/nix-support";
          });
        };

        scope' = scope.overrideScope' overlay;

        # Packages in this workspace
        packages =
          pkgs.lib.getAttrs (builtins.attrNames localPackagesQuery) scope';
      in
      {
        legacyPackages = scope';

        packages = packages // { default = packages.polytt; };
      });
}

This should fail on any package that depends on, for example, the ocaml lsp package.

Expected behavior
I would expect a successful static build.

Environment

  • Nixos 23.05
  • Version of the code: ocaml 5.0

Additional context
Add any other context about the problem here.

@balsoft
Copy link
Collaborator

balsoft commented Jul 12, 2023

This is not an opam-nix problem, and unfortunately there's little we can do from our side. See similar issues: 1 2 3 .You can try an override like this:

jsonrpc = super.jsonrpc.overrideAttrs (oa: { buildPhase = "dune build -p $pname @install"; });

Which skips the part of the build that required unixdll.so (ocaml unix.cma unvendor.ml) but it's not clear to me whether the resulting package will work after that.

@balsoft
Copy link
Collaborator

balsoft commented Jul 17, 2023

Can we close this issue, as there's nothing that can be done on opam-nix side?

@solomon-b
Copy link
Author

Hi. Yes consider this issue closed. To make sure I understand the issue correctly, the problem is that jsonrpc depends on dllunix.so for which there is not a static build available?

@balsoft
Copy link
Collaborator

balsoft commented Jul 18, 2023

To make sure I understand the issue correctly, the problem is that jsonrpc depends on dllunix.so for which there is not a static build available?

Yes, pretty much. dllunix relies on dynamic loading (it uses dlopen), so it can't be built statically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants