Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: Splice packages to better support cross #104201

Merged
merged 3 commits into from Nov 19, 2020

Conversation

Ericson2314
Copy link
Member

Motivation for this change

Fixes #104135. Also should hopefully make it easier to fix these sorts of things later.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

CC @globin @FRidh @expipiplus1

It's ugly as hell, but I suppose it is needed to codify how to make
spliced package sets.
Copy link
Member

@FRidh FRidh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have the current legacy, how would the interpreter + package set could look then. Like Haskell? E.g., create the package set directly, instead of via the interpreter Would that solve any issues? It should make overriding easier I think, because you no longer need to bother with self.

The same fix as for PyPy should be done for Graal.

@Ericson2314
Copy link
Member Author

Ericson2314 commented Nov 19, 2020

@FRidh

If we don't have the current legacy, how would the interpreter + package set could look then. Like Haskell? E.g., create the package set directly, instead of via the interpreter.

Do you mean what bigger changes might we do in addition, like making pythonXY and pythonXYPackages separately rather than having the latter just be an alias of pythonXY,pkgs, just as haskell.compiler.* and haskell.packages.* are built separately?

Would that solve any issues? It should make overriding easier I think, because you no longer need to bother with self.

I'm not sure what you mean. I do think the .override { overrides = ... } thing is not as easy to use as the overriding the makeScopes alone allow, so perhaps we could get rid of that callPackage and change the docs accordingly. But I didn't want to get into these breaking changes on my own.

The same fix as for PyPy should be done for Graal.

Graal the JVM thing? Shouldn't we do that in a separate PR?

In other places of Nixpkgs this will also need to be done eventually. Maybe its better having a single attribute that consists of the 6 pkgs{theirHost}{theirTarget} sets? That could be constructed already in stage.nix.

Yes that sounds reasonable. But I think rather land this and then try a few other makeScope invocations and then decide what to abstract. Haskell, python, and xorg (the three examples today) are more different than I'd like, so I'd like to firmly establish the pattern first.

@Ericson2314 Ericson2314 marked this pull request as ready for review November 19, 2020 16:09
@Ericson2314 Ericson2314 changed the title WIP: python: Splice packages to better support cross python: Splice packages to better support cross Nov 19, 2020
@FRidh
Copy link
Member

FRidh commented Nov 19, 2020

Do you mean what bigger changes might we do in addition, like making pythonXY and pythonXYPackages separately rather than having the latter just be an alias of pythonXY,pkgs, just as haskell.compiler.* and haskell.packages.* are built separately?

Yes. The whole overriding is often considered confusing (it is) and different across package sets. If we're making changes that are (potentially) backwards-compatible, we should try to implement what we really want.

Graal the JVM thing? Shouldn't we do that in a separate PR?

It uses the same passthru function. See pkgs/interpreters/python/default.nix.

But I think rather land this and then try a few other makeScope invocations and then decide what to abstract.

Okay. See also for Qt #102168.

@FRidh
Copy link
Member

FRidh commented Nov 19, 2020

$ nix-build -A pkgsCross.raspberryPi.python3.pkgs.numpy
error: --- EvalError ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- nix-build
at: (74:34) in file: /home/freddy/Code/libraries/nixpkgs_2/pkgs/development/interpreters/python/cpython/default.nix

    73|     pythonPackagesHostHost = pkgsHostHost.${pythonAttr};
    74|     pythonPackagesTargetTarget = pkgsTargetTarget.${pythonAttr};
      |                                  ^
    75|   };

attribute 'python38' missing
(use '--show-trace' to show detailed location information)

This makes sense as these are tools we want to run at build time.
Now non-`buildInputs` that are python packages should be resolved
correctly.
@Ericson2314
Copy link
Member Author

If we're making changes that are (potentially) backwards-compatible, we should try to implement what we really want.

Well I think this change is pretty much backwards compatible? If we were to change things everywhere to be consistent (which I do want to do) that would be a bunch more reviewers and things. OK with doing that as a follow-up?

nix-build -A pkgsCross.raspberryPi.python3.pkgs.numpy

Oh oops, I only did the fix for that with python 2. Sorry, fixed now.

@Ericson2314 Ericson2314 merged commit 93b430b into NixOS:master Nov 19, 2020
@Ericson2314 Ericson2314 deleted the splice-python branch November 19, 2020 19:07
FRidh added a commit that referenced this pull request Nov 22, 2020
super was incorrectly possible until #104201
got merged.
adisbladis added a commit to nix-community/poetry2nix that referenced this pull request Nov 26, 2020
FRidh added a commit to FRidh/nixpkgs that referenced this pull request Nov 28, 2020
FRidh added a commit to FRidh/nixpkgs that referenced this pull request Nov 28, 2020
super was incorrectly possible until NixOS#104201
got merged.
FRidh added a commit to FRidh/nixpkgs that referenced this pull request Feb 27, 2021
The package set is an attribute of the interpreter. The function to
build an environment (`buildEnv`/`withPackages`) is part of the
interpreter. The interpreter is passed to itself, and needs to be
updated when overridden.

For cross-compilation we splice the package set, and for that the
various `build/host` interpreters and sets need to be available. We
select these currently through `pkgs.${pythonAttr}`. The `pythonAttr`
attribute was not fixed for `pythonFull`.

NixOS/rfcs#83
NixOS#104201

We need a better solution for this because this is very brittle.
FRidh added a commit that referenced this pull request Feb 27, 2021
The package set is an attribute of the interpreter. The function to
build an environment (`buildEnv`/`withPackages`) is part of the
interpreter. The interpreter is passed to itself, and needs to be
updated when overridden.

For cross-compilation we splice the package set, and for that the
various `build/host` interpreters and sets need to be available. We
select these currently through `pkgs.${pythonAttr}`. The `pythonAttr`
attribute was not fixed for `pythonFull`.

NixOS/rfcs#83
#104201

We need a better solution for this because this is very brittle.
Artturin added a commit to Artturin/nixpkgs that referenced this pull request Apr 25, 2023
wrapPython for some reason has to be not spliced because 'substitutions.pythonHost = python;' causes
```
error: output '/nix/store/li07bad6s9brxx7cf8j408631nca39ka-python3.10-chardet-5.1.0-aarch64-unknown-linux-gnu' is not allowed to refer to the following paths:
         /nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10
```

ericson said in NixOS#104201 (comment) that the reason they were in keep was to not splice them but before the commit which broke hook splicing (33d12e5) everything appeared to be working correctly when cross-compiling

we also somehow get a correctly spliced python in nativeBuildInputs for free
Artturin added a commit to Artturin/nixpkgs that referenced this pull request Apr 25, 2023
as far as i can see there should be no reason to not splice the hooks

wrapPython for some reason has to be not spliced because 'substitutions.pythonHost = python;' causes
```
error: output '/nix/store/li07bad6s9brxx7cf8j408631nca39ka-python3.10-chardet-5.1.0-aarch64-unknown-linux-gnu' is not allowed to refer to the following paths:
         /nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10
```

ericson said in NixOS#104201 (comment) that the reason they were in keep was to not splice them but before the commit which broke hook splicing (33d12e5) everything appeared to be working correctly when cross-compiling

we also somehow get a correctly spliced python in nativeBuildInputs for free
Artturin added a commit to Artturin/nixpkgs that referenced this pull request Jun 24, 2023
as far as i can see there should be no reason to not splice the hooks

wrapPython for some reason has to be not spliced because 'substitutions.pythonHost = python;' causes
```
error: output '/nix/store/li07bad6s9brxx7cf8j408631nca39ka-python3.10-chardet-5.1.0-aarch64-unknown-linux-gnu' is not allowed to refer to the following paths:
         /nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10
```

ericson said in NixOS#104201 (comment) that the reason they were in keep was to not splice them but before the commit which broke hook splicing (33d12e5) everything appeared to be working correctly when cross-compiling

we also somehow get a correctly spliced python in nativeBuildInputs for free
Artturin added a commit to Artturin/nixpkgs that referenced this pull request Jul 24, 2023
as far as i can see there should be no reason to not splice the hooks

wrapPython for some reason has to be not spliced because 'substitutions.pythonHost = python;' causes
```
error: output '/nix/store/li07bad6s9brxx7cf8j408631nca39ka-python3.10-chardet-5.1.0-aarch64-unknown-linux-gnu' is not allowed to refer to the following paths:
         /nix/store/fdqpyj613dr0v1l1lrzqhzay7sk4xg87-python3-3.10.10
```

ericson said in NixOS#104201 (comment) that the reason they were in keep was to not splice them but before the commit which broke hook splicing (33d12e5) everything appeared to be working correctly when cross-compiling

we also somehow get a correctly spliced python in nativeBuildInputs for free
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Python needs splicing
2 participants