cachix / devenv

Fast, Declarative, Reproducible, and Composable Developer Environments
https://devenv.sh
Apache License 2.0
3.79k stars 281 forks source link

Can not override python package #715

Open sandangel opened 1 year ago

sandangel commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

I can not override the python3 package with buildEnv:

To reproduce Please provide an sscce by creating a gist using devenv.nix, devenv.yaml, and optionally devenv.lock.

{
  description = "Description for the project";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    devenv.url = "github:cachix/devenv";
    nix2container.url = "github:nlewo/nix2container";
    nix2container.inputs.nixpkgs.follows = "nixpkgs";
    mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
  };

  outputs = inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.devenv.flakeModule
      ];
      systems = [ "x86_64-linux" "aarch64-linux" ];

      perSystem = { config, self', inputs', pkgs, lib, system, ... }:
        let
          python3 = pkgs.buildEnv {
            name = "python3";
            paths = [ pkgs.python3 pkgs.makeWrapper ];
            postBuild = ''
              wrapProgram $out/bin/python3 --set LD_LIBRARY_PATH ${lib.makeLibraryPath [ pkgs.stdenv.cc.cc.lib ]}
            '';
          };
        in
        {
          devenv.shells.default = {
            name = "stable-diffusion-webui";
            packages = with pkgs; [ pciutils wget ];
            languages.python.enable = true;
            languages.python.package = python3;
            languages.python.venv.enable = true;
            languages.python.venv.requirements = builtins.readFile ./requirements.txt;
          };
        };
    };
}

Version : latest main

Paste the output of $ devenv version here.

domenkozar commented 1 year ago

What's the error you get?

sandangel commented 1 year ago
error: attribute 'sitePackages' missing

       at /nix/store/2p68yxfrgiv6g31sx2iamf4ilqlpn7i2-source/src/modules/languages/python.nix:209:46:

          208|       ''
          209|         export PYTHONPATH="$DEVENV_PROFILE/${cfg.package.sitePackages}''${PYTHONPATH:+:$PYTHONPATH}"
             |                                              ^
          210|       ''

This is the error

domenkozar commented 1 year ago

You will need to use python.withPackages.

sandangel commented 1 year ago

sorry can you elaborate a bit more? I need to set the LD_LIBRARY_PATH for the python3 binary, how will that work with python.withPackages?

domenkozar commented 1 year ago

Does it help if you try python.buildEnv instead of pkgs.buildEnv?

domenkozar commented 11 months ago

@sandangel what python package fails to build here? I'm trying to write down a good python test suite.

sandangel commented 11 months ago

@domenkozar https://github.com/cachix/devenv/issues/715#issuecomment-1632782942

because when I override python package, it requires that package to have sitePackages property, which is not available if I use pkgs.buildEnv. I have not tried python.buildEnv yet.