Poetry2nix Flake构建报错:`poetry2nix.overrides`属性缺失
问题
基于poetry2nix官方应用模板编写flake.nix,仅修改overrides部分,执行nix build命令时报错,提示poetry2nix.overrides属性缺失。
我的flake代码
{ description = "bear"; inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; poetry2nix = { url = "github:nix-community/poetry2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, flake-utils, poetry2nix }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication; in { packages = { bear = mkPoetryApplication { packageName = "bearctl"; projectDir = ./.; overrides = poetry2nix.overrides.withDefaults (self: super: { pycairo = super.pycairo.overridePythonAttrs (old: { nativeBuildInputs = [ self.meson pkgs.buildPackages.pkg-config ]; }); pygobject = super.pygobject.overridePythonAttrs (old: { buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; }); urllib3 = super.urllib3.overridePythonAttrs (old: { buildInputs = (old.buildInputs or [ ]) ++ [ self.hatch-vcs ]; }); pipewire-python = super.pipewire-python.overridePythonAttrs (old: { buildInputs = (old.buildInputs or [ ]) ++ [ self.flit-core ]; }); }); buildInputs = (with pkgs; [ pkgs.pipewire pkgs.lorri pkgs.xorg.xset pkgs.i3 ]); }; default = self.packages.${system}.bear; }; devShells.default = pkgs.mkShell { inputsFrom = [ self.packages.${system}.myapp ]; packages = [ pkgs.poetry ]; }; }); }
报错信息
✦ ❯ nix build . warning: Git tree '/home/robin/devel/bearctl' is dirty error: … while evaluating the attribute 'packages.x86_64-linux.bear' at /nix/store/2xz05z3ar2i1fr06mzr434f6n59513g6-source/flake.nix:88:11: 87| packages = { 88| bear = mkPoetryApplication { | ^ 89| packageName = "bearctl"; … while evaluating the attribute 'pkgs.buildPythonPackage' at /nix/store/yy19v2dwb8ldphvia9smajvwv3ycx2c1-source/pkgs/development/interpreters/python/passthrufun.nix:87:5: 86| withPackages = import ./with-packages.nix { inherit buildEnv pythonPackages;}; 87| pkgs = pythonPackages; | ^ 88| interpreter = "${self}/bin/${executable}"; (stack trace truncated; use '--show-trace' to show the full trace) error: attribute 'overrides' missing at /nix/store/2xz05z3ar2i1fr06mzr434f6n59513g6-source/flake.nix:92:25: 91| 92| overrides = poetry2nix.overrides.withDefaults (self: super: { | ^ 93|
解决方案
核心问题
poetry2nix.overrides并非直接存在于flake输入的poetry2nix对象中,你错误地直接调用了这个不存在的属性。正确的overrides需要从poetry2nix.lib.mkPoetry2Nix生成的上下文获取,或者通过poetry2nix.lib调用。
修正步骤
1. 调整overrides的获取方式
在let块中,从mkPoetry2Nix的返回值里同时继承overrides:
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication overrides;
然后在mkPoetryApplication中使用这个本地的overrides变量:
overrides = overrides.withDefaults (self: super: { # 你的override代码保持不变 });
2. 修正devShell中的包名错误
devShell里引用的myapp是不存在的,需要改成实际的包名bear:
inputsFrom = [ self.packages.${system}.bear ];
修正后的完整flake代码
{ description = "bear"; inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixos-23.11"; poetry2nix = { url = "github:nix-community/poetry2nix"; inputs.nixpkgs.follows = "nixpkgs"; }; }; outputs = { self, nixpkgs, flake-utils, poetry2nix }: flake-utils.lib.eachDefaultSystem (system: let pkgs = nixpkgs.legacyPackages.${system}; inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication overrides; in { packages = { bear = mkPoetryApplication { packageName = "bearctl"; projectDir = ./.; overrides = overrides.withDefaults (self: super: { pycairo = super.pycairo.overridePythonAttrs (old: { nativeBuildInputs = [ self.meson pkgs.buildPackages.pkg-config ]; }); pygobject = super.pygobject.overridePythonAttrs (old: { buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; }); urllib3 = super.urllib3.overridePythonAttrs (old: { buildInputs = (old.buildInputs or [ ]) ++ [ self.hatch-vcs ]; }); pipewire-python = super.pipewire-python.overridePythonAttrs (old: { buildInputs = (old.buildInputs or [ ]) ++ [ self.flit-core ]; }); }); buildInputs = (with pkgs; [ pkgs.pipewire pkgs.lorri pkgs.xorg.xset pkgs.i3 ]); }; default = self.packages.${system}.bear; }; devShells.default = pkgs.mkShell { inputsFrom = [ self.packages.${system}.bear ]; packages = [ pkgs.poetry ]; }; }); }
内容的提问来源于stack exchange,提问作者thepandaatemyface
相关产品推荐
相关产品推荐

