You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
813 B
JavaScript
38 lines
813 B
JavaScript
5 years ago
|
"use strict";
|
||
|
|
||
|
// const nijs = require("nijs");
|
||
|
const path = require("path");
|
||
|
|
||
|
function nixEscapeString(string) {
|
||
|
return string
|
||
|
.replace(/\\/g, "\\\\")
|
||
|
.replace(/"/g, "\\\"");
|
||
|
}
|
||
|
|
||
|
module.exports = function generateEnvironment({ targetBinary, packages, binaryName }) {
|
||
|
// return nijs.jsToNix("foo", true);
|
||
|
|
||
|
// return nijs.jsToNix(function (args) {
|
||
|
// return args.pkgs().buildFHSUserEnv({
|
||
|
// name: path.basename(targetBinary)
|
||
|
// });
|
||
|
// }, true);
|
||
|
|
||
|
return `
|
||
|
{ pkgs ? import <nixpkgs> {} }:
|
||
|
pkgs.buildFHSUserEnv {
|
||
|
name = "${nixEscapeString(binaryName)}";
|
||
|
|
||
|
targetPkgs = pkgs: with pkgs; [
|
||
|
${packages.join(" ")}
|
||
|
];
|
||
|
|
||
|
runScript = pkgs.writeScript "run-${nixEscapeString(binaryName)}" ''
|
||
|
cmd="$1"
|
||
|
shift
|
||
|
exec -- "${nixEscapeString(targetBinary)}" "$@"
|
||
|
'';
|
||
|
}
|
||
|
`;
|
||
|
};
|