2022-12-14 04:00:56 +00:00
|
|
|
{
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
stdenv,
|
|
|
|
deno2nix,
|
|
|
|
...
|
|
|
|
}: {
|
|
|
|
pname,
|
|
|
|
version,
|
|
|
|
src,
|
|
|
|
bin ? pname,
|
2023-02-08 15:20:40 +00:00
|
|
|
buildInputs ? [],
|
2022-12-14 04:00:56 +00:00
|
|
|
entrypoint,
|
|
|
|
lockfile,
|
|
|
|
config,
|
|
|
|
allow ? {},
|
|
|
|
additionalDenoFlags ? "",
|
|
|
|
} @ inputs: let
|
|
|
|
inherit (builtins) isString;
|
|
|
|
inherit (lib) importJSON concatStringsSep;
|
|
|
|
inherit (deno2nix.internal) mkDepsLink findImportMap;
|
|
|
|
|
|
|
|
allowflag = flag: (
|
|
|
|
if (allow ? flag) && allow."${flag}"
|
|
|
|
then ["--allow-${flag}"]
|
|
|
|
else []
|
|
|
|
);
|
|
|
|
|
|
|
|
importMap = findImportMap {
|
|
|
|
inherit (inputs) src config importMap;
|
|
|
|
};
|
|
|
|
|
|
|
|
compileCmd = concatStringsSep " " (
|
|
|
|
[
|
|
|
|
"deno compile --cached-only"
|
|
|
|
"--lock=${lockfile}"
|
|
|
|
"--output=${bin}"
|
|
|
|
# "--config=${config}"
|
|
|
|
]
|
|
|
|
++ (
|
|
|
|
if (isString importMap)
|
|
|
|
then ["--import-map=${importMap}"]
|
|
|
|
else []
|
|
|
|
)
|
|
|
|
++ (allowflag "all")
|
|
|
|
++ (allowflag "env")
|
|
|
|
++ (allowflag "ffi")
|
|
|
|
++ (allowflag "hrtime")
|
|
|
|
++ (allowflag "net")
|
|
|
|
++ (allowflag "read")
|
|
|
|
++ (allowflag "run")
|
|
|
|
++ (allowflag "sys")
|
|
|
|
++ (allowflag "write")
|
|
|
|
++ [additionalDenoFlags]
|
|
|
|
++ ["${entrypoint}"]
|
|
|
|
);
|
|
|
|
in
|
|
|
|
stdenv.mkDerivation {
|
|
|
|
inherit pname version src;
|
|
|
|
dontFixup = true;
|
|
|
|
|
2023-02-08 15:20:40 +00:00
|
|
|
buildInputs = with pkgs; [deno jq] ++ buildInputs;
|
2022-12-14 04:00:56 +00:00
|
|
|
buildPhase = ''
|
|
|
|
export DENO_DIR="/tmp/deno2nix"
|
|
|
|
mkdir -p $DENO_DIR
|
|
|
|
ln -s "${mkDepsLink (src + "/${lockfile}")}" $(deno info --json | jq -r .modulesCache)
|
|
|
|
${compileCmd}
|
|
|
|
'';
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out/bin
|
|
|
|
cp "${bin}" "$out/bin/"
|
|
|
|
'';
|
|
|
|
}
|