From f6f8e2649425948860f81eff476e11984c40e5d7 Mon Sep 17 00:00:00 2001
From: adisbladis <adisbladis@gmail.com>
Date: Mon, 18 Nov 2024 21:19:53 +0000
Subject: [PATCH] build: Deprecate package set

---
 build/checks/default.nix     | 20 +++++++++----
 build/hacks/checks.nix       | 10 +++++--
 build/lib/test_renderers.nix |  8 +++++-
 build/packages.nix           | 12 ++++++--
 build/test_overlay.nix       | 54 ++++++++++++++++++++++++++++++++++++
 5 files changed, 93 insertions(+), 11 deletions(-)
 create mode 100644 build/test_overlay.nix

diff --git a/build/checks/default.nix b/build/checks/default.nix
index da7fc78..8c118ba 100644
--- a/build/checks/default.nix
+++ b/build/checks/default.nix
@@ -10,11 +10,17 @@ let
 
   python = pkgs.python312;
 
-  # Inject your own packages on top with overrideScope
-  pythonSet = pkgs.callPackage pyproject-nix.build.packages {
-    inherit python;
+  testOverlay = import ../test_overlay.nix {
+    inherit pyproject-nix lib;
   };
 
+  # Inject your own packages on top with overrideScope
+  pythonSet =
+    (pkgs.callPackage pyproject-nix.build.packages {
+      inherit python;
+    }).overrideScope
+      testOverlay;
+
   testVenv = pythonSet.pythonPkgsHostHost.mkVirtualEnv "test-venv" {
     build = [ ];
   };
@@ -43,9 +49,11 @@ in
     let
       pkgs' = pkgs.pkgsCross.aarch64-multiplatform;
       python = pkgs'.python312;
-      crossSet = pkgs'.callPackage pyproject-nix.build.packages {
-        inherit python;
-      };
+      crossSet =
+        (pkgs'.callPackage pyproject-nix.build.packages {
+          inherit python;
+        }).overrideScope
+          testOverlay;
     in
     crossSet.pythonPkgsHostHost.mkVirtualEnv "cross-venv" {
       build = [ ];
diff --git a/build/hacks/checks.nix b/build/hacks/checks.nix
index 363f998..4ddc1e5 100644
--- a/build/hacks/checks.nix
+++ b/build/hacks/checks.nix
@@ -7,10 +7,16 @@ let
 
   python = pkgs.python3;
 
-  pythonSet = pkgs.callPackage pyproject-nix.build.packages {
-    inherit python;
+  testOverlay = import ../test_overlay.nix {
+    inherit pyproject-nix lib;
   };
 
+  pythonSet =
+    (pkgs.callPackage pyproject-nix.build.packages {
+      inherit python;
+    }).overrideScope
+      testOverlay;
+
 in
 {
   nixpkgsPrebuilt =
diff --git a/build/lib/test_renderers.nix b/build/lib/test_renderers.nix
index 7d6c31f..cb9c2b1 100644
--- a/build/lib/test_renderers.nix
+++ b/build/lib/test_renderers.nix
@@ -12,7 +12,13 @@ let
 
   python = pkgs.python312;
 
-  pythonSet = pkgs.callPackage pyproject-nix.build.packages { inherit python; };
+  testOverlay = import ../test_overlay.nix {
+    inherit pyproject-nix lib;
+  };
+
+  pythonSet =
+    (pkgs.callPackage pyproject-nix.build.packages { inherit python; }).overrideScope
+      testOverlay;
 
 in
 
diff --git a/build/packages.nix b/build/packages.nix
index 67c8c58..faf9050 100644
--- a/build/packages.nix
+++ b/build/packages.nix
@@ -1,7 +1,7 @@
 {
   lib,
-  pyproject-nix,
   resolvers,
+  pyproject-nix,
 }:
 let
   inherit (resolvers) resolveCyclic resolveNonCyclic;
@@ -31,7 +31,15 @@ let
 
   mkResolveVirtualEnv = set: spec: map (name: set.${name}) (resolveCyclic set spec);
 
-  pkgsFun = final: mkPkgs' { inherit (final) callPackage pyprojectBootstrapHook; };
+  deprecatedBuild = name: ''
+    You are using '${name}' from the pyproject.nix base package set.
+    This is deprecated in favour of https://github.com/pyproject-nix/build-system-pkgs and will be removed shortly.
+  '';
+  pkgsFun =
+    final:
+    lib.mapAttrs (name: drv: builtins.trace (deprecatedBuild name) drv) (mkPkgs' {
+      inherit (final) callPackage pyprojectBootstrapHook;
+    });
 
   mkPythonSet =
     {
diff --git a/build/test_overlay.nix b/build/test_overlay.nix
new file mode 100644
index 0000000..fa3d68f
--- /dev/null
+++ b/build/test_overlay.nix
@@ -0,0 +1,54 @@
+{
+  lib,
+  pyproject-nix,
+}:
+let
+  overlay' =
+    final: _prev:
+    lib.mapAttrs
+      (
+        name: pkg:
+        if pyproject-nix.build.lib.isBootstrapPackage name then
+          final.callPackage pkg { pyprojectHook = final.pyprojectBootstrapHook; }
+        else
+          final.callPackage pkg { }
+      )
+      {
+        flit-core = ./pkgs/flit-core;
+        packaging = ./pkgs/packaging;
+        pyproject-hooks = ./pkgs/pyproject-hooks;
+        setuptools = ./pkgs/setuptools;
+        wheel = ./pkgs/wheel;
+        hatchling = ./pkgs/hatchling;
+        pdm-backend = ./pkgs/pdm-backend;
+        cython = ./pkgs/cython;
+        meson = ./pkgs/meson;
+        build = ./pkgs/build;
+        installer = ./pkgs/installer;
+        pathspec = ./pkgs/pathspec;
+        pluggy = ./pkgs/pluggy;
+        setuptools-scm = ./pkgs/setuptools-scm;
+        trove-classifiers = ./pkgs/trove-classifiers;
+        calver = ./pkgs/calver;
+        zipp = ./pkgs/zipp;
+        tomli-w = ./pkgs/tomli-w;
+        cffi = ./pkgs/cffi;
+        maturin = ./pkgs/maturin;
+        setuptools-rust = ./pkgs/setuptools-rust;
+        pycparser = ./pkgs/pycparser;
+        typing-extensions = ./pkgs/typing-extensions;
+        semantic-version = ./pkgs/semantic-version;
+        tomli = ./pkgs/tomli;
+        pip = ./pkgs/pip;
+      };
+
+  crossOverlay = lib.composeExtensions (_final: prev: {
+    pythonPkgsBuildHost = prev.pythonPkgsBuildHost.overrideScope overlay';
+  }) overlay';
+
+in
+final: prev:
+if prev.stdenv.buildPlatform != prev.stdenv.hostPlatform then
+  crossOverlay final prev
+else
+  overlay' final prev