1{ stdenv
2, lib
3, callPackage
4, fetchFromGitHub
5, rustPlatform
6, installShellFiles
7, libiconv
8, darwin
9, librusty_v8 ? callPackage ./librusty_v8.nix { }
10}:
11
12rustPlatform.buildRustPackage rec {
13 pname = "deno";
14 version = "1.34.1";
15
16 src = fetchFromGitHub {
17 owner = "denoland";
18 repo = pname;
19 rev = "v${version}";
20 hash = "sha256-LpW1cbedMPG8VeuQldfYfnxdLrOeDSSf60WfYJbDwHw=";
21 };
22 cargoHash = "sha256-HRsEekv1vSDm2Nk7xvcRmMfHxl4M6BWwHbdPNNop4Ic=";
23
24 postPatch = ''
25 # upstream uses lld on aarch64-darwin for faster builds
26 # within nix lld looks for CoreFoundation rather than CoreFoundation.tbd and fails
27 substituteInPlace .cargo/config.toml --replace '"-C", "link-arg=-fuse-ld=lld"' ""
28 '';
29
30 nativeBuildInputs = [ installShellFiles ];
31 buildInputs = lib.optionals stdenv.isDarwin (
32 [ libiconv darwin.libobjc ] ++
33 (with darwin.apple_sdk.frameworks; [ Security CoreServices Metal Foundation QuartzCore ])
34 );
35
36 buildAndTestSubdir = "cli";
37
38 # The v8 package will try to download a `librusty_v8.a` release at build time to our read-only filesystem
39 # To avoid this we pre-download the file and export it via RUSTY_V8_ARCHIVE
40 RUSTY_V8_ARCHIVE = librusty_v8;
41
42 # Tests have some inconsistencies between runs with output integration tests
43 # Skipping until resolved
44 doCheck = false;
45
46 preInstall = ''
47 find ./target -name libswc_common${stdenv.hostPlatform.extensions.sharedLibrary} -delete
48 '';
49
50 postInstall = ''
51 installShellCompletion --cmd deno \
52 --bash <($out/bin/deno completions bash) \
53 --fish <($out/bin/deno completions fish) \
54 --zsh <($out/bin/deno completions zsh)
55 '';
56
57 doInstallCheck = true;
58 installCheckPhase = ''
59 runHook preInstallCheck
60 $out/bin/deno --help
61 $out/bin/deno --version | grep "deno ${version}"
62 runHook postInstallCheck
63 '';
64
65 passthru.updateScript = ./update/update.ts;
66 passthru.tests = callPackage ./tests { };
67
68 meta = with lib; {
69 homepage = "https://deno.land/";
70 changelog = "https://github.com/denoland/deno/releases/tag/v${version}";
71 description = "A secure runtime for JavaScript and TypeScript";
72 longDescription = ''
73 Deno aims to be a productive and secure scripting environment for the modern programmer.
74 Deno will always be distributed as a single executable.
75 Given a URL to a Deno program, it is runnable with nothing more than the ~15 megabyte zipped executable.
76 Deno explicitly takes on the role of both runtime and package manager.
77 It uses a standard browser-compatible protocol for loading modules: URLs.
78 Among other things, Deno is a great replacement for utility scripts that may have been historically written with
79 bash or python.
80 '';
81 license = licenses.mit;
82 maintainers = with maintainers; [ jk ];
83 platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
84 };
85}