From 487aaa905f78e7f3acaef238650552d74730851b Mon Sep 17 00:00:00 2001 From: AmineChikhaoui Date: Thu, 15 Apr 2021 05:02:41 -0400 Subject: [PATCH] yarn2nix: use yarn lockfile integrity field whenever possible Whenever available use the SRI hashes from the integrity field to create the fetchurl calls instead of entirely relying on the `resolved` sha1 which may or may not exist with recent yarn versions. Related issues: - https://github.com/nix-community/yarn2nix/issues/125 - https://github.com/NixOS/nixpkgs/issues/77238 --- .../yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js | 4 ++-- .../tools/yarn2nix-moretea/yarn2nix/lib/generateNix.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js index 86e92f852087..3c067fc99aaa 100755 --- a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js +++ b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/internal/fixup_yarn_lock.js @@ -25,14 +25,14 @@ const result = [] readFile .on('line', line => { - const arr = line.match(/^ {2}resolved "([^#]+)#([^"]+)"$/) + const arr = line.match(/^ {2}resolved "([^#]+)(#[^"]+)?"$/) if (arr !== null) { const [_, url, shaOrRev] = arr const fileName = urlToName(url) - result.push(` resolved "${fileName}#${shaOrRev}"`) + result.push(` resolved "${fileName}${shaOrRev ?? ''}"`) } else { result.push(line) } diff --git a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/generateNix.js b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/generateNix.js index 1e7b4f341002..5004e6f3903d 100644 --- a/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/generateNix.js +++ b/pkgs/development/tools/yarn2nix-moretea/yarn2nix/lib/generateNix.js @@ -69,7 +69,7 @@ function fetchgit(fileName, url, rev, branch, builtinFetchGit) { function fetchLockedDep(builtinFetchGit) { return function (pkg) { - const { nameWithVersion, resolved } = pkg + const { integrity, nameWithVersion, resolved } = pkg if (!resolved) { console.error( @@ -102,14 +102,14 @@ function fetchLockedDep(builtinFetchGit) { return fetchgit(fileName, urlForGit, rev, branch || 'master', builtinFetchGit) } - const sha = sha1OrRev + const [algo, hash] = integrity ? integrity.split('-') : ['sha1', sha1OrRev] return ` { name = "${fileName}"; path = fetchurl { name = "${fileName}"; url = "${url}"; - sha1 = "${sha}"; + ${algo} = "${hash}"; }; }` }