deno2.nix/nix/make-executable.nix

45 lines
851 B
Nix
Raw Normal View History

{
pkgs,
stdenv,
deno2nix,
...
}: {
pname,
2022-08-03 23:32:54 +00:00
version,
src,
lockfile,
output ? pname,
entrypoint,
2022-08-03 23:32:54 +00:00
importMap ? null,
additionalDenoFlags ? "",
2022-08-03 23:32:54 +00:00
}: let
inherit (deno2nix.internal) mkDepsLink;
2022-08-03 23:32:54 +00:00
in
stdenv.mkDerivation {
inherit pname version src;
dontFixup = true;
2022-08-03 23:32:54 +00:00
buildInputs = with pkgs; [deno jq];
2022-08-03 23:32:54 +00:00
buildPhase = ''
export DENO_DIR=`mktemp -d`
ln -s "${mkDepsLink lockfile}" $(deno info --json | jq -r .modulesCache)
deno compile \
--cached-only \
--lock="${lockfile}" \
--output="${output}" \
${
if importMap != null
then "--import-map=\"$src/${importMap}\""
else ""
} \
${additionalDenoFlags} \
"$src/${entrypoint}"
2022-08-03 23:32:54 +00:00
'';
2022-08-03 23:32:54 +00:00
installPhase = ''
mkdir -p $out/bin
cp "${output}" "$out/bin/"
2022-08-03 23:32:54 +00:00
'';
}