Skip to content

Commit 7572928

Browse files
committed
editors/vscode: patchelf-ing without intermediate files
1 parent 8e0d776 commit 7572928

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

editors/code/src/main.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ async function patchelf(dest: PathLike): Promise<void> {
196196
title: "Patching rust-analysis for NixOS"
197197
},
198198
async (progress, _) => {
199-
const patchPath = path.join(os.tmpdir(), "patch-ra.nix");
200-
progress.report({ message: "Writing nix file", increment: 5 });
201-
await fs.writeFile(patchPath, `
199+
const expression = `
202200
{src, pkgs ? import <nixpkgs> {}}:
203201
pkgs.stdenv.mkDerivation {
204202
name = "rust-analyzer";
@@ -210,19 +208,21 @@ async function patchelf(dest: PathLike): Promise<void> {
210208
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out
211209
'';
212210
}
213-
`);
211+
`;
214212
const origFile = dest + "-orig";
215213
await fs.rename(dest, origFile);
216214
progress.report({ message: "Patching executable", increment: 20 });
217215
await new Promise((resolve, reject) => {
218-
exec(`nix-build ${patchPath} --arg src '${origFile}' -o ${dest}`,
216+
const handle = exec(`nix-build -E - --arg src '${origFile}' -o ${dest}`,
219217
(err, stdout, stderr) => {
220218
if (err != null) {
221219
reject(Error(stderr));
222220
} else {
223221
resolve(stdout);
224222
}
225223
});
224+
handle.stdin?.write(expression);
225+
handle.stdin?.end();
226226
});
227227
await fs.unlink(origFile);
228228
}

0 commit comments

Comments
 (0)