如何在Nixos configuration.nix中覆盖2(两个)包

时间:2016-03-15 00:17:57

标签: nix nixos

我的配置中有一些要覆盖的包.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
};

仍然有同样的错误。

1 个答案:

答案 0 :(得分:10)

正确的解决方案是:

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是指之前应用覆盖,而self在应用覆盖之后引用 。明确区分这两者以避免无限递归等很重要。

另请注意您的覆盖

  

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

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