about summary refs log tree commit diff
path: root/pkgs/development/tools/yarn2nix-moretea/yarn2nix
diff options
context:
space:
mode:
authorGuillaume Desforges <guillaume.desforges.pro@gmail.com>2023-02-06 16:27:02 +0100
committerGuillaume Desforges <guillaume.desforges.pro@gmail.com>2023-04-11 10:58:16 +0000
commit6bf78d8d3d07a77c043b68f3795a250257a23b21 (patch)
tree8ece7cbfa943fccbe9fc30882fdf9d9999cc6a8e /pkgs/development/tools/yarn2nix-moretea/yarn2nix
parent747927516efcb5e31ba03b7ff32f61f6d47e7d87 (diff)
mkYarnPackage: fix uncopied resolutions field
Yarn only uses the "resolutions" field in the top-level package.json
file of a workspace. While it has been taken into account for
mkYarnWorkspace (9801e6e53dc321e860c822f7f3c370e76d218a42), it has not
been fixed for mkYarnPackage yet, which also uses the yarn workspace
mechanism under the hood.

A bit of care was needed because we don't want to introduce any IFD.
Diffstat (limited to 'pkgs/development/tools/yarn2nix-moretea/yarn2nix')
-rw-r--r--pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix14
1 files changed, 11 insertions, 3 deletions
diff --git a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix
index 6098c50df1376..e0bd54fd11a97 100644
--- a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix
+++ b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/default.nix
@@ -99,9 +99,17 @@ in rec {
           ""
       ) (builtins.attrNames pkgConfig));
 
-      workspaceJSON = pkgs.writeText
-        "${name}-workspace-package.json"
-        (builtins.toJSON { private = true; workspaces = ["deps/**"]; resolutions = packageResolutions; }); # scoped packages need second splat
+      # build-time JSON generation to avoid IFD
+      # see https://nixos.wiki/wiki/Import_From_Derivation
+      workspaceJSON = pkgs.runCommand "${name}-workspace-package.json"
+        {
+          nativeBuildInputs = [ pkgs.jq ];
+          inherit packageJSON;
+          passAsFile = [ "baseJSON" ];
+          baseJSON = builtins.toJSON { private = true; workspaces = [ "deps/**" ]; resolutions = packageResolutions; };
+        } ''
+        jq --slurpfile packageJSON "$packageJSON" '.resolutions = $packageJSON[0].resolutions + .resolutions' <"$baseJSONPath" >$out
+      '';
 
       workspaceDependencyLinks = lib.concatMapStringsSep "\n"
         (dep: ''