-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
44 lines (39 loc) · 1.45 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
outputs = inputs:
{
overlay = final: prev: {
mkDenoDrv = { name, src, lockfile, entrypoint }@args:
let
inherit (builtins) split hashString;
inherit (prev) lib fetchurl linkFarm writeText runCommand deno;
inherit (prev.lib) elemAt flatten mapAttrsToList importJSON;
inherit (prev.stdenv) mkDerivation;
urlPart = url: elemAt (flatten (split "://([a-z0-9\.]*)" url));
artifactPath = url: "${urlPart url 0}/${urlPart url 1}/${hashString "sha256" (urlPart url 2)}";
dep = url: sha256: [
{
name = artifactPath url;
path = fetchurl { inherit url sha256; };
}
{
name = (artifactPath url) + ".metadata.json";
path = writeText "metadata.json" ''{"headers": {}, "url": ""}'';
}
];
deps = linkFarm "deps" (flatten (mapAttrsToList dep (importJSON lockfile)));
in
mkDerivation
({
buildPhase = ''
export DENO_DIR=`mktemp -d`
ln -s "${deps}" "$DENO_DIR/deps"
${deno}/bin/deno compile --unstable --lock="$lockfile" --cached-only -o "$name" "$entrypoint"
'';
installPhase = ''
mkdir -p "$out/bin"
mv "$name" "$out/bin/"
'';
} // args);
};
};
}