From 0f4f56b43f3aefb378d5c65802171a59d0d3515e Mon Sep 17 00:00:00 2001
From: Pyrox <pyrox@pyrox.dev>
Date: Fri, 28 Jun 2024 22:48:31 -0400
Subject: [PATCH] patch-package: migrate from nodePackages

---
 pkgs/by-name/pa/patch-package/package.nix     | 45 +++++++++
 pkgs/development/node-packages/aliases.nix    |  1 +
 .../node-packages/node-packages.json          |  1 -
 .../node-packages/node-packages.nix           | 93 -------------------
 4 files changed, 46 insertions(+), 94 deletions(-)
 create mode 100644 pkgs/by-name/pa/patch-package/package.nix

diff --git a/pkgs/by-name/pa/patch-package/package.nix b/pkgs/by-name/pa/patch-package/package.nix
new file mode 100644
index 000000000000..7260ca50f888
--- /dev/null
+++ b/pkgs/by-name/pa/patch-package/package.nix
@@ -0,0 +1,45 @@
+{
+  lib,
+  stdenv,
+  fetchFromGitHub,
+  fetchYarnDeps,
+  yarnConfigHook,
+  yarnBuildHook,
+  yarnInstallHook,
+  nodejs,
+  nix-update-script,
+}:
+
+stdenv.mkDerivation (finalAttrs: {
+  pname = "patch-package";
+  version = "8.0.0";
+
+  src = fetchFromGitHub {
+    owner = "ds300";
+    repo = "patch-package";
+    rev = "v${finalAttrs.version}";
+    hash = "sha256-QuCgdQGqy27wyLUI6w6p8EWLn1XA7QbkjpLJwFXSex8=";
+  };
+
+  yarnOfflineCache = fetchYarnDeps {
+    yarnLock = "${finalAttrs.src}/yarn.lock";
+    hash = "sha256-WF9gJkj4wyrBeGPIzTOw3nG6Se7tFb0YLcAM8Uv9YNI=";
+  };
+
+  nativeBuildInputs = [
+    yarnConfigHook
+    yarnBuildHook
+    yarnInstallHook
+    nodejs
+  ];
+
+  passthru.updateScript = nix-update-script { };
+
+  meta = {
+    description = "Fix broken node modules instantly";
+    mainProgram = "patch-package";
+    homepage = "https://github.com/ds300/patch-package";
+    license = lib.licenses.mit;
+    maintainers = with lib.maintainers; [ pyrox0 ];
+  };
+})
diff --git a/pkgs/development/node-packages/aliases.nix b/pkgs/development/node-packages/aliases.nix
index 4e315d23ef5b..faeaaad5e9d8 100644
--- a/pkgs/development/node-packages/aliases.nix
+++ b/pkgs/development/node-packages/aliases.nix
@@ -141,6 +141,7 @@ mapAliases {
   inherit (pkgs) npm-check-updates; # added 2023-08-22
   ocaml-language-server = throw "ocaml-language-server was removed because it was abandoned upstream"; # added 2023-09-04
   parcel-bundler = self.parcel; # added 2023-09-04
+  inherit (pkgs) patch-package; # added 2024-06-29
   pkg = pkgs.vercel-pkg; # added 2023-10-04
   inherit (pkgs) pm2; # added 2024-01-22
   inherit (pkgs) pnpm; # added 2024-06-26
diff --git a/pkgs/development/node-packages/node-packages.json b/pkgs/development/node-packages/node-packages.json
index 9c50df42a0d2..cf09c1180ac0 100644
--- a/pkgs/development/node-packages/node-packages.json
+++ b/pkgs/development/node-packages/node-packages.json
@@ -151,7 +151,6 @@
 , "orval"
 , "parcel"
 , "parsoid"
-, "patch-package"
 , "peerflix"
 , "peerflix-server"
 , "poor-mans-t-sql-formatter-cli"
diff --git a/pkgs/development/node-packages/node-packages.nix b/pkgs/development/node-packages/node-packages.nix
index ef6e6f2e90e9..9472bba530fc 100644
--- a/pkgs/development/node-packages/node-packages.nix
+++ b/pkgs/development/node-packages/node-packages.nix
@@ -32344,15 +32344,6 @@ let
         sha512 = "0Fo5oir+O9jnXu5EefYbVK+mHMBeEVEy2cmctR1O1NECcCkPRreJKrS6Qt/j3KC2C148Dfo9i3pCmCMsdqGr0g==";
       };
     };
-    "klaw-sync-6.0.0" = {
-      name = "klaw-sync";
-      packageName = "klaw-sync";
-      version = "6.0.0";
-      src = fetchurl {
-        url = "https://registry.npmjs.org/klaw-sync/-/klaw-sync-6.0.0.tgz";
-        sha512 = "nIeuVSzdCCs6TDPTqI8w1Yre34sSq7AkZ4B3sfOBbI2CgVSB4Du4aLQijFU2+lhAFCwt9+42Hel6lQNIv6AntQ==";
-      };
-    };
     "kleur-3.0.3" = {
       name = "kleur";
       packageName = "kleur";
@@ -77438,90 +77429,6 @@ in
     bypassCache = true;
     reconstructLock = true;
   };
-  patch-package = nodeEnv.buildNodePackage {
-    name = "patch-package";
-    packageName = "patch-package";
-    version = "8.0.0";
-    src = fetchurl {
-      url = "https://registry.npmjs.org/patch-package/-/patch-package-8.0.0.tgz";
-      sha512 = "da8BVIhzjtgScwDJ2TtKsfT5JFWz1hYoBl9rUQ1f38MC2HwnEIkK8VN3dKMKcP7P7bvvgzNDbfNHtx3MsQb5vA==";
-    };
-    dependencies = [
-      sources."@yarnpkg/lockfile-1.1.0"
-      sources."ansi-styles-4.3.0"
-      sources."at-least-node-1.0.0"
-      sources."balanced-match-1.0.2"
-      sources."brace-expansion-1.1.11"
-      sources."braces-3.0.3"
-      sources."call-bind-1.0.7"
-      sources."chalk-4.1.2"
-      sources."ci-info-3.9.0"
-      sources."color-convert-2.0.1"
-      sources."color-name-1.1.4"
-      sources."concat-map-0.0.1"
-      sources."cross-spawn-7.0.3"
-      sources."define-data-property-1.1.4"
-      sources."es-define-property-1.0.0"
-      sources."es-errors-1.3.0"
-      sources."fill-range-7.1.1"
-      sources."find-yarn-workspace-root-2.0.0"
-      sources."fs-extra-9.1.0"
-      sources."fs.realpath-1.0.0"
-      sources."function-bind-1.1.2"
-      sources."get-intrinsic-1.2.4"
-      sources."glob-7.2.3"
-      sources."gopd-1.0.1"
-      sources."graceful-fs-4.2.11"
-      sources."has-flag-4.0.0"
-      sources."has-property-descriptors-1.0.2"
-      sources."has-proto-1.0.3"
-      sources."has-symbols-1.0.3"
-      sources."hasown-2.0.2"
-      sources."inflight-1.0.6"
-      sources."inherits-2.0.4"
-      sources."is-docker-2.2.1"
-      sources."is-number-7.0.0"
-      sources."is-wsl-2.2.0"
-      sources."isarray-2.0.5"
-      sources."isexe-2.0.0"
-      sources."json-stable-stringify-1.1.1"
-      sources."jsonfile-6.1.0"
-      sources."jsonify-0.0.1"
-      sources."klaw-sync-6.0.0"
-      sources."micromatch-4.0.8"
-      sources."minimatch-3.1.2"
-      sources."minimist-1.2.8"
-      sources."object-keys-1.1.1"
-      sources."once-1.4.0"
-      sources."open-7.4.2"
-      sources."os-tmpdir-1.0.2"
-      sources."path-is-absolute-1.0.1"
-      sources."path-key-3.1.1"
-      sources."picomatch-2.3.1"
-      sources."rimraf-2.7.1"
-      sources."semver-7.6.3"
-      sources."set-function-length-1.2.2"
-      sources."shebang-command-2.0.0"
-      sources."shebang-regex-3.0.0"
-      sources."slash-2.0.0"
-      sources."supports-color-7.2.0"
-      sources."tmp-0.0.33"
-      sources."to-regex-range-5.0.1"
-      sources."universalify-2.0.1"
-      sources."which-2.0.2"
-      sources."wrappy-1.0.2"
-      sources."yaml-2.5.1"
-    ];
-    buildInputs = globalBuildInputs;
-    meta = {
-      description = "Fix broken node modules with no fuss";
-      homepage = "https://github.com/ds300/patch-package#readme";
-      license = "MIT";
-    };
-    production = true;
-    bypassCache = true;
-    reconstructLock = true;
-  };
   peerflix = nodeEnv.buildNodePackage {
     name = "peerflix";
     packageName = "peerflix";