7

I have some package to override in my configuration.nix. So I write the code as follows:

nixpkgs.config = {
  allowUnfree = true;
  packageOverrides = {
    pkgs: rec {
      #mumble + pulse audio
      mumble = pkgs.mumble.override {
        pulseSupport = true;
      };

      #kernel for intel ethernet and Testing e1000e package override
      linuxPackages.e1000e = pkgs.linuxPackages.e1000e.overrideDerivation (attrs: {
        name = "e1000e-3.3.3-${config.boot.kernelPackages.kernel.version}";
        src = fetchurl {
          url = "https://www.dropbox.com/s/pxx883hx9763ygn/e1000e-3.3.3.tar.gz?dl=0";
          sha256 = "1s2w54927fsxg0f037h31g3qkajgn5jd0x3yi1chxsyckrcr0x80";
        };
      });
    };
  };
};

but when I do nixos-rebuild switch, I got the following error:

syntax error, unexpected ':', expecting '.' or '=', at 37,11

which is at pkgs: rec {...

What did I do wrong? At first I write it by separating the pkgs like this:

packageOverrides = {
  pkgs: with pkgs: {......}; #this is for mumble
  pkgs: rec {...}; #this is for kernel
};

and still got the same error.

Sumner Evans
  • 8,951
  • 5
  • 30
  • 47
Rizary
  • 123
  • 1
  • 7

1 Answers1

16

The proper solution is:

nixpkgs.config = {

  allowUnfree = true;

  packageOverrides = super: let self = super.pkgs; in {

    mumble = super.mumble.override { pulseSupport = true; };

    linuxPackages = super.linuxPackages // {
      e1000e = super.linuxPackages.e1000e.overrideDerivation (old: {
        name = "e1000e-3.3.3-${config.boot.kernelPackages.kernel.version}";
        src = fetchurl {
          url = "https://www.dropbox.com/s/pxx883hx9763ygn/e1000e-3.3.3.tar.gz?dl=0";
          sha256 = "1s2w54927fsxg0f037h31g3qkajgn5jd0x3yi1chxsyckrcr0x80";
        };
      });
    };
  };
}

The variable super refers to the Nixpkgs set before the overrides are applied and self refers to it after the overrides are applied. It's important to distinguish these two explicitly to avoid infinite recursions, etc.

Also, note that your override

linuxPackages.e1000e = pkgs.linuxPackages.e1000e.overrideDerivation ...

replaces the linuxPackages attribute set with one that contains nothing but the (overriden) e1000e derivation. That's probably not what you want.

Peter Simons
  • 1,752
  • 17
  • 17
  • It doesn't look like `self`, introduced by the let binding, ever gets used. Is it even necessary in this situation? – Andrew Thaddeus Martin Dec 28 '16 at 14:48
  • 2
    The `self` binding is unnecessary, indeed. I added it to the example by habit, mostly, because oftentimes one does need it. – Peter Simons Dec 30 '16 at 11:45
  • regarding your comment "Also note... ", what's the right way to do it? – Henry Crutcher Jan 26 '17 at 06:20
  • 1
    should this nowadays be solved via overlays? Whats the difference between `packageOverrides` and using an overlay? – MarcDefiant Nov 15 '19 at 19:42
  • @MarcDefiant To **question1**: Yes, it can be, but [`packageOverrides` are not officially deprecated yet](https://github.com/NixOS/nixpkgs/issues/43266). The linked issue also has comments regarding use cases that may still hold true. To **question2**: Couldn't find much but hopefully the deprecation RFC will shed a light on it - once ready..:) – toraritte Jul 23 '21 at 12:53