Override a qt5 package

252 views
Skip to first unread message

Matthew Robbetts

unread,
Feb 16, 2018, 5:29:34 PM2/16/18
to nix-...@googlegroups.com
I’m getting some build failures on MacOS. Of course, I plan to file these to the issue tracker once I figure them out. But while I try to do that, I’m trying to make local changes.

I am currently stuck on qt5-qtwebengine. Can anyone advise me how to best to locally modify one of qt5’s subpackages?

My ultimate aim is to get the command:

$ nix-shell -p python3Packages.jupyter

to work. There were some build errors in some Python packages, which I’ve managed to overcome with:

packageOverrides = pkgs: rec {
    python3Packages = pkgs.python3Packages.override (oldAttrs: {
        overrides = self: super: {
            send2trash = super.send2trash.overrideAttrs (x: {
                doInstallCheck = false;
            });
            notebook = super.notebook.overrideAttrs (x: {
                doInstallCheck = false;
            });
        };
    });
};


And the build process continues beyond those packages now. However, it now fails at qt5.qtwebengine, so I’m trying to make an equivalent change for that (to override its postInstall section), and I can’t figure out how to make that work. qt5 doesn’t seem to offer an override function the way python3Packages does.

The nearest I’ve managed is adding something along the lines of:

    qt5 = pkgs.qt5 // {
        qtwebengine = pkgs.qt5.qtwebengine.overrideAttrs (y: {
            postInstall = '’
                ...
            "';
        });
    };

which “fixes” things as far as allowing:

$ nix-shell -p qt5.qtwebengine

to complete. However, packages which depend on qt5.qtwebengine (e.g. Jupyter, in this case) do not see the new definition, and their builds keep failing.


I suspect there is an obvious way to achieve what I want, but after looking at pkgs/development/libraries/qt-5/5.10/default.nix, I cannot figure it out for the life of me!

Any help would be very much appreciated!

Thomas Tuegel

unread,
Feb 17, 2018, 12:01:56 PM2/17/18
to Matthew Robbetts, nix-...@googlegroups.com
Matthew Robbetts <wingfe...@gmail.com> writes:

> The nearest I’ve managed is adding something along the lines of:
>
> qt5 = pkgs.qt5 // {
> qtwebengine = pkgs.qt5.qtwebengine.overrideAttrs (y: {
> postInstall = '’
> ...
> "';
> });
> };
>
> which “fixes” things as far as allowing:
>
> $ nix-shell -p qt5.qtwebengine
>
> to complete. However, packages which depend on qt5.qtwebengine
> (e.g. Jupyter, in this case) do not see the new definition, and their
> builds keep failing.


The reason this doesn't do what you expected is that `qt5' is defined as
a fixed-point so that every package sees a consistent set of
dependencies, e.g. no package may have two different versions of
`qtwebengine' in its closure.

`qt5' provides `overrideScope' that does what you need:

qt5 = pkgs.qt5.overrideScope (super: self: {
qtwebengine = super.qtwebengine.overrideAttrs (y: {
postInstall = ''
...
'';
});
});

I think of `overrideScope' as patching the package set before the
packages are built and `//' as patching the package set after.


Hope that helps,
Thomas

Matthew Robbetts

unread,
Feb 18, 2018, 9:14:14 PM2/18/18
to Thomas Tuegel, nix-...@googlegroups.com
I... am going to need to stare at these statements for a while until I understand them better.

But, thank you!! This works perfectly.


As an aside: is this mechanism an obvious thing? Even now that you’ve told me about it, I am looking at pkgs/development/libraries/qt-5/5.10/default.nix and I still don’t see it! I am guessing it comes in via the newScope argument? Is it documented anywhere?


Now the next failure on my way to Jupyter is with qtwebkit… which seems to emit an Abort trap: 6 error during something to do with ANGLE... Wish me luck!


Thanks,
Matt

Thomas Tuegel

unread,
Feb 19, 2018, 12:57:36 PM2/19/18
to Matthew Robbetts, nix-...@googlegroups.com
Matthew Robbetts <wingfe...@gmail.com> writes:

> As an aside: is this mechanism an obvious thing? Even now that you’ve
> told me about it, I am looking at
> pkgs/development/libraries/qt-5/5.10/default.nix and I still don’t see
> it! I am guessing it comes in via the newScope argument? Is it
> documented anywhere?


That file defines a function that is turned into a package set by a call
to `makeScope' in `pkgs/top-level/all-packages.nix'. The function takes
a package set as its argument; `makeScope' [1] works by calling the
function with its own result,

makeScope = newScope: f:
let self = f self // { ... };
in self;

which is an old lazy functional programming trick. `f' is the function
defined in `pkgs/development/libraries/qt-5/5.10/default.nix', which has
the form:

self: with self; {
qtbase = ...;
qtwebengine = ...;
...
}

In Nix, this is about the same as defining a recursive set:

rec {
qtbase = ...;
qtwebengine = ...;
...
}

The difference between the fixed-point trick and the recursive set is
when overrides are applied: If we override with `overrideScope' (only in
the fixed-point version) to override `qtbase', then `qtwebengine' will
depend on the new one. If we override with `//' (which is the only
option in the recursive-set version) then `qtwebengine' will depend on
the old one. Why does this matter? Imagine you have a build that depends
directly on `qtbase' and `qtwebengine' and that you override `qtbase';
if `qtwebengine' is still built with the old `qtbase', then the build
will pull in both old and new versions and there will be trouble!

I've already said more than I intended to, so I hope this clarifies
things, rather than adding to the confusion!


Regards,
Thomas


[1]. https://github.com/NixOS/nixpkgs/blob/943592f69850fd07dd2422da062b1c1ebc45974d/lib/customisation.nix#L196

Matthew Robbetts

unread,
Feb 20, 2018, 12:44:46 PM2/20/18
to Thomas Tuegel, nix-...@googlegroups.com
Hi Thomas,
Thanks very much for taking the time, this is super helpful :)
Reply all
Reply to author
Forward
0 new messages