How To - Override Python Packages

Published in the topic of NixOS, Python

Override Python Packages

With the following in ~/.nixpkgs/config.nix,

rec {
  pythonPackageOverrides = {super}: {
    matplotlib = super.matplotlib.override {
      enableGtk2 = true;
    };
  };

  packageOverrides = pkgs: rec {
    # Apply python package overrides in a way that everything will use the
    # overidden derivations.
    pythonPackages = pkgs.pythonPackages.override (oldAttrs: {
      self = pythonPackages;
    }) // (pythonPackageOverrides {
      self = pythonPackages;
      super = pkgs.pythonPackages;
    });
  };
}

Error Stack

Above code raising an error

error: while evaluating the attribute ‘buildInputs’ of the derivation ‘shell’ at /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/pkgs/stdenv/generic/make-derivation.nix:98:11:
while evaluating ‘getOutput’ at /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/lib/attrsets.nix:450:23, called from undefined position:
while evaluating anonymous function at /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/pkgs/stdenv/generic/make-derivation.nix:63:15, called from undefined position:
while evaluating ‘override’ at /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/lib/customisation.nix:78:20, called from /home/fazbdillah/.nixpkgs/config.nix:13:22:
while evaluating ‘makeOverridable’ at /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/lib/customisation.nix:72:24, called from /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/lib/customisation.nix:78:29:
anonymous function at /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/pkgs/top-level/python-packages.nix:9:1 called with unexpected argument ‘self’, at /nix/store/npfqckzk4s9jxkx1gwqysfqspg7ly2vq-nixos-17.09.2033.0c5a587eeb/nixos/lib/customisation.nix:74:12

Data Gathering

  1. Something to do with understanding lazy eval of nix, can it refer to itself (attribute)?

Solution

Hackish way

Get rid of the self argument both in function and its call.

Proper way

... not yet.


abdillah