|
1 | 1 | {
|
2 |
| - description = "A basic flake using pyproject.toml project metadata"; |
| 2 | + description = "Flake using pyproject.toml metadata"; |
3 | 3 |
|
4 | 4 | inputs.pyproject-nix.url = "github:pyproject-nix/pyproject.nix";
|
5 | 5 | inputs.pyproject-nix.inputs.nixpkgs.follows = "nixpkgs";
|
6 | 6 |
|
7 | 7 | outputs =
|
8 | 8 | { nixpkgs, pyproject-nix, ... }:
|
9 | 9 | let
|
10 |
| - # Loads pyproject.toml into a high-level project representation |
11 |
| - # Do you notice how this is not tied to any `system` attribute or package sets? |
12 |
| - # That is because `project` refers to a pure data representation. |
| 10 | + inherit (nixpkgs) lib; |
| 11 | + forAllSystems = lib.genAttrs lib.systems.flakeExposed; |
| 12 | + |
13 | 13 | project = pyproject-nix.lib.project.loadPyproject {
|
14 |
| - # Read & unmarshal pyproject.toml relative to this project root. |
15 |
| - # projectRoot is also used to set `src` for renderers such as buildPythonPackage. |
16 | 14 | projectRoot = ./.;
|
17 | 15 | };
|
18 | 16 |
|
19 |
| - # This example is only using x86_64-linux |
20 |
| - pkgs = nixpkgs.legacyPackages.x86_64-linux; |
21 |
| - |
22 |
| - # We are using the default nixpkgs Python3 interpreter & package set. |
23 |
| - # |
24 |
| - # This means that you are purposefully ignoring: |
25 |
| - # - Version bounds |
26 |
| - # - Dependency sources (meaning local path dependencies won't resolve to the local path) |
27 |
| - # |
28 |
| - # To use packages from local sources see "Overriding Python packages" in the nixpkgs manual: |
29 |
| - # https://nixos.org/manual/nixpkgs/stable/#reference |
30 |
| - # |
31 |
| - # Or use an overlay generator such as uv2nix: |
32 |
| - # https://github.com/pyproject-nix/uv2nix |
33 |
| - python = pkgs.python3; |
34 |
| - |
| 17 | + pythonAttr = "python3"; |
35 | 18 | in
|
36 | 19 | {
|
37 |
| - # Create a development shell containing dependencies from `pyproject.toml` |
38 |
| - devShells.x86_64-linux.default = |
39 |
| - let |
40 |
| - # Returns a function that can be passed to `python.withPackages` |
41 |
| - arg = project.renderers.withPackages { inherit python; }; |
42 |
| - |
43 |
| - # Returns a wrapped environment (virtualenv like) with all our packages |
44 |
| - pythonEnv = python.withPackages arg; |
45 |
| - |
46 |
| - in |
47 |
| - # Create a devShell like normal. |
48 |
| - pkgs.mkShell { packages = [ pythonEnv ]; }; |
49 |
| - |
50 |
| - # Build our package using `buildPythonPackage |
51 |
| - packages.x86_64-linux.default = |
| 20 | + devShells = forAllSystems (system: { |
| 21 | + default = |
| 22 | + let |
| 23 | + pkgs = nixpkgs.legacyPackages.${system}; |
| 24 | + python = pkgs.${pythonAttr}; |
| 25 | + pythonEnv = python.withPackages (project.renderers.withPackages { inherit python; }); |
| 26 | + in |
| 27 | + pkgs.mkShell { packages = [ pythonEnv ]; }; |
| 28 | + }); |
| 29 | + |
| 30 | + packages = forAllSystems ( |
| 31 | + system: |
52 | 32 | let
|
53 |
| - # Returns an attribute set that can be passed to `buildPythonPackage`. |
54 |
| - attrs = project.renderers.buildPythonPackage { inherit python; }; |
| 33 | + pkgs = nixpkgs.legacyPackages.${system}; |
| 34 | + python = pkgs.${pythonAttr}; |
55 | 35 | in
|
56 |
| - # Pass attributes to buildPythonPackage. |
57 |
| - # Here is a good spot to add on any missing or custom attributes. |
58 |
| - python.pkgs.buildPythonPackage (attrs // { env.CUSTOM_ENVVAR = "hello"; }); |
| 36 | + { |
| 37 | + default = python.pkgs.buildPythonPackage (project.renderers.buildPythonPackage { inherit python; }); |
| 38 | + } |
| 39 | + ); |
59 | 40 | };
|
60 | 41 | }
|
0 commit comments