Override package in poetry2nix

Hi

I am new to using poetry2nix to develop a python package. I like the philosophy of nix, but currently it is a bit of a mixed experience. Currently I am struggling to get an interactive plotting backend with matplotlib to work. By default, GTK3 is disabled for matplotlib. How do I specify that I want it enabled in my poetry2nix flake?

Thanks

Hey, this might be a bit late, but here is a flake.nix that works for me (the default override appears to be broken).

This will give you gtk3/4cairo support


{
  description = "Analysis code for the realization of the NHQW in fibre loops.";

  inputs = {
    flake-utils.url = "github:numtide/flake-utils";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
    poetry2nix = {
      url = "github:nix-community/poetry2nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs @ { self, nixpkgs, flake-utils, ... }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        poetry2nix = inputs.poetry2nix.lib.mkPoetry2Nix { inherit pkgs;};
      in
        {
          packages = {
            fibreMagic = poetry2nix.mkPoetryApplication {
              projectDir = self;
              preferWheels = true;


              overrides = poetry2nix.overrides.withDefaults (final: prev: {
                matplotlib = with pkgs; prev.matplotlib.overridePythonAttrs (
                  old:
                  let
                    interactive = true;

                    passthru = {
                      config = {
                        directories = { basedirlist = "."; };
                        libs = {
                          system_freetype = true;
                          system_qhull = true;
                        };
                      };
                    };

                    inherit (pkgs) tk tcl wayland qhull;
                    inherit (pkgs.xorg) libX11;
                  in
                    {
                      XDG_RUNTIME_DIR = "/tmp";

                      buildInputs = old.buildInputs or [ ] ++ [
                        pkgs.which
                      ];

                      propagatedBuildInputs = (old.propagatedBuildInputs or [ ]) ++ [
                        final.certifi
                        pkgs.libpng
                        pkgs.freetype
                        qhull
                      ]
                      ++ [ pkgs.cairo pkgs.librsvg final.pycairo pkgs.gtk3 pkgs.gtk4 pkgs.gobject-introspection final.pygobject3 ]  ;

                      nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [
                        pkg-config
                      ] ++ [
                        final.setuptools-scm
                      ];

                      # Clang doesn't understand -fno-strict-overflow, and matplotlib builds with -Werror
                      hardeningDisable = if stdenv.isDarwin then [ "strictoverflow" ] else [ ];

                      passthru = old.passthru or { } // passthru;

                      MPLSETUPCFG = pkgs.writeText "mplsetup.cfg" (lib.generators.toINI { } passthru.config);

                    }
                );


              });
            };
            default = self.packages.${system}.fibreMagic;
          };

          # Shell for app dependencies.
          #
          #     nix develop
          #
          # Use this shell for developing your app.
          devShells.default = pkgs.mkShell {
            inputsFrom = [ self.packages.${system}.fibreMagic ];
            package = with pkgs; [
              ruff pyright
            ];
          };

          # Shell for poetry.
          #
          #     nix develop .#poetry
          #
          # Use this shell for changes to pyproject.toml and poetry.lock.
          devShells.poetry = pkgs.mkShell {
            packages = [ pkgs.poetry ];
          };
        });
}