NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.07k stars 14.13k forks source link

Doc: example dont work in 15.17.1.4. Including a derivation using callPackage #72167

Open davidak opened 5 years ago

davidak commented 5 years ago

Describe the bug

I just copied the code and put it into nixpkgs.overlays.

Build fails.

To Reproduce Steps to reproduce the behavior:

packages/toolz/default.nix

{ lib, buildPythonPackage }:

buildPythonPackage rec {
  pname = "toolz";
  version = "0.7.4";

  src = fetchPypi {
    inherit pname version;
    sha256 = "43c2c9e5e7a16b6c88ba3088a9bfc82f7db8e13378be7c78d6c14a5f8ed05afd";
  };

  meta = with lib; {
    homepage = "https://github.com/pytoolz/toolz/";
    description = "List processing tools and functional utilities";
    license = licenses.bsd3;
    maintainers = with maintainers; [ fridh ];
  };
}

configuration.nix

...
  nixpkgs.overlays = [
  (self: super:
  {
    toolz = super.callPackage ../../packages/toolz {
      buildPythonPackage = super.python35Packages.buildPythonPackage;
    };
  }
  )];
...
  environment.systemPackages = with pkgs; [ toolz ];
[root@ethmoid:~]# nixos-rebuild switch
building Nix...
building the system configuration...
trace: Default desktop manager (pantheon) not found at evaluation time.
These are the known valid session names:
  services.xserver.desktopManager.default = "none";
It's also possible the default can be found in one of these packages:
  elementary-session-settings-5.0.3

error: undefined variable 'fetchPypi' at /root/nixos-config/packages/toolz/default.nix:7:9
(use '--show-trace' to show detailed location information)

when i define fetchPypi in the package like:

{ lib, fetchPypi, buildPythonPackage }:

I get this error:

error: anonymous function at /root/nixos-config/packages/toolz/default.nix:1:1 called without required argument 'fetchPypi', at /nix/store/c8gsa6n8lb62xsjkidhivx01a1iyz1y4-nixos-19.09.907.f6dac808387/nixos/lib/customisation.nix:69:12
(use '--show-trace' to show detailed location information)

Why is that missing in this context? That is not a problem with fetchurl! It is done exactly like this in nixpkgs https://github.com/NixOS/nixpkgs/blob/5102201ba4f22e6d91e5a13d9b1e89eb4b8e4eb5/pkgs/development/python-modules/poetry/glob2.nix.

In the documentation it says: "We now call this function using callPackage in the definition of our environment". Please add a filename and command, how to build the package. I might doing it wrong because the documentation is not detailed enough here.

Expected behavior Package get's build and installed.

Metadata

Maintainer information:

# a list of nixpkgs attributes affected by the problem
attribute:
# a list of nixos modules affected by the problem
module:
davidak commented 5 years ago

It works when i also specify fetchPypi in the overlay.

  nixpkgs.overlays = [
  (self: super:
  {
    toolz = super.callPackage ../../packages/toolz {
      fetchPypi = super.python35Packages.fetchPypi;
      buildPythonPackage = super.python35Packages.buildPythonPackage;
    };
  }
  )];

But the build of that package fails:

writing manifest file 'toolz.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
  File "nix_run_setup", line 8, in <module>
    exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))
  File "setup.py", line 22, in <module>
    zip_safe=False)
  File "/nix/store/pky8wchkji14q3nabm7dps7c0frsqi0j-python3.5-setuptools-41.2.0/lib/python3.5/site-packages/setuptools-41.2.0-py3.5.egg/setuptools/__init__.py", line 145, in setup
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/nix/store/pky8wchkji14q3nabm7dps7c0frsqi0j-python3.5-setuptools-41.2.0/lib/python3.5/site-packages/setuptools-41.2.0-py3.5.egg/setuptools/command/test.py", line 229, in run
  File "/nix/store/pky8wchkji14q3nabm7dps7c0frsqi0j-python3.5-setuptools-41.2.0/lib/python3.5/site-packages/setuptools-41.2.0-py3.5.egg/setuptools/command/test.py", line 251, in run_tests
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/unittest/main.py", line 94, in __init__
    self.parseArgs(argv)
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/unittest/main.py", line 118, in parseArgs
    self._do_discovery(argv[2:])
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/unittest/main.py", line 229, in _do_discovery
    self.test = loader.discover(self.start, self.pattern, self.top)
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/unittest/loader.py", line 341, in discover
    tests = list(self._find_tests(start_dir, pattern))
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/unittest/loader.py", line 398, in _find_tests
    full_path, pattern, namespace)
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/unittest/loader.py", line 475, in _find_test_path
    tests = self.loadTestsFromModule(package, pattern=pattern)
  File "/nix/store/pky8wchkji14q3nabm7dps7c0frsqi0j-python3.5-setuptools-41.2.0/lib/python3.5/site-packages/setuptools-41.2.0-py3.5.egg/setuptools/command/test.py", line 55, in loadTestsFromModule
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/unittest/loader.py", line 153, in loadTestsFromName
    module = __import__(module_name)
  File "/build/toolz-0.7.4/toolz/curried/__init__.py", line 53, in <module>
    _curry_namespace(vars(toolz)),
  File "/build/toolz-0.7.4/toolz/curried/__init__.py", line 48, in _curry_namespace
    for name, f in ns.items() if '__' not in name
  File "/build/toolz-0.7.4/toolz/curried/__init__.py", line 48, in <genexpr>
    for name, f in ns.items() if '__' not in name
  File "/build/toolz-0.7.4/toolz/curried/__init__.py", line 42, in _should_curry
    return (callable(f) and _nargs(f) > 1 or f in do_curry)
  File "/build/toolz-0.7.4/toolz/curried/__init__.py", line 35, in _nargs
    return len(inspect.getargspec(f).args)
  File "/nix/store/bmb13jiq3g1lslc7j42f4krh8n3shx0l-python3-3.5.7/lib/python3.5/inspect.py", line 1050, in getargspec
    raise ValueError("Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
builder for '/nix/store/bybr5zdsh78xn177l2pml2drrzh9np9p-python3.5-toolz-0.7.4.drv' failed with exit code 1
cannot build derivation '/nix/store/mgflkpv67krgjrig7qlkl4zy4sb0zdrk-system-path.drv': 1 dependencies couldn't be built

That's probably why the workaround in the nixpkgs package exists: https://github.com/NixOS/nixpkgs/blob/257c6529b1d6feefe118e150b3ed15c9cf005aa0/pkgs/development/python-modules/toolz/default.nix#L20

So we might use a different example here that works and is also simple to understand.

FRidh commented 5 years ago

just add fetchPypi to the function parameters...

davidak commented 5 years ago

@FRidh like here https://github.com/NixOS/nixpkgs/issues/72167#issuecomment-546984659?

I got it working in my code.

But the example in the documentation should be in a form that one can just copy it and it works.

tokudan commented 4 years ago

There seems to be a major difference between derivations introduced into pkgs/top-level/python-packages.nix and all other derivations. As far as I can tell derivations in python-packages.nix automatically get a selected version of buildPythonPackage, while all other derivations need to select their own version of python by using pythonXXXPackages.buildPythonPackage, but I'm not sure that's the only difference. It can be very confusing if example code doesn't work.

stale[bot] commented 4 years ago

Hello, I'm a bot and I thank you in the name of the community for opening this issue.

To help our human contributors focus on the most-relevant reports, I check up on old issues to see if they're still relevant. This issue has had no activity for 180 days, and so I marked it as stale, but you can rest assured it will never be closed by a non-human.

The community would appreciate your effort in checking if the issue is still valid. If it isn't, please close it.

If the issue persists, and you'd like to remove the stale label, you simply need to leave a comment. Your comment can be as simple as "still important to me". If you'd like it to get more attention, you can ask for help by searching for maintainers and people that previously touched related code and @ mention them in a comment. You can use Git blame or GitHub's web interface on the relevant files to find them.

Lastly, you can always ask for help at our Discourse Forum or at #nixos' IRC channel.

davidak commented 4 years ago

since this was not closed, it's probably not fixed

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info

Artturin commented 1 year ago

https://github.com/NixOS/nixpkgs/pull/222413