DavHau / mach-nix

Create highly reproducible python environments
MIT License
853 stars 105 forks source link

mach-nix removes dependencies from nixpkgs-package #520

Open pawsen opened 1 year ago

pawsen commented 1 year ago

When trying to install matplotlib from nixpkgs, mach-nix removes some dependencies before building.

trace: removing dependency python3.8-mock-4.0.3 from matplotlib
trace: removing dependency python3.8-pytz-2022.2.1 from matplotlib
trace: removing dependency python3.8-tornado-6.2 from matplotlib
trace: removing dependency python3.8-tkinter-3.8.15 from matplotlib
trace: removing dependency python3.8-sphinx-5.1.1 from matplotlib

which leaves me with the Agg backend and thus I'm unable to view plots. How do I prevent mach-nix from removing the dependencies?

I have the following flake.nix

{
  description = "jupyter env";
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    pypi-deps-db = {
      url = "github:DavHau/pypi-deps-db";
      flake = false;
    };
    mach-nix = {
      url = "mach-nix/3.5.0";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
      inputs.pypi-deps-db.follows = "pypi-deps-db";
    };
  };

  outputs = { self, nixpkgs, flake-utils, mach-nix, pypi-deps-db }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};
        python = "python38";
        pythonPackages = pkgs.${python + "Packages"};

        pythonEnv = mach-nix.lib."${system}".mkPython {
          python = python;
          requirements = ''
            tk
            matplotlib
          '';
          # force matplotlib to be taken from nixpkgs
          providers.matplotlib = "nixpkgs";
          # try to keep tkinter as a dependency
          _.matplotlib.propagatedBuildInputs.mod = pySelf: self: oldVal:
             oldVal ++ [ pySelf.tk ];
        };
      in
      {
        devShell = pkgs.mkShell {
          buildInputs = [
            pythonEnv
            # might be a solution - but then we need to build scipy, etc --> takes a lot of time
            # pythonPackages.matplotlib
          ];
          '';
        };
      });
}

invoked with nix develop.

If I use matplotlib from wheel (i.e. remove providers.matplotlib = "nixpkgs";), I still only have Agg as a backend.

Anyone have suggestions to how I can get matplotlib with a gui-backend?

ref issue 330

liubigli-tcp commented 1 year ago

Hello! I have the same problem! Did you find any solution?