fix: Replace overlays self super with final prev

This commit is contained in:
Malte Neuss 2024-04-14 20:27:42 +02:00 committed by Phillip Cloud
parent beb9518b4d
commit 023a0e045a
No known key found for this signature in database
GPG key ID: D908212070FD785E
23 changed files with 745 additions and 720 deletions

View file

@ -2,6 +2,7 @@
[![Chat on Matrix](https://matrix.to/img/matrix-badge.svg)](https://matrix.to/#/#poetry2nix:blad.is) [![Chat on Matrix](https://matrix.to/img/matrix-badge.svg)](https://matrix.to/#/#poetry2nix:blad.is)
# poetry2nix # poetry2nix
_poetry2nix_ turns [Poetry](https://python-poetry.org/) projects into Nix derivations without the need to actually write Nix expressions. It does so by parsing `pyproject.toml` and `poetry.lock` and converting them to Nix derivations on the fly. _poetry2nix_ turns [Poetry](https://python-poetry.org/) projects into Nix derivations without the need to actually write Nix expressions. It does so by parsing `pyproject.toml` and `poetry.lock` and converting them to Nix derivations on the fly.
For more information, see [the announcement post on the Tweag blog](https://www.tweag.io/blog/2020-08-12-poetry2nix/). For more information, see [the announcement post on the Tweag blog](https://www.tweag.io/blog/2020-08-12-poetry2nix/).
@ -110,8 +111,9 @@ myPythonApp = pkgs.poetry2nix.mkPoetryApplication { projectDir = self; };
``` ```
## Table of contents ## Table of contents
- [API](#api) - [API](#api)
- [FAQ](#FAQ) - [FAQ](#faq)
- [How-to guides](#how-to-guides) - [How-to guides](#how-to-guides)
- [Using the flake](#using-the-flake) - [Using the flake](#using-the-flake)
- [Contributing](#contributing) - [Contributing](#contributing)
@ -159,6 +161,7 @@ poetry = "poetry.console.application:main"
``` ```
#### Example #### Example
```nix ```nix
poetry2nix.mkPoetryApplication { poetry2nix.mkPoetryApplication {
projectDir = ./.; projectDir = ./.;
@ -191,6 +194,7 @@ If you prefer to build a single binary that runs `gunicorn web:app`, use [`pkgs.
Note: If you need to perform overrides on the application, use `app.dependencyEnv.override { app = app.override { ... }; }`. See [./tests/dependency-environment/default.nix](./tests/dependency-environment/default.nix) for a full example. Note: If you need to perform overrides on the application, use `app.dependencyEnv.override { app = app.override { ... }; }`. See [./tests/dependency-environment/default.nix](./tests/dependency-environment/default.nix) for a full example.
### mkPoetryEnv ### mkPoetryEnv
Creates an environment that provides a Python interpreter along with all dependencies declared by the designated poetry project and lock files. Also allows package sources of an application to be installed in editable mode for fast development. `mkPoetryEnv` takes an attribute set with the following attributes (attributes without default are mandatory): Creates an environment that provides a Python interpreter along with all dependencies declared by the designated poetry project and lock files. Also allows package sources of an application to be installed in editable mode for fast development. `mkPoetryEnv` takes an attribute set with the following attributes (attributes without default are mandatory):
- **projectDir**: path to the root of the project. - **projectDir**: path to the root of the project.
@ -206,6 +210,7 @@ Creates an environment that provides a Python interpreter along with all depende
- **extras**: Which Poetry `extras` to install (_default_: `[ "*" ]`, all extras). - **extras**: Which Poetry `extras` to install (_default_: `[ "*" ]`, all extras).
#### Example #### Example
```nix ```nix
poetry2nix.mkPoetryEnv { poetry2nix.mkPoetryEnv {
projectDir = ./.; projectDir = ./.;
@ -215,6 +220,7 @@ poetry2nix.mkPoetryEnv {
See [./tests/env/default.nix](./tests/env/default.nix) for a working example. See [./tests/env/default.nix](./tests/env/default.nix) for a working example.
#### Example with editable packages #### Example with editable packages
```nix ```nix
poetry2nix.mkPoetryEnv { poetry2nix.mkPoetryEnv {
projectDir = ./.; projectDir = ./.;
@ -227,6 +233,7 @@ poetry2nix.mkPoetryEnv {
See [./tests/editable/default.nix](./tests/editable/default.nix) for a working example of an editable package. See [./tests/editable/default.nix](./tests/editable/default.nix) for a working example of an editable package.
#### Example shell.nix #### Example shell.nix
The `env` attribute of the attribute set created by `mkPoetryEnv` contains a shell environment. The `env` attribute of the attribute set created by `mkPoetryEnv` contains a shell environment.
```nix ```nix
@ -242,7 +249,9 @@ in myAppEnv.env
``` ```
#### Example shell.nix with external dependencies #### Example shell.nix with external dependencies
For a shell environment including external dependencies, override the `env` to add dependency packages (for example, `pkgs.hello`) as build inputs. For a shell environment including external dependencies, override the `env` to add dependency packages (for example, `pkgs.hello`) as build inputs.
```nix ```nix
{ pkgs ? import <nixpkgs> {} }: { pkgs ? import <nixpkgs> {} }:
let let
@ -258,6 +267,7 @@ in myAppEnv.env.overrideAttrs (oldAttrs: {
``` ```
### mkPoetryPackages ### mkPoetryPackages
Creates an attribute set of the shape `{ python, poetryPackages, pyProject, poetryLock }`. Where `python` is the interpreter specified, `poetryPackages` is a list of all generated python packages, `pyProject` is the parsed `pyproject.toml` and `poetryLock` is the parsed `poetry.lock` file. `mkPoetryPackages` takes an attribute set with the following attributes (attributes without default are mandatory): Creates an attribute set of the shape `{ python, poetryPackages, pyProject, poetryLock }`. Where `python` is the interpreter specified, `poetryPackages` is a list of all generated python packages, `pyProject` is the parsed `pyproject.toml` and `poetryLock` is the parsed `poetry.lock` file. `mkPoetryPackages` takes an attribute set with the following attributes (attributes without default are mandatory):
- **projectDir**: path to the root of the project. - **projectDir**: path to the root of the project.
@ -272,6 +282,7 @@ Creates an attribute set of the shape `{ python, poetryPackages, pyProject, poet
- **extras**: Which Poetry `extras` to install (_default_: `[ "*" ]`, all extras). - **extras**: Which Poetry `extras` to install (_default_: `[ "*" ]`, all extras).
#### Example #### Example
```nix ```nix
poetry2nix.mkPoetryPackages { poetry2nix.mkPoetryPackages {
projectDir = ./.; projectDir = ./.;
@ -280,6 +291,7 @@ poetry2nix.mkPoetryPackages {
``` ```
### mkPoetryScriptsPackage ### mkPoetryScriptsPackage
Creates a package containing the scripts from `tool.poetry.scripts` of the `pyproject.toml`: Creates a package containing the scripts from `tool.poetry.scripts` of the `pyproject.toml`:
- **projectDir**: path to the root of the project. - **projectDir**: path to the root of the project.
@ -287,6 +299,7 @@ Creates a package containing the scripts from `tool.poetry.scripts` of the `pypr
- **python**: The Python interpreter to use (_default:_ `pkgs.python3`). - **python**: The Python interpreter to use (_default:_ `pkgs.python3`).
#### Example #### Example
```nix ```nix
poetry2nix.mkPoetryScriptsPackage { poetry2nix.mkPoetryScriptsPackage {
projectDir = ./.; projectDir = ./.;
@ -295,6 +308,7 @@ poetry2nix.mkPoetryScriptsPackage {
``` ```
### mkPoetryEditablePackage ### mkPoetryEditablePackage
Creates a package containing editable sources. Changes in the specified paths will be reflected in an interactive nix-shell session without the need to restart it: Creates a package containing editable sources. Changes in the specified paths will be reflected in an interactive nix-shell session without the need to restart it:
- **projectDir**: path to the root of the project. - **projectDir**: path to the root of the project.
@ -303,6 +317,7 @@ Creates a package containing editable sources. Changes in the specified paths wi
- **editablePackageSources**: A mapping from package name to source directory, these will be installed in editable mode (_default:_ `{}`). - **editablePackageSources**: A mapping from package name to source directory, these will be installed in editable mode (_default:_ `{}`).
#### Example #### Example
```nix ```nix
poetry2nix.mkPoetryEditablePackage { poetry2nix.mkPoetryEditablePackage {
projectDir = ./.; projectDir = ./.;
@ -318,9 +333,11 @@ poetry2nix.mkPoetryEditablePackage {
_poetry2nix_ bundles a set of default overrides that fix problems with various Python packages. These overrides are implemented in [overrides](./overrides/default.nix). _poetry2nix_ bundles a set of default overrides that fix problems with various Python packages. These overrides are implemented in [overrides](./overrides/default.nix).
### overrides.withDefaults ### overrides.withDefaults
Returns a list containing the specified overlay and `defaultPoetryOverrides`. Returns a list containing the specified overlay and `defaultPoetryOverrides`.
Takes an attribute set with the following attributes (attributes without default are mandatory): Takes an attribute set with the following attributes (attributes without default are mandatory):
- **src**: project source directory - **src**: project source directory
#### Example #### Example
@ -328,12 +345,14 @@ Takes an attribute set with the following attributes (attributes without default
```nix ```nix
poetry2nix.mkPoetryEnv { poetry2nix.mkPoetryEnv {
projectDir = ./.; projectDir = ./.;
overrides = poetry2nix.overrides.withDefaults (self: super: { foo = null; }); overrides = poetry2nix.overrides.withDefaults (final: prev: { foo = null; });
} }
``` ```
See [./tests/override-support/default.nix](./tests/override-support/default.nix) for a working example. See [./tests/override-support/default.nix](./tests/override-support/default.nix) for a working example.
### overrides.withoutDefaults ### overrides.withoutDefaults
Returns a list containing just the specified overlay, ignoring `defaultPoetryOverrides`. Returns a list containing just the specified overlay, ignoring `defaultPoetryOverrides`.
#### Example #### Example
@ -341,12 +360,14 @@ Returns a list containing just the specified overlay, ignoring `defaultPoetryOve
```nix ```nix
poetry2nix.mkPoetryEnv { poetry2nix.mkPoetryEnv {
projectDir = ./.; projectDir = ./.;
overrides = poetry2nix.overrides.withoutDefaults (self: super: { foo = null; }); overrides = poetry2nix.overrides.withoutDefaults (final: prev: { foo = null; });
} }
``` ```
### cleanPythonSources ### cleanPythonSources
Provides a source filtering mechanism that: Provides a source filtering mechanism that:
- Filters gitignore's - Filters gitignore's
- Filters pycache/pyc files - Filters pycache/pyc files
- Uses cleanSourceFilter to filter out .git/.hg, .o/.so, editor backup files & nix result symlinks - Uses cleanSourceFilter to filter out .git/.hg, .o/.so, editor backup files & nix result symlinks
@ -360,18 +381,20 @@ poetry2nix.cleanPythonSources {
``` ```
### Creating a custom Poetry2nix instance ### Creating a custom Poetry2nix instance
Sometimes when it can be convenient to create a custom instance of `poetry2nix` with a different set of default overrides. Sometimes when it can be convenient to create a custom instance of `poetry2nix` with a different set of default overrides.
#### Example #### Example
```nix ```nix
let let
# self & super refers to poetry2nix # final & prev refers to poetry2nix
p2nix = poetry2nix.overrideScope (self: super: { p2nix = poetry2nix.overrideScope' (final: prev: {
# pyself & pysuper refers to python packages # pyself & pyprev refers to python packages
defaultPoetryOverrides = super.defaultPoetryOverrides.extend (pyself: pysuper: { defaultPoetryOverrides = prev.defaultPoetryOverrides.extend (pyfinal: pyprev: {
my-custom-pkg = super.my-custom-pkg.overridePythonAttrs (oldAttrs: { }); my-custom-pkg = prev.my-custom-pkg.overridePythonAttrs (oldAttrs: { });
}); });
@ -384,20 +407,21 @@ p2nix.mkPoetryApplication {
``` ```
or as a [nixpkgs overlay](https://nixos.org/nixpkgs/manual/#chap-overlays): or as a [nixpkgs overlay](https://nixos.org/nixpkgs/manual/#chap-overlays):
```nix ```nix
let let
pkgs = import <nixpkgs> { pkgs = import <nixpkgs> {
overlays = [ overlays = [
# self & super refers to nixpkgs # final & prev refers to nixpkgs
(self: super: { (final: prev: {
# p2self & p2super refers to poetry2nix # p2nixfinal & p2nixprev refers to poetry2nix
poetry2nix = super.poetry2nix.overrideScope (p2nixself: p2nixsuper: { poetry2nix = prev.poetry2nix.overrideScope' (p2nixfinal: p2nixprev: {
# pyself & pysuper refers to python packages # pyfinal & pyprev refers to python packages
defaultPoetryOverrides = p2nixsuper.defaultPoetryOverrides.extend (pyself: pysuper: { defaultPoetryOverrides = p2nixprev.defaultPoetryOverrides.extend (pyfinal: pyprev: {
my-custom-pkg = super.my-custom-pkg.overridePythonAttrs (oldAttrs: { }); my-custom-pkg = prev.my-custom-pkg.overridePythonAttrs (oldAttrs: { });
}); });
@ -549,7 +573,7 @@ Any package that is used, but isn't in the `poetry.lock` file (most commonly [bu
poetry2nix.mkPoetryApplication { poetry2nix.mkPoetryApplication {
projectDir = ./.; projectDir = ./.;
overrides = poetry2nix.overrides.withDefaults (final: prev: { overrides = poetry2nix.overrides.withDefaults (final: prev: {
# Notice that using .overridePythonAttrs or .overrideAttrs wont work! # Notice that using .overridePythonAttrs or .overrideAttrs won't work!
some-dependency = prev.some-dependency.override { some-dependency = prev.some-dependency.override {
preferWheel = true; preferWheel = true;
}; };
@ -570,6 +594,7 @@ poetry2nix.mkPoetryApplication {
**A.** Have a look at the following document [edgecase.md](./docs/edgecases.md) **A.** Have a look at the following document [edgecase.md](./docs/edgecases.md)
## How-to guides ## How-to guides
- [Package and deploy Python apps faster with Poetry and Nix](https://www.youtube.com/watch?v=TbIHRHy7_JM) - [Package and deploy Python apps faster with Poetry and Nix](https://www.youtube.com/watch?v=TbIHRHy7_JM)
This is a short (11 minutes) video tutorial by [Steve Purcell](https://github.com/purcell/) from [Tweag](https://tweag.io) walking you through how to get started with a small web development project. This is a short (11 minutes) video tutorial by [Steve Purcell](https://github.com/purcell/) from [Tweag](https://tweag.io) walking you through how to get started with a small web development project.
@ -607,10 +632,13 @@ nix-build --expr 'with import <unstable> {}; callPackage ./tests/default.nix {}'
To sort `overrides/build-systems.json` according to the [`sort-build-systems` job](.github/workflows/ci.yml), patch the source with the output of the "Check format" step, like this: `nix-shell [omitted] | patch -p0`. To sort `overrides/build-systems.json` according to the [`sort-build-systems` job](.github/workflows/ci.yml), patch the source with the output of the "Check format" step, like this: `nix-shell [omitted] | patch -p0`.
## Contact ## Contact
We have a Matrix room at [#poetry2nix:blad.is](https://matrix.to/#/#poetry2nix:blad.is). We have a Matrix room at [#poetry2nix:blad.is](https://matrix.to/#/#poetry2nix:blad.is).
## Acknowledgements ## Acknowledgements
Development of `poetry2nix` has been supported by [Tweag](https://tweag.io). Development of `poetry2nix` has been supported by [Tweag](https://tweag.io).
## License ## License
_poetry2nix_ is released under the terms of the MIT license. _poetry2nix_ is released under the terms of the MIT license.

View file

@ -42,7 +42,7 @@ class UrlPackage(Package):
def expression(self, output: str) -> str: def expression(self, output: str) -> str:
sha256 = output.rstrip() sha256 = output.rstrip()
return textwrap.dedent(""" return textwrap.dedent("""
%s = super.%s.overridePythonAttrs ( %s = prev.%s.overridePythonAttrs (
_: { _: {
src = pkgs.fetchzip { src = pkgs.fetchzip {
url = "%s"; url = "%s";
@ -76,7 +76,7 @@ class GitPackage(Package):
def expression(self, output: str) -> str: def expression(self, output: str) -> str:
meta = json.loads(output) meta = json.loads(output)
return textwrap.dedent(""" return textwrap.dedent("""
%s = super.%s.overridePythonAttrs ( %s = prev.%s.overridePythonAttrs (
_: { _: {
src = pkgs.fetchgit { src = pkgs.fetchgit {
url = "%s"; url = "%s";
@ -131,7 +131,7 @@ def main() -> None:
lines = [ lines = [
"{ pkgs }:", "{ pkgs }:",
"self: super: {", "final: prev: {",
] ]
for f in futures: for f in futures:

View file

@ -196,7 +196,7 @@ lib.makeScope pkgs.newScope (self: {
# #
# We need to avoid mixing multiple versions of pythonPackages in the same # We need to avoid mixing multiple versions of pythonPackages in the same
# closure as python can only ever have one version of a dependency # closure as python can only ever have one version of a dependency
baseOverlay = self: super: baseOverlay = final: prev:
let let
lockPkgs = builtins.listToAttrs ( lockPkgs = builtins.listToAttrs (
builtins.map builtins.map
@ -205,14 +205,14 @@ lib.makeScope pkgs.newScope (self: {
let normalizedName = normalizePackageName pkgMeta.name; in let normalizedName = normalizePackageName pkgMeta.name; in
{ {
name = normalizedName; name = normalizedName;
value = self.mkPoetryDep ( value = final.mkPoetryDep (
pkgMeta // { pkgMeta // {
inherit pwd preferWheels; inherit pwd preferWheels;
pos = poetrylockPos; pos = poetrylockPos;
source = pkgMeta.source or null; source = pkgMeta.source or null;
# Default to files from lock file version 2.0 and fall back to 1.1 # Default to files from lock file version 2.0 and fall back to 1.1
files = pkgMeta.files or lockFiles.${normalizedName}; files = pkgMeta.files or lockFiles.${normalizedName};
pythonPackages = self; pythonPackages = final;
sourceSpec = (normalizePackageSet pyProject.tool.poetry.dependencies or { }).${normalizedName} sourceSpec = (normalizePackageSet pyProject.tool.poetry.dependencies or { }).${normalizedName}
or (normalizePackageSet pyProject.tool.poetry.dev-dependencies or { }).${normalizedName} or (normalizePackageSet pyProject.tool.poetry.dev-dependencies or { }).${normalizedName}
@ -224,7 +224,7 @@ lib.makeScope pkgs.newScope (self: {
) )
(lib.reverseList compatible) (lib.reverseList compatible)
); );
buildSystems = builtins.listToAttrs (builtins.map (x: { name = x; value = super.${x}; }) nixpkgsBuildSystems); buildSystems = builtins.listToAttrs (builtins.map (x: { name = x; value = prev.${x}; }) nixpkgsBuildSystems);
in in
lockPkgs // buildSystems // { lockPkgs // buildSystems // {
# Create a dummy null package for the current project in case any dependencies depend on the root project (issue #307) # Create a dummy null package for the current project in case any dependencies depend on the root project (issue #307)
@ -234,45 +234,45 @@ lib.makeScope pkgs.newScope (self: {
getFunctorFn getFunctorFn
( (
[ [
(self: super: lib.attrsets.mapAttrs (final: prev: lib.attrsets.mapAttrs
( (
name: value: name: value:
if lib.isDerivation value && self.hasPythonModule value && (normalizePackageName name) != name if lib.isDerivation value && final.hasPythonModule value && (normalizePackageName name) != name
then null then null
else value else value
) )
super) prev)
( (
self: _super: final: _prev:
{ {
mkPoetryDep = self.callPackage ./mk-poetry-dep.nix { mkPoetryDep = final.callPackage ./mk-poetry-dep.nix {
inherit lib python poetryLib pep508Env pyVersion; inherit lib python poetryLib pep508Env pyVersion;
inherit pyproject-nix; inherit pyproject-nix;
}; };
__toPluginAble = toPluginAble self; __toPluginAble = toPluginAble final;
} }
) )
# Fix infinite recursion in a lot of packages because of checkInputs # Fix infinite recursion in a lot of packages because of checkInputs
(_self: super: lib.mapAttrs (_final: prev: lib.mapAttrs
(_name: value: ( (_name: value: (
if lib.isDerivation value && lib.hasAttr "overridePythonAttrs" value if lib.isDerivation value && lib.hasAttr "overridePythonAttrs" value
then value.overridePythonAttrs (_: { doCheck = false; }) then value.overridePythonAttrs (_: { doCheck = false; })
else value else value
)) ))
super) prev)
# Null out any filtered packages, we don't want python.pkgs from nixpkgs # Null out any filtered packages, we don't want python.pkgs from nixpkgs
(_self: _super: builtins.listToAttrs (builtins.map (x: { name = normalizePackageName x.name; value = null; }) incompatible)) (_final: _prev: builtins.listToAttrs (builtins.map (x: { name = normalizePackageName x.name; value = null; }) incompatible))
# Create poetry2nix layer # Create poetry2nix layer
baseOverlay baseOverlay
] ++ # User provided overrides ] ++ # User provided overrides
(if builtins.typeOf overrides == "list" then overrides else [ overrides ]) (if builtins.typeOf overrides == "list" then overrides else [ overrides ])
); );
packageOverrides = lib.foldr lib.composeExtensions (_self: _super: { }) overlays; packageOverrides = lib.foldr lib.composeExtensions (_final: _prev: { }) overlays;
py = python.override { inherit packageOverrides; self = py; }; py = python.override { inherit packageOverrides; self = py; };
inputAttrs = mkInputAttrs { inherit py pyProject groups checkGroups extras; attrs = { }; includeBuildSystem = false; }; inputAttrs = mkInputAttrs { inherit py pyProject groups checkGroups extras; attrs = { }; includeBuildSystem = false; };
@ -476,10 +476,10 @@ lib.makeScope pkgs.newScope (self: {
overrideOverlay = fn: overrideOverlay = fn:
let let
overlay = self: super: overlay = final: prev:
let let
defaultSet = defaults self super; defaultSet = defaults final prev;
customSet = fn self super; customSet = fn final prev;
in in
defaultSet // customSet; defaultSet // customSet;
in in

View file

@ -128,11 +128,11 @@ In order to be able to build `django-floppyforms` we should modify our nix defin
poetry2nix.mkPoetryApplication { poetry2nix.mkPoetryApplication {
projectDir = ./.; projectDir = ./.;
overrides = poetry2nix.defaultPoetryOverrides.extend overrides = poetry2nix.defaultPoetryOverrides.extend
(self: super: { (final: prev: {
django-floppyforms = super.django-floppyforms.overridePythonAttrs django-floppyforms = prev.django-floppyforms.overridePythonAttrs
( (
old: { old: {
buildInputs = (old.buildInputs or [ ]) ++ [ super.setuptools ]; buildInputs = (old.buildInputs or [ ]) ++ [ prev.setuptools ];
} }
); );
}); });
@ -150,17 +150,17 @@ Your file might then look something like this:
poetry2nix.mkPoetryApplication { poetry2nix.mkPoetryApplication {
projectDir = ./.; projectDir = ./.;
overrides = poetry2nix.defaultPoetryOverrides.extend overrides = poetry2nix.defaultPoetryOverrides.extend
(self: super: { (final: prev: {
first-dependency = super.first-dependency.overridePythonAttrs first-dependency = prev.first-dependency.overridePythonAttrs
( (
old: { old: {
buildInputs = (old.buildInputs or [ ]) ++ [ super.buildtools ]; buildInputs = (old.buildInputs or [ ]) ++ [ prev.buildtools ];
} }
); );
second-dependency = super.second-dependency.overridePythonAttrs second-dependency = prev.second-dependency.overridePythonAttrs
( (
old: { old: {
buildInputs = (old.buildInputs or [ ]) ++ [ super.pdm ]; buildInputs = (old.buildInputs or [ ]) ++ [ prev.pdm ];
} }
); );
}); });
@ -180,10 +180,10 @@ let
simpervisor = [ "setuptools" ]; simpervisor = [ "setuptools" ];
pandas = [ "versioneer" ]; pandas = [ "versioneer" ];
}; };
p2n-overrides = p2n.defaultPoetryOverrides.extend (self: super: p2n-overrides = p2n.defaultPoetryOverrides.extend (final: prev:
builtins.mapAttrs (package: build-requirements: builtins.mapAttrs (package: build-requirements:
(builtins.getAttr package super).overridePythonAttrs (old: { (builtins.getAttr package prev).overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: if builtins.isString pkg then builtins.getAttr pkg super else pkg) build-requirements); buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: if builtins.isString pkg then builtins.getAttr pkg prev else pkg) build-requirements);
}) })
) pypkgs-build-requirements ) pypkgs-build-requirements
); );
@ -212,9 +212,9 @@ Resulting override:
```nix ```nix
{ {
python-ulid = super.python-ulid.overridePythonAttrs ( python-ulid = prev.python-ulid.overridePythonAttrs (
old: { old: {
nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ self.setuptools-scm ]; nativeBuildInputs = (old.nativeBuildInputs or [ ]) ++ [ final.setuptools-scm ];
} }
); );
} }
@ -224,7 +224,7 @@ Resulting override:
**Please update `getCargoHash` and there is a stanza that gives out the hash** **Please update `getCargoHash` and there is a stanza that gives out the hash**
This has known solution https://github.com/nix-community/poetry2nix/pull/1116 This has known solution <https://github.com/nix-community/poetry2nix/pull/1116>
Though, the solution still needs human-in-a-loop as there are many cases where Though, the solution still needs human-in-a-loop as there are many cases where
there is no expected hash provided. there is no expected hash provided.
@ -279,7 +279,6 @@ While the ecosystem is growing, we have an escape hatch to use `preferWheels`
if you trust pip wheel dists. `preferWheels` is basically Python's version of if you trust pip wheel dists. `preferWheels` is basically Python's version of
compiled binary, so it is vulnerable to supply chain attacks. compiled binary, so it is vulnerable to supply chain attacks.
```nix ```nix
poetry2nix.mkPoetryApplication { poetry2nix.mkPoetryApplication {
projectDir = ./.; projectDir = ./.;
@ -333,10 +332,10 @@ files = [
Suppose we override the version in our Nix file as follows: Suppose we override the version in our Nix file as follows:
```nix ```nix
let poetryOverrides = self: super: { let poetryOverrides = final: prev: {
foobar = super.foobar.overridePythonAttrs (old: rec { foobar = prev.foobar.overridePythonAttrs (old: rec {
version = "2.0"; version = "2.0";
src = super.pkgs.fetchFromGitHub { src = prev.pkgs.fetchFromGitHub {
owner = "fakerepo"; owner = "fakerepo";
repo = "foobar"; repo = "foobar";
rev = "refs/tags/${version}"; rev = "refs/tags/${version}";

File diff suppressed because it is too large Load diff

View file

@ -6,8 +6,8 @@ let
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
preferWheels = false; preferWheels = false;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_: super: { _: prev: {
cairocffi = super.cairocffi.override { cairocffi = prev.cairocffi.override {
preferWheel = true; preferWheel = true;
}; };
} }

View file

@ -10,8 +10,8 @@ poetry2nix.mkPoetryApplication {
poetry2nix.defaultPoetryOverrides poetry2nix.defaultPoetryOverrides
(import ./poetry-git-overlay.nix { inherit pkgs; }) (import ./poetry-git-overlay.nix { inherit pkgs; })
( (
_self: super: { _final: prev: {
pyramid-deferred-sqla = super.pyramid-deferred-sqla.overridePythonAttrs ( pyramid-deferred-sqla = prev.pyramid-deferred-sqla.overridePythonAttrs (
_old: { _old: {
postPatch = '' postPatch = ''
touch LICENSE touch LICENSE

View file

@ -1,7 +1,7 @@
{ pkgs }: { pkgs }:
_self: super: { _final: prev: {
pyramid-deferred-sqla = super.pyramid-deferred-sqla.overridePythonAttrs ( pyramid-deferred-sqla = prev.pyramid-deferred-sqla.overridePythonAttrs (
_: { _: {
src = pkgs.fetchgit { src = pkgs.fetchgit {
url = "https://github.com/niteoweb/pyramid_deferred_sqla.git"; url = "https://github.com/niteoweb/pyramid_deferred_sqla.git";

View file

@ -1,18 +1,16 @@
{ poetry2nix, python3 }: { poetry2nix, python3 }:
let let
p2nix = poetry2nix.overrideScope (_self: super: { p2nix = poetry2nix.overrideScope' (_final: prev: {
defaultPoetryOverrides = prev.defaultPoetryOverrides.extend (_pyfinal: _pyprev: {
defaultPoetryOverrides = super.defaultPoetryOverrides.extend (_pyself: _pysuper: { my-custom-pkg = prev.my-custom-pkg.overridePythonAttrs (_oldAttrs: { });
my-custom-pkg = super.my-custom-pkg.overridePythonAttrs (_oldAttrs: { });
}); });
}); });
in in
p2nix.mkPoetryApplication { p2nix.mkPoetryApplication {
python = python3; python = python3;
projectDir = ./.; projectDir = ./.;
overrides = p2nix.overrides.withDefaults (_self: super: { overrides = p2nix.overrides.withDefaults (_final: prev: {
inherit (super) customjox; inherit (prev) customjox;
}); });
} }

View file

@ -6,8 +6,8 @@ let
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
preferWheels = false; preferWheels = false;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_: super: { _: prev: {
numpy = super.numpy.override { numpy = prev.numpy.override {
preferWheel = true; preferWheel = true;
}; };
} }

View file

@ -6,11 +6,11 @@ let
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
preferWheels = false; preferWheels = false;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_: super: { _: prev: {
contourpy = super.contourpy.override { contourpy = prev.contourpy.override {
preferWheel = true; preferWheel = true;
}; };
numpy = super.numpy.override { numpy = prev.numpy.override {
preferWheel = true; preferWheel = true;
}; };
} }

View file

@ -6,7 +6,7 @@ poetry2nix.mkPoetryApplication {
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
pwd = ./.; pwd = ./.;
overrides = poetry2nix.overrides.withDefaults (self: super: { overrides = poetry2nix.overrides.withDefaults (final: prev: {
trivial = self.addBuildSystem "poetry" super.trivial; trivial = final.addBuildSystem "poetry" prev.trivial;
}); });
} }

View file

@ -6,7 +6,7 @@ poetry2nix.mkPoetryApplication {
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
pwd = ./.; pwd = ./.;
overrides = poetry2nix.overrides.withDefaults (self: super: { overrides = poetry2nix.overrides.withDefaults (final: prev: {
trivial = self.addBuildSystem "poetry" super.trivial; trivial = final.addBuildSystem "poetry" prev.trivial;
}); });
} }

View file

@ -1,7 +1,7 @@
{ pkgs }: { pkgs }:
_self: super: { _final: prev: {
alembic = super.alembic.overridePythonAttrs ( alembic = prev.alembic.overridePythonAttrs (
_: { _: {
src = pkgs.fetchgit { src = pkgs.fetchgit {
url = "https://github.com/sqlalchemy/alembic.git"; url = "https://github.com/sqlalchemy/alembic.git";
@ -11,7 +11,7 @@ _self: super: {
} }
); );
colorama = super.colorama.overridePythonAttrs ( colorama = prev.colorama.overridePythonAttrs (
_: { _: {
src = pkgs.fetchgit { src = pkgs.fetchgit {
url = "https://github.com/tartley/colorama.git"; url = "https://github.com/tartley/colorama.git";
@ -21,7 +21,7 @@ _self: super: {
} }
); );
s3transfer = super.s3transfer.overridePythonAttrs ( s3transfer = prev.s3transfer.overridePythonAttrs (
_: { _: {
src = pkgs.fetchgit { src = pkgs.fetchgit {
url = "https://github.com/boto/s3transfer.git"; url = "https://github.com/boto/s3transfer.git";

View file

@ -7,8 +7,8 @@ let
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
preferWheels = false; preferWheels = false;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_self: super: { _final: prev: {
grpcio = super.grpcio.override { grpcio = prev.grpcio.override {
preferWheel = isLinux; preferWheel = isLinux;
}; };
} }

View file

@ -7,8 +7,8 @@ let
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
preferWheels = false; preferWheels = false;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_self: super: { _final: prev: {
markdown-it-py = super.markdown-it-py.override { markdown-it-py = prev.markdown-it-py.override {
preferWheel = isLinux; preferWheel = isLinux;
}; };
} }

View file

@ -8,15 +8,15 @@ let
overrides = [ overrides = [
(( ((
poetry2nix.defaultPoetryOverrides.overrideOverlay ( poetry2nix.defaultPoetryOverrides.overrideOverlay (
_self: super: { _final: prev: {
alembic = super.alembic.overridePythonAttrs ( alembic = prev.alembic.overridePythonAttrs (
_old: { _old: {
TESTING_FOOBAR = 42; TESTING_FOOBAR = 42;
} }
); );
} }
) )
).extend (_pyself: _pysuper: { })) # Test .extend for good measure ).extend (_pyfinal: _pyprev: { })) # Test .extend for good measure
]; ];
}; };
in in

View file

@ -6,8 +6,8 @@ let
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
pyproject = ./pyproject.toml; pyproject = ./pyproject.toml;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_self: super: { _final: prev: {
alembic = super.alembic.overridePythonAttrs ( alembic = prev.alembic.overridePythonAttrs (
_old: { _old: {
TESTING_FOOBAR = 42; TESTING_FOOBAR = 42;
} }

View file

@ -11,16 +11,16 @@ let
pyproject = ./pyproject.toml; pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_self: super: { _final: prev: {
bokeh = super.bokeh.override { bokeh = prev.bokeh.override {
preferWheel = true; preferWheel = true;
}; };
panel = super.panel.override { panel = prev.panel.override {
preferWheel = true; preferWheel = true;
}; };
pillow = super.pillow.override { pillow = prev.pillow.override {
preferWheel = true; preferWheel = true;
}; };
} }

View file

@ -8,9 +8,9 @@ let
dep1 = null; dep1 = null;
}; };
overrides = poetry2nix.overrides.withDefaults (self: super: { overrides = poetry2nix.overrides.withDefaults (final: prev: {
dep1 = super.dep1.overridePythonAttrs (old: { dep1 = prev.dep1.overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ [ self.setuptools ]; buildInputs = (old.buildInputs or [ ]) ++ [ final.setuptools ];
}); });
}); });
}; };

View file

@ -4,11 +4,11 @@ let
python = python310; python = python310;
pyproject = ./pyproject.toml; pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
overrides = poetry2nix.overrides.withDefaults (_: super: { overrides = poetry2nix.overrides.withDefaults (_final: prev: {
threadpoolctl = super.threadpoolctl.override { preferWheel = true; }; threadpoolctl = prev.threadpoolctl.override { preferWheel = true; };
pandas = super.pandas.override { preferWheel = true; }; pandas = prev.pandas.override { preferWheel = true; };
pyquaternion = super.pyquaternion.override { preferWheel = true; }; pyquaternion = prev.pyquaternion.override { preferWheel = true; };
scikit-learn = super.scikit-learn.override { preferWheel = true; }; scikit-learn = prev.scikit-learn.override { preferWheel = true; };
}); });
}; };
in in

View file

@ -7,11 +7,11 @@ let
overrides = poetry2nix.overrides.withDefaults overrides = poetry2nix.overrides.withDefaults
# This is also in overrides.nix but repeated for completeness # This is also in overrides.nix but repeated for completeness
( (
_self: super: { _final: prev: {
maturin = super.maturin.override { maturin = prev.maturin.override {
preferWheel = true; preferWheel = true;
}; };
funcy = super.funcy.overridePythonAttrs (_old: { funcy = prev.funcy.overridePythonAttrs (_old: {
preferWheel = true; preferWheel = true;
}); });
} }

View file

@ -7,20 +7,20 @@ let
poetrylock = ./poetry.lock; poetrylock = ./poetry.lock;
preferWheels = false; preferWheels = false;
overrides = poetry2nix.overrides.withDefaults ( overrides = poetry2nix.overrides.withDefaults (
_: super: { _: prev: {
rpds-py = super.rpds-py.override { rpds-py = prev.rpds-py.override {
preferWheel = isLinux; preferWheel = isLinux;
}; };
referencing = super.referencing.override { referencing = prev.referencing.override {
preferWheel = isLinux; preferWheel = isLinux;
}; };
jsonschema-specifications = super.jsonschema-specifications.override { jsonschema-specifications = prev.jsonschema-specifications.override {
preferWheel = isLinux; preferWheel = isLinux;
}; };
jsonschema = super.jsonschema.override { jsonschema = prev.jsonschema.override {
preferWheel = isLinux; preferWheel = isLinux;
}; };
} }