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

buildDunePackage: add support function and use it in a few packages #49684

Merged
merged 4 commits into from Nov 7, 2018

Conversation

Zimmi48
Copy link
Member

@Zimmi48 Zimmi48 commented Nov 3, 2018

Motivation for this change

This takes advantage of the uniformization of the OCaml package ecosystem around the dune build system (and often the accompanying dune-release) to simplify the way usual OCaml derivations are prepared in nixpkgs.

cc @vbgl

Things done

I have ported a few packages which allowed me to refine the design of dunePackage but not all of them yet.

  • Tested using sandboxing (nix.useSandbox on NixOS, or option 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/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Fits CONTRIBUTING.md.

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 4, 2018

I can certainly backtrack of the src refactoring but I would find this pretty sad given that virtually all the dune packages that I refactored took their sources from GitHub. Furthermore, this setup makes it simpler for package maintainers to use the dune-release tarball if it is available (just set dune-release = true). In the previous setting, switching from one setup to the other was significantly more complicated. Of course, I can also keep only the shared unpackPhase when dune-release = true is set.
I don't see any issue in changing the hash when doing this refactoring (switch from fetch unpacked to fetch). It's not bringing any complexity after the refactoring.

@Mic92
Copy link
Member

Mic92 commented Nov 4, 2018

There could be a new fetcher for dune release tarballs.

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 4, 2018

OK let's postpone this part then.

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 4, 2018

@Mic92 I still do not know what you meant by "build hook" but the composability aspect might not be so important given how similar all dune packages are (and anyways, the current setup allows to override any given phase).

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 4, 2018

OMG, this is horrible 😱 Don't count on me to imitate that 😉

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 5, 2018

Updated. This makes it a quite smaller refactoring (although I have updated even more packages).

pkgs/top-level/ocaml-packages.nix Outdated Show resolved Hide resolved
pkgs/build-support/ocaml/dune.nix Outdated Show resolved Hide resolved
pkgs/build-support/ocaml/dune.nix Outdated Show resolved Hide resolved
pkgs/build-support/ocaml/dune.nix Outdated Show resolved Hide resolved
@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 5, 2018

Where are these hooks coming from? Where is this documented? How is it different from pre and post phases?
About the need to document this, I agree and I will take care of this.

@Mic92
Copy link
Member

Mic92 commented Nov 5, 2018

Build phases are described in the stdenv documentation: https://nixos.org/nixpkgs/manual/#sec-stdenv-phases . It is not different from preBuild etc, but since you are overwriting buildPhase and so on, you need to call runHook explicitly or else those phases are no longer called.

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 5, 2018

OK, I knew about this part of the doc but I had missed that this had to be run from the build phases themselves. Will update.

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 5, 2018

Refactoring complete. Doc remains.

@Mic92 Mic92 changed the title dunePackage: add support function and use it in a few packages buildDunePackage: add support function and use it in a few packages Nov 5, 2018
@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 6, 2018

The PR is ready now, and it includes the doc. It was quite time that OCaml got its section in the nixpkgs manual!

minimumOCamlVersion = "4.01";

src = fetchurl {
url = "https://github.com/flowtype/ocaml-${pname}/releases/download/v${version}/${pname}-${version}.tbz";
Copy link
Member

@Mic92 Mic92 Nov 6, 2018

Choose a reason for hiding this comment

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

In future this could be solved with the following trick:

fetchDuneRelease {
  url = "https://github.com/flowtype/ocaml-wtf8/releases/download/v${version}/ocaml-wtf8-${version}.tbz";
  sha256 = "1msg3vycd3k8qqj61sc23qks541cxpb97vrnrvrhjnqxsqnh6ygq";
};

fetchDuneRelease = { url, ... } @args : fetchurl (args // {
  url = "${url}#package.tar.bz2";
})

This would do the trick in the unpack phase.

Copy link
Member

Choose a reason for hiding this comment

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

An alternative would be override the unpack phase of buildDunePackage to also learn this extension.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed but voluntarily left for future work.

Copy link
Member

@Mic92 Mic92 left a comment

Choose a reason for hiding this comment

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

I tested the examples. @vbgl any last comments?

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 7, 2018

CI had passed but an update to odoc meant that I had to rebase the PR and fix the conflicts. Can this PR get merged now? I would like to avoid having to rebase it once more.

@vbgl vbgl mentioned this pull request Nov 7, 2018
9 tasks
@Mic92 Mic92 merged commit 7e2e6e1 into NixOS:master Nov 7, 2018
@vbgl
Copy link
Contributor

vbgl commented Nov 7, 2018

I’m very surprised you did not find any interesting issues with the zmq packages when testing this PR…

@Mic92
Copy link
Member

Mic92 commented Nov 7, 2018

I built all affected packages on Linux. Are there problems on other architectures?

@Mic92
Copy link
Member

Mic92 commented Nov 7, 2018

This might have been not included in the list as ocamlPackages are not recursed.

$ nix-shell -p acgtk -p eff -p flow -p fstar -p google-drive-ocamlfuse -p jackline -p libbap -p liquidsoap -p ocaml-top -p ocamlformat -p patdiff -p pyre -p reason -p satysfi -p stog -p trv -p virt-top

@Mic92
Copy link
Member

Mic92 commented Nov 7, 2018

But also that one seems to work:

$ nix-shell -p ocamlPackages.zmq
these derivations will be built:
  /nix/store/scsiz53z9wyypkrrgndnmp747f477nd5-source.drv
  /nix/store/kaxk9z132zkg7mn9j9yd5ah3f7v0d295-ocaml4.06.1-zmq-20180726.drv
these paths will be fetched (0.21 MiB download, 1.06 MiB unpacked):
  /nix/store/5217m8ssa8n7x0vpw8ndxplwf72wqrxs-czmq-4.1.1
copying path '/nix/store/5217m8ssa8n7x0vpw8ndxplwf72wqrxs-czmq-4.1.1' from 'https://cache.nixos.org'...
building '/nix/store/scsiz53z9wyypkrrgndnmp747f477nd5-source.drv'...

trying https://github.com/issuu/ocaml-zmq/archive/d312a8458d6b688f75470248f11875fbbfa5bb1a.tar.gz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   157    0   157    0     0    371      0 --:--:-- --:--:-- --:--:--   370
100 30169    0 30169    0     0  30259      0 --:--:-- --:--:-- --:--:-- 30259
unpacking source archive /build/d312a8458d6b688f75470248f11875fbbfa5bb1a.tar.gz
building '/nix/store/kaxk9z132zkg7mn9j9yd5ah3f7v0d295-ocaml4.06.1-zmq-20180726.drv'...
unpacking sources
unpacking source archive /nix/store/24j11nwkl20f4v6rm3x8sgb8h51638b7-source
source root is source
patching sources
applying patch /nix/store/kg1vs1b0azdk8i5hyzwrw5z9d7bazifh-ocaml-zmq-issue43.patch
patching file zmq/src/caml_zmq_stubs.c
configuring
no configure script, doing nothing
building
installing
Processing file zmq.install as zmq.
post-installation fixup
moving /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726/doc to /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726/share/doc
shrinking RPATHs of ELF executables and libraries in /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726
shrinking /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726/lib/ocaml/4.06.1/site-lib/stublibs/dllzmq_stubs.so
shrinking /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726/lib/ocaml/4.06.1/site-lib/zmq/deferred/zmq_deferred.cmxs
shrinking /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726/lib/ocaml/4.06.1/site-lib/zmq/zmq.cmxs
strip is /nix/store/vcc4svb8gy29g4pam2zja6llkbcwsyiq-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726/lib
patching script interpreter paths in /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726
checking for references to /build in /nix/store/dr8qcfxiphjpmvjszjnmg9y1zdjv0i8i-ocaml4.06.1-zmq-20180726...
bash: /tmp/env-vars: cannot overwrite existing file

@vbgl
Copy link
Contributor

vbgl commented Nov 7, 2018

This one is broken: ocamlPackages_latest.zmq. It was already broken. Now it is harder to fix.

@Mic92
Copy link
Member

Mic92 commented Nov 7, 2018

I don't see why this should be harder to fix then before.

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 7, 2018

@vbgl Can you explain how this makes it harder to fix? The goal of this PR was to make the life of contributors (I included) easier not harder.

@Zimmi48
Copy link
Member Author

Zimmi48 commented Nov 7, 2018

In any case, if zmq is not well served by buildDunePackage, feel free to revert the change on this file only.

@Zimmi48 Zimmi48 deleted the dune-package branch November 7, 2018 18:47
@vbgl
Copy link
Contributor

vbgl commented Nov 8, 2018

PR to fix zmq: #49921. Suggestions welcome.

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

4 participants