cachix / nixpkgs-python

All Python versions, kept up-to-date on hourly basis using Nix.
Apache License 2.0
163 stars 10 forks source link

Cannot use `withPackages` #12

Open asymmetric opened 1 year ago

asymmetric commented 1 year ago

I have the following in my flake.nix:


devShells.default = pkgs.mkShell {

  packages = [
    (inputs.nixpkgs-python.packages.${system}."3.9.2".withPackages (ps: with ps; [ requests ]))
  ]

...
}

which fails to build:

error checking the existence of https://tarballs.nixos.org//:
curl: (6) Could not resolve host: tarballs.nixos.org

trying https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tar.xz
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: www.python.org
Warning: Problem : timeout. Will retry in 1 seconds. 3 retries left.
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: www.python.org
Warning: Problem : timeout. Will retry in 2 seconds. 2 retries left.
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: www.python.org
Warning: Problem : timeout. Will retry in 4 seconds. 1 retries left.
^M  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: www.python.org
error: cannot download Python-3.9.2.tar.xz from any mirror

If I try adding matplotlib instead, the error is different:

error:
       … while calling the 'derivationStrict' builtin

         at //builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'market-maker-stats'
         whose name attribute is located at /nix/store/46i6y04hr6zq7054mg2svxgk9zzpsiqy-source/pkgs/stdenv/generic/make-derivation.nix:303:7

       … while evaluating attribute 'nativeBuildInputs' of derivation 'market-maker-stats'

         at /nix/store/46i6y04hr6zq7054mg2svxgk9zzpsiqy-source/pkgs/stdenv/generic/make-derivation.nix:347:7:

          346|       depsBuildBuild              = lib.elemAt (lib.elemAt dependencies 0) 0;
          347|       nativeBuildInputs           = lib.elemAt (lib.elemAt dependencies 0) 1;
             |       ^
          348|       depsBuildTarget             = lib.elemAt (lib.elemAt dependencies 0) 2;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: function 'anonymous lambda' called with unexpected argument 'x11Support'

       at /nix/store/ysisn7pamb4plgr95w5szis24pfwihfd-source/self.nix:1:1:

            1| { nixpkgs-python, version }:
             | ^
            2|
domenkozar commented 1 year ago

https://www.python.org/ftp/python/3.9.2/Python-3.9.2.tar.xz

If I copy that to my browser it works. Do you have problems with networking?

domenkozar commented 1 year ago

@asymmetric could you provide exact steps and files how to reproduce it?

domenkozar commented 9 months ago

Same issue as https://github.com/cachix/nixpkgs-python/issues/14

domenkozar commented 6 months ago

Should be fixed on main, can you try?

asymmetric commented 6 months ago

I'm not currently using this anymore, so I won't be able to investigate further, but running nix develop with the following flake.nix errors with a different error:

  1. flake.nix

    {
    inputs.nixpkgs.url = "github:nixos/nixpkgs";
    inputs.nixpkgs-python.url = "github:cachix/nixpkgs-python";
    outputs = inputs:
    let
      system = "x86_64-linux";
      pkgs = inputs.nixpkgs.legacyPackages.${system};
    in
    {
      devShells.${system}.default = pkgs.mkShell {
        packages = (inputs.nixpkgs-python.packages.${system}."3.9.2".withPackages (ps: with ps; [ requests ]));
      };
    };
    }
  2. nix develop

error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nix-shell'
         whose name attribute is located at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/pkgs/stdenv/generic/make-derivation.nix:352:7

       … while evaluating attribute 'nativeBuildInputs' of derivation 'nix-shell'

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/pkgs/stdenv/generic/make-derivation.nix:396:7:

          395|       depsBuildBuild              = elemAt (elemAt dependencies 0) 0;
          396|       nativeBuildInputs           = elemAt (elemAt dependencies 0) 1;
             |       ^
          397|       depsBuildTarget             = elemAt (elemAt dependencies 0) 2;

       … while calling 'chooseDevOutputs'

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/lib/attrsets.nix:1146:5:

         1145|     # List of packages to pick `dev` outputs from
         1146|     drvs:
             |     ^
         1147|     builtins.map getDev drvs;

       … from call site

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/pkgs/stdenv/generic/make-derivation.nix:293:51:

          292|       (map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild))
          293|       (map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs'))
             |                                                   ^
          294|       (map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTarget" depsBuildTarget))

       … while calling 'checkDependencyList''

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/pkgs/stdenv/generic/make-derivation.nix:265:43:

          264|   checkDependencyList = checkDependencyList' [];
          265|   checkDependencyList' = positions: name: deps: flip imap1 deps (index: dep:
             |                                           ^
          266|     if isDerivation dep || dep == null || builtins.isString dep || builtins.isPath dep then dep

       … from call site

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/pkgs/stdenv/generic/make-derivation.nix:265:49:

          264|   checkDependencyList = checkDependencyList' [];
          265|   checkDependencyList' = positions: name: deps: flip imap1 deps (index: dep:
             |                                                 ^
          266|     if isDerivation dep || dep == null || builtins.isString dep || builtins.isPath dep then dep

       … while calling 'flip'

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/lib/trivial.nix:148:16:

          147|   */
          148|   flip = f: a: b: f b a;
             |                ^
          149|

       … from call site

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/lib/trivial.nix:148:19:

          147|   */
          148|   flip = f: a: b: f b a;
             |                   ^
          149|

       … while calling 'imap1'

         at /nix/store/sf3hbz4qg3wkii2hx9lfixf4srkd89y1-source/lib/lists.nix:165:14:

          164|   */
          165|   imap1 = f: list: genList (n: f (n + 1) (elemAt list n)) (length list);
             |              ^
          166|

       error: value is a set while a list was expected
genevieve-me commented 5 months ago

I'm not currently using this anymore, so I won't be able to investigate further, but running nix develop with the following flake.nix errors with a different error:

I was getting hit by the same error, then realized I was using a flake based on a template that still was on nixpkgs nixos-23.05. Once I updated to 23.11, this seems to be working. Sample config:

Edit: Not really related to this issue, but just in case anyone tries the below code: My example actually must specify python 3.11.6 or below for the time being (which is the version in nixpkgs 23.11), because of some annoying issues with a bug in pytest-mock (which is a transitive dependency of practically everything). See:

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
    nixpkgs-python.url = "github:cachix/nixpkgs-python";
    systems.url = "github:nix-systems/default";
    devenv.url = "github:cachix/devenv";
  };

  outputs = { self, nixpkgs, devenv, systems, nixpkgs-python, ... }@inputs:
    let forEachSystem = nixpkgs.lib.genAttrs (import systems);
    in {
      devShells = forEachSystem (system:
        let pkgs = nixpkgs.legacyPackages.${system};
        in {
          default = devenv.lib.mkShell {
            inherit inputs pkgs;
            modules = [{
              languages.python.enable = true;
              languages.python.version = "3.11.6";
              languages.python.venv.enable = true;
              packages = with pkgs; [
                postgresql
                playwright
                (nixpkgs-python.packages.${system}."3.11.6".withPackages (ps:
                  with ps; [
                    requests
                    pyyaml
                  ]))
              ];
              enterShell = ''pip install -r requirements.txt -e .'';
            }];
          };
        });
    };
}