From 4b3a198904d2ed55e1753557beb246fc214443e2 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Tue, 15 Mar 2022 03:37:36 +0100 Subject: [PATCH] Add support for patching dependencies Can be used to patchShebangs for specific packages, which with NPM version 7.0 can't be done globally for all packages anymore Could also be a replacement for preInstallLinks --- API.md | 21 +++ internal.nix | 147 ++++++++++++++++-- .../source-patching/package-lock.json | 13 ++ .../source-patching/package.json | 11 ++ .../source-patching/shell.nix | 25 +++ tests/integration-tests/default.nix | 8 + tests/lib.nix | 5 +- tests/make-source.nix | 5 +- 8 files changed, 217 insertions(+), 18 deletions(-) create mode 100644 tests/examples-projects/source-patching/package-lock.json create mode 100644 tests/examples-projects/source-patching/package.json create mode 100644 tests/examples-projects/source-patching/shell.nix diff --git a/API.md b/API.md index ea50b97..8d1e70c 100644 --- a/API.md +++ b/API.md @@ -16,6 +16,7 @@ The `node_modules` function takes an attribute set with the following attributes - **nodejs** *(default `nixpkgs.nodejs`, which is the Active LTS version)*: Node.js derivation to use - **preInstallLinks** *(default `{}`)*: Map of symlinks to create inside npm dependencies in the `node_modules` output (See [Concepts](#concepts) for details). - **githubSourceHashMap** *(default `{}`)*: Dependency hashes for evaluation in restricted mode (See [Concepts](#concepts) for details). +- **sourceMods** *(default `{}`)*: Source modifications (See [Concepts](#concepts) for details) #### Notes - You may provide additional arguments accepted by `mkDerivation` all of which are going to be passed on. @@ -114,3 +115,23 @@ npmlock2nix.build { }; } ``` + +### Source modifications + +`node_modules` takes a `sourceMods` argument, which allows you to modify sources of individual npm packages you depend on, useful for adding Nix-specific fixes to packages. This could be used for patching interpreter or paths, or to replace vendored binaries with ones provided by Nix: + +```nix +npmlock2nix.node_modules { + sourceMods = { + # = { version }: { + # patches = [ ]; + # postPatch =