diff --git a/dev/build-systems.nix b/dev/build-systems.nix new file mode 100644 index 0000000..ef5e259 --- /dev/null +++ b/dev/build-systems.nix @@ -0,0 +1,598 @@ +# Build system packages for testing +# TODO: This file is a temporary arrangement to avoid Flake dependencies. +# The solution to removing this file is to stop using flakes for CI so we can depend on https://github.com/pyproject-nix/build-system-pkgs + +{ + pyproject-nix, + lib, +}: +final: _prev: +let + pkgs = final.callPackage ({ pkgs }: pkgs) { }; + inherit (pkgs) python3Packages; +in +lib.mapAttrs + ( + n: v: + final.callPackage v { + pyprojectHook = + if pyproject-nix.build.lib.isBootstrapPackage n then + final.pyprojectBootstrapHook + else + final.pyprojectHook; + } + ) + { + + flit-core = + { stdenv, pyprojectHook }: + stdenv.mkDerivation { + inherit (python3Packages.flit-core) + pname + version + src + meta + patches + ; + postPatch = python3Packages.flit-core.postPatch or null; + sourceRoot = python3Packages.flit-core.sourceRoot or null; + nativeBuildInputs = [ + pyprojectHook + ]; + }; + + cmake = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.cmake) + pname + version + src + meta + postUnpack + setupHooks + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + scikit-build-core = +{ + stdenv, + lib, + python, + python3Packages, + pyprojectHook, + resolveBuildSystem, +}: +stdenv.mkDerivation { + inherit (python3Packages.scikit-build-core) + pname + version + src + meta + patches + ; + + passthru.dependencies = + { + packaging = [ ]; + pathspec = [ ]; + } + // lib.optionalAttrs (python.pythonOlder "3.11") { + exceptiongroup = [ ]; + tomli = [ ]; + } + // lib.optionalAttrs (python.pythonOlder "3.9") { + importlib-resources = [ ]; + typing-extensions = [ ]; + } + // lib.optionalAttrs (python.pythonOlder "3.8") { + importlib-metadata = [ ]; + }; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + hatchling = [ ]; + hatch-vcs = [ ]; + }; +}; + + ninja = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.ninja) + pname + version + src + meta + postUnpack + setupHook + preBuild + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + cython = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + pkg-config, + }: + stdenv.mkDerivation { + inherit (python3Packages.cython) + pname + version + src + meta + setupHook + ; + + nativeBuildInputs = + [ + pyprojectHook + pkg-config + ] + ++ resolveBuildSystem { + setuptools = [ ]; + }; + }; + + pytest-runner = + { + stdenv, + fetchurl, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + pname = "pytest-runner"; + version = "6.0.1"; + + src = fetchurl { + url = "https://files.pythonhosted.org/packages/d7/7d/60976d532519c3a0b41e06a59ad60949e2be1af937cf02738fec91bfd808/pytest-runner-6.0.1.tar.gz"; + hash = "sha256-cNRzlYWnAI83v0kzwBP9sye4h4paafy7MxbIiILw9Js="; + }; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + setuptools = [ ]; + setuptools-scm = [ ]; + }; + }; + + hatchling = + { + stdenv, + lib, + python, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation (finalAttrs: { + inherit (python3Packages.hatchling) + pname + version + src + meta + ; + + passthru.dependencies = + { + packaging = [ ]; + pathspec = [ ]; + pluggy = [ ]; + trove-classifiers = [ ]; + } + // lib.optionalAttrs (python.pythonOlder "3.11") { + tomli = [ ]; + }; + + nativeBuildInputs = [ + pyprojectHook + ] ++ resolveBuildSystem finalAttrs.passthru.dependencies; + }); + + pluggy = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.pluggy) + pname + version + src + meta + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + setuptools-scm = [ ]; + }; + }; + + trove-classifiers = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.trove-classifiers) + pname + version + src + meta + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + setuptools = [ ]; + calver = [ ]; + }; + }; + + build = + { + stdenv, + lib, + python, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.build) + pname + version + src + meta + ; + + passthru.dependencies = + { + packaging = [ ]; + pyproject-hooks = [ ]; + + } + // lib.optionalAttrs (python.pythonOlder "3.11") { + tomli = [ ]; + }; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + pyproject-hooks = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.pyproject-hooks) + pname + version + src + meta + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + packaging = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.packaging) + pname + version + src + meta + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + setuptools-scm = + { + stdenv, + lib, + python, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.setuptools-scm) + pname + version + src + meta + setupHook + ; + + passthru = { + dependencies = + { + packaging = [ ]; + setuptools = [ ]; + } + // lib.optionalAttrs (python.pythonOlder "3.11") { + tomli = [ ]; + } + // lib.optionalAttrs (python.pythonOlder "3.10") { + typing-extensions = [ ]; + }; + + optional-dependencies = { + toml = { + tomli = [ ]; + }; + rich = { + rich = [ ]; + }; + }; + }; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem ( + { + setuptools = [ ]; + } + // lib.optionalAttrs (python.pythonOlder "3.11") { + tomli = [ ]; + } + ); + }; + + setuptools = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.setuptools) + pname + version + src + meta + patches + preBuild # Skips windows files + ; + + passthru.dependencies.wheel = [ ]; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + tomli-w = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.tomli-w) + pname + version + src + meta + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + wheel = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.wheel) + pname + version + src + meta + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + calver = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.calver) + pname + version + src + meta + postPatch + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + setuptools = [ ]; + }; + }; + + hatch-fancy-pypi-readme = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.hatch-fancy-pypi-readme) + pname + version + src + meta + ; + + passthru.dependencies = { + hatchling = [ ]; + }; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + hatchling = [ ]; + }; + }; + + hatch-vcs = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation (_finalAttrs: { + inherit (python3Packages.hatch-vcs) + pname + version + src + meta + ; + + passthru.dependencies = { + hatchling = [ ]; + setuptools-scm = [ ]; + }; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + hatchling = [ ]; + }; + }); + + pathspec = + { + stdenv, + python3Packages, + pyprojectHook, + resolveBuildSystem, + }: + stdenv.mkDerivation { + inherit (python3Packages.pathspec) + pname + version + src + meta + ; + + nativeBuildInputs = + [ + pyprojectHook + ] + ++ resolveBuildSystem { + flit-core = [ ]; + }; + }; + + } diff --git a/dev/checks.nix b/dev/checks.nix index 06555fc..acd5533 100644 --- a/dev/checks.nix +++ b/dev/checks.nix @@ -47,6 +47,10 @@ let pytest-cov.setuptools = [ ]; }; + buildSystems = import ./build-systems.nix { + inherit lib pyproject-nix; + }; + # Assemble overlay from spec pyprojectOverrides = final: prev: @@ -84,7 +88,13 @@ let (pkgs.callPackage pyproject-nix.build.packages { python = interpreter; }).overrideScope - (lib.composeExtensions overlay pyprojectOverrides); + ( + lib.composeManyExtensions [ + buildSystems + overlay + pyprojectOverrides + ] + ); in # Render venv @@ -247,6 +257,7 @@ let # Override package set with our overlays pythonSet = baseSet.overrideScope ( lib.composeManyExtensions [ + buildSystems overlay pyprojectOverrides editableOverlay diff --git a/flake.lock b/flake.lock index 33a5312..82f2370 100644 --- a/flake.lock +++ b/flake.lock @@ -23,11 +23,11 @@ ] }, "locked": { - "lastModified": 1732016033, - "narHash": "sha256-+mqYN/h8/6mjKI0VPBCixo/0q/WeSfUKaGwAr3+9aT4=", + "lastModified": 1732086351, + "narHash": "sha256-E2/km+smfIc+wpT8dHnEJQsZS+dGNAzlNDJZD5ICA6Q=", "owner": "pyproject-nix", "repo": "pyproject.nix", - "rev": "a407647c2d0df919fe4f8aad30cf327c03f8f008", + "rev": "72f29865c9476b8a5d842862e8682dac1eb52d0e", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 6d9915a..d94c24b 100644 --- a/flake.nix +++ b/flake.nix @@ -145,6 +145,11 @@ inputs' = inputs // { uv2nix = self; self = flake; + pyproject-build-systems = { + overlays.default = import ./dev/build-systems.nix { + inherit pyproject-nix lib; + }; + }; }; in flake; diff --git a/templates/django-webapp/flake.nix b/templates/django-webapp/flake.nix index d6360e0..a555fba 100644 --- a/templates/django-webapp/flake.nix +++ b/templates/django-webapp/flake.nix @@ -14,6 +14,13 @@ inputs.pyproject-nix.follows = "pyproject-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + + pyproject-build-systems = { + url = "github:pyproject-nix/build-system-pkgs"; + inputs.pyproject-nix.follows = "pyproject-nix"; + inputs.uv2nix.follows = "uv2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = @@ -22,6 +29,7 @@ nixpkgs, uv2nix, pyproject-nix, + pyproject-build-systems, ... }: let @@ -161,7 +169,13 @@ }; in - baseSet.overrideScope (lib.composeExtensions overlay pyprojectOverrides) + baseSet.overrideScope ( + lib.composeManyExtensions [ + pyproject-build-systems.overlays.default + overlay + pyprojectOverrides + ] + ) ); # Django static roots grouped per system diff --git a/templates/overriding/flake.nix b/templates/overriding/flake.nix index 59292fc..1088590 100644 --- a/templates/overriding/flake.nix +++ b/templates/overriding/flake.nix @@ -14,6 +14,13 @@ inputs.pyproject-nix.follows = "pyproject-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + + pyproject-build-systems = { + url = "github:pyproject-nix/build-system-pkgs"; + inputs.pyproject-nix.follows = "pyproject-nix"; + inputs.uv2nix.follows = "uv2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = @@ -21,6 +28,7 @@ nixpkgs, uv2nix, pyproject-nix, + pyproject-build-systems, ... }: let @@ -44,6 +52,7 @@ }; overlays = [ + pyproject-build-systems.overlays.default overlay # Note: Files are only split for documentation structuring purposes. # This is not considered a best practice. diff --git a/templates/testing/flake.nix b/templates/testing/flake.nix index 8e46663..6e9d1b3 100644 --- a/templates/testing/flake.nix +++ b/templates/testing/flake.nix @@ -14,6 +14,13 @@ inputs.pyproject-nix.follows = "pyproject-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; + + pyproject-build-systems = { + url = "github:pyproject-nix/build-system-pkgs"; + inputs.pyproject-nix.follows = "pyproject-nix"; + inputs.uv2nix.follows = "uv2nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; # This example shows testing with pytest using uv2nix. @@ -24,6 +31,7 @@ nixpkgs, uv2nix, pyproject-nix, + pyproject-build-systems, ... }: let @@ -110,7 +118,13 @@ }; in - baseSet.overrideScope (lib.composeExtensions overlay pyprojectOverrides) + baseSet.overrideScope ( + lib.composeManyExtensions [ + pyproject-build-systems.overlays.default + overlay + pyprojectOverrides + ] + ) ); in