editors/vscode: patchelf-ing without intermediate files

This commit is contained in:
Vladimir Serov 2020-05-21 21:30:56 +03:00
parent 8e0d776369
commit 757292856b
No known key found for this signature in database
GPG key ID: 6BA7C26C3FDF7BB3

View file

@ -196,9 +196,7 @@ async function patchelf(dest: PathLike): Promise<void> {
title: "Patching rust-analysis for NixOS" title: "Patching rust-analysis for NixOS"
}, },
async (progress, _) => { async (progress, _) => {
const patchPath = path.join(os.tmpdir(), "patch-ra.nix"); const expression = `
progress.report({ message: "Writing nix file", increment: 5 });
await fs.writeFile(patchPath, `
{src, pkgs ? import <nixpkgs> {}}: {src, pkgs ? import <nixpkgs> {}}:
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
name = "rust-analyzer"; name = "rust-analyzer";
@ -210,12 +208,12 @@ async function patchelf(dest: PathLike): Promise<void> {
patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out
''; '';
} }
`); `;
const origFile = dest + "-orig"; const origFile = dest + "-orig";
await fs.rename(dest, origFile); await fs.rename(dest, origFile);
progress.report({ message: "Patching executable", increment: 20 }); progress.report({ message: "Patching executable", increment: 20 });
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
exec(`nix-build ${patchPath} --arg src '${origFile}' -o ${dest}`, const handle = exec(`nix-build -E - --arg src '${origFile}' -o ${dest}`,
(err, stdout, stderr) => { (err, stdout, stderr) => {
if (err != null) { if (err != null) {
reject(Error(stderr)); reject(Error(stderr));
@ -223,6 +221,8 @@ async function patchelf(dest: PathLike): Promise<void> {
resolve(stdout); resolve(stdout);
} }
}); });
handle.stdin?.write(expression);
handle.stdin?.end();
}); });
await fs.unlink(origFile); await fs.unlink(origFile);
} }