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

nixpkgs manual: advise against overriding whole phases #26345

Merged
merged 1 commit into from Jun 19, 2017

Conversation

vcunat
Copy link
Member

@vcunat vcunat commented Jun 3, 2017

I've seen that mistake at least a few times already, e.g.
#26209 (comment)
It might perhaps seem counter-intuitive if one doesn't know nixpkgs well.

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
    • Linux
  • Tested compilation of all (= none) 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/ = none)
  • Fits CONTRIBUTING.md.

I've seen that mistake at least a few times already, e.g.
NixOS#26209 (comment)
It might perhaps seem counter-intuitive if one doesn't know nixpkgs well.
@mention-bot
Copy link

@vcunat, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @Ericson2314 and @pSub to be potential reviewers.

@dezgeg
Copy link
Contributor

dezgeg commented Jun 3, 2017

I think the problem with Qt5 would be rather avoided by adding _qtRmTmp and _qtFixCMakePaths to $preFixupPhases rather than $postInstallHooks.

@vcunat
Copy link
Member Author

vcunat commented Jun 3, 2017

Right, that certainly seems less risky in this respect. I guess @ttuegel knows best this stuff.

@ttuegel
Copy link
Member

ttuegel commented Jun 3, 2017

I think the problem with Qt5 would be rather avoided by adding _qtRmTmp and _qtFixCMakePaths to $preFixupPhases rather than $postInstallHooks.

Then you have the same problem whenever someone overrides fixupPhase. That's less common, but it imposes the same constraint on packagers: don't override any whole phase without running the pre- and post-hooks.

@dezgeg
Copy link
Contributor

dezgeg commented Jun 3, 2017

No, changing preFixupPhases adds a new phase between installPhase and fixupPhase, whether they're overwritten or not (it's different from a *Hook).

Yes, you now get screwed if a package specifies phases = ... but that typically causes borkage in any package (because everyone who does that doesn't know they need fixupPhase so now you get manpages in wrong places or huge closures due to not shrinking rpaths).

@layus
Copy link
Member

layus commented Jun 3, 2017

May I suggest to change the default builder in this respect.
For example, when "make install" does not work, using installPhase = ...; is much more natural than dontInstall = true; postInstall = .... Plus, in the later case, you cannot be sure that your postInstall runse before postInstall hooks.

tl;dr; I think hooks should not be part of the phase, and should not be explicitly overriden if need be.

@layus layus mentioned this pull request Jun 3, 2017
7 tasks
latter is convenient from a build script.</para>
latter is convenient from a build script.

However, typically one only wants to <emphasis>add</emphasis> some
Copy link
Member

Choose a reason for hiding this comment

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

Well, yes, but what if I really want to replace the default phase behavior, but keep the hooks. We should really explain that.

@gazally
Copy link
Contributor

gazally commented Jun 4, 2017

doc/stdenv.xml also contains this example:

stdenv.mkDerivation {
  name = "fnord-4.5";
  ...
  buildPhase = ''
    gcc foo.c -o foo
  '';
  installPhase = ''
    mkdir -p $out/bin
    cp foo $out/bin
  '';
}

If redefining installPhase is not the right thing to do, then this example should be changed. However (as a newcomer to nixpkgs) I prefer @layus's solution. Keep the simple example for the simple package simple.

@layus
Copy link
Member

layus commented Jun 4, 2017

Something weird happened. Apparently I did not post this message:

I have a working update to setup.sh that implements my above proposition in layus@66a2bde

To test on only one package, you will need overrideSetup from pkgs/stdenv/adapters.nix.
In particular, it works for #26209.

@ttuegel
Copy link
Member

ttuegel commented Jun 4, 2017

No, changing preFixupPhases adds a new phase between installPhase and fixupPhase, whether they're overwritten or not (it's different from a *Hook).

@dezgeg Oh, I understand now. Yes, I think that would be the most appropriate solution for the Qt 5 setup hooks. And I agree that although this may break packages that set phases = ..., generally one should not do that unless one understands very very well what one is doing!

@grahamc
Copy link
Member

grahamc commented Jun 5, 2017

Seems pretty good, reminds me of this very unfortunate bit in the nixpkgs manual (a similar bit is in the nix manual) too:

While the standard environment provides a generic builder, you can still supply your own build script:

stdenv.mkDerivation {
  name = "libfoo-1.2.3";
  ...
  builder = ./builder.sh;
}

@FRidh FRidh merged commit 75933da into NixOS:master Jun 19, 2017
@vcunat vcunat deleted the p/doc-override-phases branch June 19, 2017 07:48
@vcunat vcunat restored the p/doc-override-phases branch July 2, 2017 12:04
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

8 participants