nixpkgs.overlays and nixpkgs.config.packageoverrides不反映在环境中。Systempackages

发布于 2025-02-11 16:53:51 字数 4069 浏览 2 评论 0 原文

看来,当我覆盖 nixpkgs.config.packageoverrides nixpkgs.overlays 的python应用程序 Environment> Environment.smentpackages 不在使用这些覆盖。我如何才能在Python3应用程序中使用该覆盖的Python3软件包?

示例使用 nixpkgs.overlays > darwin-configuration.nix :

{ config, pkgs, lib, ... }:
{
  environment.systemPackages =
    [
      pkgs.myawscli2
    ];
  nixpkgs.overlays = let overlayRemovePyopenssl = self: super: 
    let removePyopenssl = pythonpkgs:
      lib.filter
        (pythonpkg: !(pythonpkg != null && pythonpkg ? pname && pythonpkg.pname == "pyopenssl"))
        pythonpkgs;
    in {
      python3 = super.python3.override {
        packageOverrides = python-self: python-super: rec {
          # Delete pyopenssl; workaround for broken package on darwin-aarch64
          # “Package ‘python3.10-pyopenssl-22.0.0’ in /nix/store/<hash>-nixpkgs/nixpkgs/pkgs/development/python-modules/pyopenssl/default.nix:73 is marked as broken, refusing to evaluate”
          # https://github.com/NixOS/nixpkgs/issues/174457
          urllib3 = python-super.urllib3.overridePythonAttrs (origattrs: rec {
            propagatedBuildInputs = removePyopenssl origattrs.propagatedBuildInputs;
          });
          twisted = python-super.twisted.overridePythonAttrs (origattrs: {
            checkInputs = removePyopenssl origattrs.checkInputs;
          });
        };
      };
      myawscli2 = (self.awscli2.override {
        # override the python3 arg of awscli2
        # https://github.com/NixOS/nixpkgs/blob/f72be3af76fb7dc45e2088d8cb9aba1e6767a930/pkgs/tools/admin/awscli2/default.nix#L2
        python3 = self.python3;
      });
    }; in
  [
    overlayRemovePyopenssl
  ];
  system.stateVersion = 4;
}

覆盖层适当地应用于单个Python软件包urllib3:

nix-repl> lib = import <nixpkgs>.lib
nix-repl> :l <darwin>
nix-repl> lib.forEach pkgs.python3.pkgs.urllib3.propagatedBuildInputs (x: x.pname)
[ "brotli" "certifi" "cryptography" "idna" "python3" ]

但是,覆盖层是不是 应用于Python应用程序使用Urllib3。请注意,AWSCli2使用时,pyopenssl在Urllib3的依赖项中:

nix-repl> lib.forEach (lib.findFirst (x: x.pname == "urllib3") null pkgs.awscli2.propagatedBuildInputs).propagatedBuildInputs (x: x.pname)
[ "brotli" "certifi" "cryptography" "idna" "pyopenssl" "python3" ]

我还使用 nixpkgs.config.package.packageoverrides 尝试了相同的效果:

{ config, pkgs, lib, ... }:
{
  environment.systemPackages =
    [
      pkgs.myawscli2
    ];
  nixpkgs.config.packageOverrides = super: 
    let removePyopenssl = pythonpkgs:
      lib.filter
        (pythonpkg: !(pythonpkg != null && lib.hasAttr "pname" pythonpkg && pythonpkg.pname == "pyopenssl"))
        pythonpkgs;
    in {
      python3 = super.python3.override {
        packageOverrides = python-self: python-super: rec {
          # workaround for
          # “Package ‘python3.10-pyopenssl-22.0.0’ in /nix/store/<hash>-nixpkgs/nixpkgs/pkgs/development/python-modules/pyopenssl/default.nix:73 is marked as broken, refusing to evaluate”
          # https://github.com/NixOS/nixpkgs/issues/174457
          urllib3 = python-super.urllib3.overridePythonAttrs (origattrs: rec {
            propagatedBuildInputs = removePyopenssl origattrs.propagatedBuildInputs;
          });
          twisted = python-super.twisted.overridePythonAttrs (origattrs: {
            checkInputs = removePyopenssl origattrs.checkInputs;
          });
        };
      };
      myawscli2 = (pkgs.awscli2.override {
        python3 = pkgs.python3;
      });
    };
  system.stateVersion = 4;
}

这似乎与 nixpkgs手册代码> pythonpackages.twisted 现在已被全局覆盖。现在使用所有包装以及所有引用 twisted (例如 services.buildbot-worker )的NIXOS服务现在使用新的定义”

It seems that when I override a python3 package in nixpkgs.config.packageOverrides or nixpkgs.overlays, a python application in environment.systemPackages is not using those overrides. How can I get that overridden python3 package to be used in a python3 application?

Example darwin-configuration.nix that uses nixpkgs.overlays:

{ config, pkgs, lib, ... }:
{
  environment.systemPackages =
    [
      pkgs.myawscli2
    ];
  nixpkgs.overlays = let overlayRemovePyopenssl = self: super: 
    let removePyopenssl = pythonpkgs:
      lib.filter
        (pythonpkg: !(pythonpkg != null && pythonpkg ? pname && pythonpkg.pname == "pyopenssl"))
        pythonpkgs;
    in {
      python3 = super.python3.override {
        packageOverrides = python-self: python-super: rec {
          # Delete pyopenssl; workaround for broken package on darwin-aarch64
          # “Package ‘python3.10-pyopenssl-22.0.0’ in /nix/store/<hash>-nixpkgs/nixpkgs/pkgs/development/python-modules/pyopenssl/default.nix:73 is marked as broken, refusing to evaluate”
          # https://github.com/NixOS/nixpkgs/issues/174457
          urllib3 = python-super.urllib3.overridePythonAttrs (origattrs: rec {
            propagatedBuildInputs = removePyopenssl origattrs.propagatedBuildInputs;
          });
          twisted = python-super.twisted.overridePythonAttrs (origattrs: {
            checkInputs = removePyopenssl origattrs.checkInputs;
          });
        };
      };
      myawscli2 = (self.awscli2.override {
        # override the python3 arg of awscli2
        # https://github.com/NixOS/nixpkgs/blob/f72be3af76fb7dc45e2088d8cb9aba1e6767a930/pkgs/tools/admin/awscli2/default.nix#L2
        python3 = self.python3;
      });
    }; in
  [
    overlayRemovePyopenssl
  ];
  system.stateVersion = 4;
}

The overlay is applied properly in the individual python package urllib3:

nix-repl> lib = import <nixpkgs>.lib
nix-repl> :l <darwin>
nix-repl> lib.forEach pkgs.python3.pkgs.urllib3.propagatedBuildInputs (x: x.pname)
[ "brotli" "certifi" "cryptography" "idna" "python3" ]

However, the overlay was not applied to the python application that uses urllib3. Note that pyopenssl is in the dependencies of urllib3 when used by awscli2:

nix-repl> lib.forEach (lib.findFirst (x: x.pname == "urllib3") null pkgs.awscli2.propagatedBuildInputs).propagatedBuildInputs (x: x.pname)
[ "brotli" "certifi" "cryptography" "idna" "pyopenssl" "python3" ]

I also tried the same thing with nixpkgs.config.packageOverrides with the same effect:

{ config, pkgs, lib, ... }:
{
  environment.systemPackages =
    [
      pkgs.myawscli2
    ];
  nixpkgs.config.packageOverrides = super: 
    let removePyopenssl = pythonpkgs:
      lib.filter
        (pythonpkg: !(pythonpkg != null && lib.hasAttr "pname" pythonpkg && pythonpkg.pname == "pyopenssl"))
        pythonpkgs;
    in {
      python3 = super.python3.override {
        packageOverrides = python-self: python-super: rec {
          # workaround for
          # “Package ‘python3.10-pyopenssl-22.0.0’ in /nix/store/<hash>-nixpkgs/nixpkgs/pkgs/development/python-modules/pyopenssl/default.nix:73 is marked as broken, refusing to evaluate”
          # https://github.com/NixOS/nixpkgs/issues/174457
          urllib3 = python-super.urllib3.overridePythonAttrs (origattrs: rec {
            propagatedBuildInputs = removePyopenssl origattrs.propagatedBuildInputs;
          });
          twisted = python-super.twisted.overridePythonAttrs (origattrs: {
            checkInputs = removePyopenssl origattrs.checkInputs;
          });
        };
      };
      myawscli2 = (pkgs.awscli2.override {
        python3 = pkgs.python3;
      });
    };
  system.stateVersion = 4;
}

This seems to contradict the nixpkgs manual, which says: “pythonPackages.twisted is now globally overridden. All packages and also all NixOS services that reference twisted (such as services.buildbot-worker) now use the new definition”

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野の 2025-02-18 16:53:51

我还在awscli2/default. nix 调用 python3.override {packageoverrides =…;}

  py = python3.override {
    packageOverrides = self: super: {
      …
    };
  };

不幸的是,这覆盖了我自己的 .override {packageoverrides =…;} 。不幸的是,您无法撰写(Python.override {packageOverRides =…;})。覆盖{packageoverrides =…;}

我通过检查nixpkgs并编辑AWSCli2 Nix来解决此问题。 packageoverrides 带有 packageoverrides 从参数:

  py = python3.override (oldargs: {
    packageOverrides = self: super: {
      …
    } // (if oldargs?packageOverrides then (oldargs.packageOverrides self super) else super);
  });

I also asked this on Element. The problem is that awscli2/default.nix calls python3.override {packageOverrides = …;}:

  py = python3.override {
    packageOverrides = self: super: {
      …
    };
  };

This unfortunately overwrites my own .override {packageOverrides = …;}. Unfortunately you can’t compose (python.override {packageOverrides = …;}).override {packageOverrides = …;}

I worked around this by checking out nixpkgs and editing the awscli2 nix to combine the python application’s packageOverrides with packageOverrides from the arguments:

  py = python3.override (oldargs: {
    packageOverrides = self: super: {
      …
    } // (if oldargs?packageOverrides then (oldargs.packageOverrides self super) else super);
  });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文