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

ocamlPackages.janeStreet{,_0_9_0}: join the ocamlPackages fix point, allowing overriding to work as expected #113696

Merged
merged 5 commits into from
Apr 11, 2021

Conversation

sternenseemann
Copy link
Member

@sternenseemann sternenseemann commented Feb 19, 2021

Motivation for this change

Fix long standing ocamlPackages issue #75485: The janeStreet package set is maintained as a sub set of ocamlPackages and merged into it using liftJaneStreet in a second step. This is not an issue in itself, however inner-janestreet dependencies are done by using a rec set in the respective nix expressions. This means that janeStreet packages are oblivious to overrides being done in ocamlPackages to other janeStreet packages and use the original derivation regardless.

This is now fixed, see the commit message of ff40bbe for an example of this.

Another issue arising due to this is that janeStreet packages are both available via ocamlPackages.package and ocamlPackages.janeStreet.package. This creates an issue with overriding as overriding one the two attributes will always be ignored, as we only can use either ocamlPackages or ocamlPackages.janeStreet as the self fix point to get dependencies from. Due to liftJaneStreet it feels more natural to use the top level attribute. To prevent confusion in the future we add a warning when using ocamlPackages.janeStreet instead of the top level attributes (2f413da).

cc @nomeata (original reporter) @vbgl

GitHub thingy: Resolves #75485.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@ofborg ofborg bot added the ofborg-internal-error Ofborg encountered an error label Feb 19, 2021
@sternenseemann
Copy link
Member Author

Seems like I have to revert af2dbfd because ofborg doesn't allow any remaining trace messages when evaluating (which is fair).

The warnings stem from these bits:

    ppx_optcomp =
      if lib.versionOlder "4.03" ocaml.version
      then janeStreet.ppx_optcomp
      else callPackage ../development/ocaml-modules/janestreet/ppx-optcomp.nix {};

Alternatively we could either

  • Move that into liftJaneStreet
  • Remove the legacy versions

Which also begs the question: Should we start removing some of the old janestreet stuff? Most packages in janeStreet_0_9_0 for example fail to build by now because its dependencies use Dune 2 and their jbuild invocations have become incompatible.

@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Feb 19, 2021
@sternenseemann sternenseemann added 6.topic: ocaml and removed ofborg-internal-error Ofborg encountered an error labels Feb 19, 2021
@sternenseemann
Copy link
Member Author

sternenseemann commented Feb 20, 2021

I've had a look at those conditional version changes and they are not that big of a problem:

  • Most are irreperably failing to evaluate and can be removed
  • We can move the rest of the conditionals that do evaluate and build into the janeStreet 0.9 set

However, the warning is still not feasible, as liftJaneStreet seems to be called multiple times if I'm not mistaken unless I figure out how to add it without overriding.

@sternenseemann
Copy link
Member Author

sternenseemann commented Mar 10, 2021

@vbgl any thoughts on this? I have an idea on the deprecation idea in the previous commit by now, but I want to do it in a separate PR.

Copy link
Member

@SuperSandro2000 SuperSandro2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small nit

@sternenseemann
Copy link
Member Author

small nit

makes the diff larger and more awkward to read imo

@sternenseemann
Copy link
Member Author

@ofborg eval

Internal dependencies in the janeStreet sets were always taken from the
own rec attribute set. While this is pretty simple and convenient, it
has the disadvantage that it doesn't play nice with overriding: If you'd
override an attribute in a janeStreet set previously, it would be
changed when referenced directly, but the other packages in that
janeStreet set still would use the original, non-overridden version of
the derivation.

This is easily fixed by passing janeStreet_0_9_0 itself from the fix
point of ocamlPackages and using it to reference the dependencies.

Example showing it now works as expected:

test-overlay.nix:

    self: super: {
      ocamlPackages = super.ocamlPackages.overrideScope (old: _: {
        janeStreet_0_9_0 = old.janeStreet_0_9_0 // {
          base = old.janeStreet_0_9_0.base.overrideAttrs (_: {
            meta.broken = true;
          });
        };
      });
    }

nix-repl> (import ./. {
  overlays = [ (import ./test-overlay.nix) ];
}).ocamlPackages.janeStreet_0_9_0.stdio

error: Package ‘ocaml4.10.0-base-0.9.4’ in /home/lukas/src/nix/nixpkgs/pkgs/development/ocaml-modules/janestreet/janePackage.nix:6 is marked as broken, refusing to evaluate.

a) To temporarily allow broken packages, you can use an environment variable
   for a single invocation of the nix tools.

     $ export NIXPKGS_ALLOW_BROKEN=1

b) For `nixos-rebuild` you can set
  { nixpkgs.config.allowBroken = true; }
in configuration.nix to override this.

c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowBroken = true; }
to ~/.config/nixpkgs/config.nix.
This change makes overrides to the janeStreet set work as expected by
making the janeStreet set take part in the ocamlPackages fixpoint for
janeStreet 0.14, i. e. OCaml >= 4.08
This change makes overrides to the janeStreet set work as expected by
making the janeStreet set take part in the ocamlPackages fixpoint for
janeStreet 0.12, i. e. OCaml == 4.07
This change makes overrides to the janeStreet set work as expected by
making the janeStreet set take part in the ocamlPackages fixpoint for
janeStreet 0.11, i. e. OCaml < 4.07
Previously, we inherited non-janestreet ocaml dependencies from super
and janestreet dependencies from self which always was super.janeStreet.

This behavior is however not really what we want due to liftJaneStreet:
Users and other packages will use ocamlPackages.base etc. instead of
ocamlPackages.janeStreet.base and the like. Consequently they also would
override the top-level attributes which would mean that other janestreet
packages would not pick up on it however.

As a consequence however, overriding ocamlPackages.janeStreet.base
doesn't work. Since this was never possible, I don't think this is an
issue. It is probably a good idea to deprecate that set anyways and
printing a warning when it is used via trace.

janeStreet_0_9_0 is unchanged as the disticniton between self and super
makes sense for it.

Below is an example showing how overriding would work from an user's
perspective:

test-overlay.nix:

    self: super: {
      ocamlPackages = super.ocamlPackages.overrideScope (old: _: {
        base = old.base.overrideAttrs (_: {
          meta.broken = true;
        });
      });
    }

nix-repl> (import ./. { overlays = [ (import ./test-overlay.nix) ]; }).ocamlPackages.
stdio
error: Package ‘ocaml4.10.0-base-0.14.0’ in /home/lukas/src/nix/nixpkgs/pkgs/development/ocaml-modules/janestreet/janePackage_0_14.nix:12 is marked as broken, refusing to evaluate.

a) To temporarily allow broken packages, you can use an environment variable
   for a single invocation of the nix tools.

     $ export NIXPKGS_ALLOW_BROKEN=1

b) For `nixos-rebuild` you can set
  { nixpkgs.config.allowBroken = true; }
in configuration.nix to override this.

c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
  { allowBroken = true; }
to ~/.config/nixpkgs/config.nix.
@sternenseemann sternenseemann merged commit 2140791 into NixOS:master Apr 11, 2021
sternenseemann added a commit to sternenseemann/nixpkgs that referenced this pull request Jul 24, 2021
These packages have been failing to evaluate for some time now for two
reasons:

* ocamlmod doesn't evaluate for OCaml < 4.04 which is fixed in NixOS#113771
* We have no ppx_core version for OCaml < 4.03 which is a fundamental
  issue.

Since this situation has been going on for some time now, I don't really
see the need to figure out how to fix these legacy versions of some
janestreet packages. There is also additional motivation:

* These packages reference the janeStreet set directly which I'd like
  to deprecate, as it spells trouble for the overriding possibilities
  introduced in NixOS#113696.
* These packages are patched in awkwardly into the janeStreet set
  without forming one themselves. By removing them we can move closer to
  having all janestreet packages managed uniformly in their own
  janestreet sets.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: ocaml 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ocaml packages are not individually overridable
2 participants