6

我的 configuration.nix 中有一些包要覆盖。所以我编写代码如下:

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";
        };
      });
    };
  };
};

但是当我这样做时nixos-rebuild switch,出现以下错误:

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

这是在pkgs: rec {...

我做错了什么?起初我通过像这样分隔 pkgs 来编写它:

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

并且仍然得到同样的错误。

4

1 回答 1

15

正确的解决方案是:

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";
        };
      });
    };
  };
}

该变量引用在应用覆盖之前super设置的 Nixpkgs ,并在应用覆盖之后引用它。明确区分这两者以避免无限递归等很重要。self

另外,请注意您的覆盖

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

将属性集替换为linuxPackages只包含(重写的)e1000e派生的属性集。这可能不是你想要的。

于 2016-03-15T12:35:38.243 回答