From 1186a8a9f1dd58ba3bcc7e82f77b0c7ac718bb3b Mon Sep 17 00:00:00 2001 From: the-sun-will-rise-tomorrow <143541718+the-sun-will-rise-tomorrow@users.noreply.github.com> Date: Wed, 6 Nov 2024 12:30:17 +0000 Subject: [PATCH] src/generate.ts: Undo Nix shebang patching Fixes generation of a broken yarn-project.nix when running a Nix-built Yarn. --- src/generate.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/generate.ts b/src/generate.ts index 8ef0a6c..c7beb10 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -59,9 +59,13 @@ export default async ( let yarnBinExpr: string; if (yarnPathAbs === null) { // Assume the current running script is the correct Yarn. - const sha512 = await hashUtils.checksumFile( - process.argv[1] as PortablePath, - ); + let text = (await xfs.readFilePromise(process.argv[1] as PortablePath)).toString(); + // If yarn was installed via Nix, revert shebang patching to get correct checksum + if (text.startsWith("#!/nix/store/")) { + const code = text.substring(text.indexOf("\n") + 1); + text = `#!/usr/bin/env node\n${code}`; + } + const sha512 = hashUtils.makeHash(Buffer.from(text)); yarnBinExpr = [ "fetchurl {", ` url = "https://repo.yarnpkg.com/${YarnVersion!}/packages/yarnpkg-cli/bin/yarn.js";`,