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

Tidy up the Coq package sets #32737

Merged
merged 4 commits into from Dec 19, 2017
Merged

Tidy up the Coq package sets #32737

merged 4 commits into from Dec 19, 2017

Conversation

vbgl
Copy link
Contributor

@vbgl vbgl commented Dec 16, 2017

Motivation for this change

See discussion of #30698.
cc/ @maximedenes @jwiegley @Zimmi48

There are three (3) coqPackages_XX set, one for each version of Coq (8.5, 8.6, 8.7); there are all built from the same function mkCoqPackages.

Before this PR, this sets all have the same attributes but many libraries are not compatible with all these versions of Coq. Therefore, many derivations in these sets are broken: they either fail at evaluation or at build time. It makes difficult to know what are the available libraries in nixpkgs and whether something is broken by mistake or by design.

The goal of this PR is that all attributes evaluate and build. Here is how it is achieved:

  1. Move most Coq-related stuff in a dedicated file pkgs/top-level/coq-packages.nix, available through the coqLib attribute.
  2. Add to most Coq library derivations a meta.compatibleCoqVersions attributes: it is a function from version strings to booleans and tells whether said version is compatible with said library. If this attribute is missing, it means that the library is compatible with all versions (i.e., defaults to _: true).
  3. At the end of the fixed point computation, the (recursive) attribute set coqPackages_XX is filtered to keep only those attributes that are compatible with the corresponding Coq version.

NB: I intended to do the filtering during the fixed point computation, but run into infinite loops. It’s probably not a big deal but I wished I understood what’s going on…

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • 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 nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@Zimmi48
Copy link
Member

Zimmi48 commented Dec 16, 2017

This looks good to me. And I've done some testing under NixOS (with sandboxing).

Given that the predicate is applied to the coq-version attribute, I would rather prefer a definition of the form compatibleCoqVersions = v: builtins.elem v [ "8.6" "8.7" ]; that has IMO the advantage of being explicit.

I suppose that what grahamcofborg-eval-check-meta shows is that this information should not be in the meta attribute set.

let pred =
if p ? meta && p.meta ? compatibleCoqVersions
then p.meta.compatibleCoqVersions
else _: true;
Copy link
Contributor

Choose a reason for hiding this comment

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

The predicate is equivalent to p ? meta.compatibleCoqVersions, and the whole conditional is equivalent to p.meta.compatibleCoqVersions or (_: true).

Copy link
Member

Choose a reason for hiding this comment

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

Note that compatibleCoqVersions isn't a valid meta attribute. Maybe passthru would be more appropriate?

};

filterCoqPackages = coq:
lib.filterAttrsRecursive
Copy link
Contributor

Choose a reason for hiding this comment

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

Is lib.filterAttrs insufficient?

coqPackages_8_7 = mkCoqPackages coqPackages_8_7 coq_8_7;
coqPackages = coqPackages_8_6;
coq = coqPackages.coq;
inherit (coqLib)
Copy link
Contributor

Choose a reason for hiding this comment

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

May you inherit (callPackage ./coq-packages.nix {}) to avoid confusing naming. (Due to coqLib = ./coq-packages ≠ coqPackages.)

@vbgl
Copy link
Contributor Author

vbgl commented Dec 17, 2017

Thanks for the comments. I addressed your concerns in 791776b.

Do you know if there is a way to inherit all attributes from a set? Currently the line inherit (callPackage ./coq-packages.nix {}) …; repeats all the attributes.

@jwiegley
Copy link
Contributor

It all looks good to me, though I haven't had the time to try it out yet.

@Zimmi48
Copy link
Member

Zimmi48 commented Dec 17, 2017

Do you know if there is a way to inherit all attributes from a set? Currently the line inherit (callPackage ./coq-packages.nix {}) …; repeats all the attributes.

Not an answer to this question, but we could also go the same route as ocamlPackages which recently moved from top-level to ocaml-ng, with some aliases kept for compatibility, although I must say that this change confused me until I found where new package sets were hiding.

@vbgl
Copy link
Contributor Author

vbgl commented Dec 17, 2017

@Zimmi48 Just above (#32737 (comment)) Orivej suggested not to introduce such an attribute (because of confusing naming).

@orivej
Copy link
Contributor

orivej commented Dec 17, 2017

This PR looks ready to merge, but "coqPackages: wip" suggests that the last commit is work in progress, i.e. unfinished. Do you consider it ready?

Do you know if there is a way to inherit all attributes from a set?

There is { one = set; } // another-set, but it is not used in all-packages and there is no equivalent with inherit. IMHO explicit inherit of coq attributes is fine.

@vbgl
Copy link
Contributor Author

vbgl commented Dec 18, 2017

I just cleaned the commits and added some documentation. Also I add the library that is used as an example in the docs.

Copy link
Member

@Zimmi48 Zimmi48 left a comment

Choose a reason for hiding this comment

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

Kudos for updating the doc!

generated using <literal>coq_makefile</literal> so we only have to
depends on Coq. It builds on the Mathematical Components library, thus it
also takes <literal>mathcomp</literal> as <literal>buildInputs</literal>.
Its <literal>makefile</literal> has been generated using
Copy link
Member

Choose a reason for hiding this comment

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

Use a capital M here, especially since it is a literal.


buildInputs = [ coq ];
propagatedBuildInputs = [ mathcomp ];
Copy link
Member

Choose a reason for hiding this comment

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

Some Coq packages also propagate Coq. Should the rule be not to propagate it? In this case, we should probably update the packages which do not respect this rule.

And how important is it to propagate math-comp? Should Coq package dependencies be always propagated? There are also examples where it is not the case.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should only be propagated if users of that library also (almost always) need to require import from mathcomp. Otherwise, they could specify mathcomp in their own dependencies list, right?

@vbgl vbgl merged commit b455192 into NixOS:master Dec 19, 2017
@vbgl vbgl deleted the coq-packages-filter branch May 22, 2019 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants