如何在 Nixos configuration.nix 中覆盖 2(两个)包
How to override 2 (two) packages in Nixos configuration.nix
我的 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 {...
我做错了什么?一开始我是这样写的:
packageOverrides = {
pkgs: with pkgs: {......}; #this is for mumble
pkgs: rec {...}; #this is for kernel
};
仍然出现同样的错误。
正确的解决方法是:
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
引用它 在 [=26] 之后=] 覆盖被应用。重要的是明确区分这两者以避免无限递归等。
另外,请注意您的覆盖
linuxPackages.e1000e = pkgs.linuxPackages.e1000e.overrideDerivation ...
将 linuxPackages
属性集替换为只包含(覆盖的)e1000e
推导的属性集。这可能不是你想要的。
我的 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 {...
我做错了什么?一开始我是这样写的:
packageOverrides = {
pkgs: with pkgs: {......}; #this is for mumble
pkgs: rec {...}; #this is for kernel
};
仍然出现同样的错误。
正确的解决方法是:
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
引用它 在 [=26] 之后=] 覆盖被应用。重要的是明确区分这两者以避免无限递归等。
另外,请注意您的覆盖
linuxPackages.e1000e = pkgs.linuxPackages.e1000e.overrideDerivation ...
将 linuxPackages
属性集替换为只包含(覆盖的)e1000e
推导的属性集。这可能不是你想要的。