tweag / opam-nix

Turn opam-based OCaml projects into Nix derivations
MIT License
109 stars 32 forks source link

Example Request: Building a dependency from source and adding it to the buildInputs. #59

Closed kentookura closed 11 months ago

kentookura commented 11 months ago

This flake currently fails to build:

{
  inputs = {
    opam-nix.url = "github:tweag/opam-nix";
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.follows = "opam-nix/nixpkgs";
    forester.url = "sourcehut:~jonsterling/ocaml-forester";
    forester.flake = false;
  };
  outputs = { self, flake-utils, forester, opam-nix, nixpkgs }@inputs:
    let
      package = "forester";
    in
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        on = opam-nix.lib.${system};
        devPackagesQuery = {
          # You can add "development" packages here. They will get added to the devShell automatically.
          ocaml-lsp-server = "*";
          ocamlformat = "*";
        };
        query = devPackagesQuery // {
          ## You can force versions of certain packages here, e.g:
          ## - force the ocaml compiler to be taken from opam-repository:
          ocaml-base-compiler = "*";
          ## - or force the compiler to be taken from nixpkgs and be a certain version:
          # ocaml-system = "4.14.0";
          ## - or force ocamlfind to be a certain version:
          # ocamlfind = "1.9.2";
        };
        scope = on.buildOpamProject' { } forester query;
        overlay = final: prev: {
          # You can add overrides here
          ${package} = prev.${package}.overrideAttrs (_: {
            doNixSupport = false;
          });
        };
        scope' = scope.overrideScope' overlay;
        main = scope'.${package};
        devPackages = builtins.attrValues
          (pkgs.lib.getAttrs (builtins.attrNames devPackagesQuery) scope');
      in
      {
        legacyPackages = scope';
        packages.default = main;
      });
}
resolve> [ERROR] No solution including optional dependencies for forester.2.5.1 & ocaml-base-compiler & ocaml-lsp-server & ocamlformat:   * Missing dependency:
resolve>             - asai
resolve>             unknown package

The package is not contained in opam-repo but should be installable with opam: https://ocaml.org/p/asai/0.2.0 The source of the package is here: https://github.com/RedPRL/asai

Is it possible to build asai from the repo and add it to the build inputs for forester?

Thanks!

kentookura commented 11 months ago
{
  inputs = {
    opam-nix.url = "github:tweag/opam-nix";
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.follows = "opam-nix/nixpkgs";
    opam-repository.url = "github:ocaml/opam-repository";
    opam-repository.flake = false;
    forester.url = "sourcehut:~jonsterling/ocaml-forester";
    asai.url = "github:RedPRL/asai";
    asai.flake = false;
    forester.flake = false;
  };
  outputs = { self, asai, flake-utils, opam-repository, forester, opam-nix, nixpkgs }@inputs:
    let
      package = "forester";
    in
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        on = opam-nix.lib.${system};
        devPackagesQuery = {
          asai = "*";
        };
        query = devPackagesQuery // {
          ocaml-base-compiler = "*";
        };
        scope = on.buildOpamProject' { repos = [ "${opam-repository}" asai ]; } forester query;
        overlay = final: prev: { };
        scope' = scope.overrideScope' overlay;
        main = scope'.${package};
        devPackages = builtins.attrValues
          (pkgs.lib.getAttrs (builtins.attrNames devPackagesQuery) scope');
      in
      {
        legacyPackages = scope';
        packages.default = main;
      });
}
balsoft commented 11 months ago

I believe you just needed a newer version of opam-repository than the one pinned in opam-nix, since it does contain the asai package.