Skip to content

Commit 409a1f0

Browse files
committed
deno: init at 1.0.0
Adding deno for it's 1.0.0 release * Builds from source (doesn't build V8 from source) * Runs most of the tests * Bundles completions for: * bash - tested * zsh - untested * fish - untested * Set up for multiple builds: * x86_64-linux * Passed - NixOS * aarch64-linux * Passed just build - Raspbian on RPI4 * Failed build + check (ended with SIGKILL 9) * x86_64-darwin * Untested
1 parent d200350 commit 409a1f0

File tree

2 files changed

+143
-0
lines changed

2 files changed

+143
-0
lines changed

pkgs/development/web/deno/default.nix

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{ stdenv
2+
, fetchurl
3+
, fetchFromGitHub
4+
, rust
5+
, rustPlatform
6+
, python27
7+
, installShellFiles
8+
, Security
9+
, CoreServices
10+
}:
11+
let
12+
pname = "deno";
13+
version = "1.0.0";
14+
15+
denoSrc = fetchFromGitHub {
16+
owner = "denoland";
17+
repo = pname;
18+
rev = "v${version}";
19+
sha256 = "0k8mqy1hf9hkp60jhd0x4z814y36g51083b3r7prc69ih2523hd1";
20+
21+
fetchSubmodules = true;
22+
};
23+
cargoSha256 = "1fjl07qqvl1f20qazcqxh32xmdfh80jni7i3jzvz6vgsfw1g5cmk";
24+
25+
rustyV8Lib = fetchlib "rusty_v8" "0.4.2" {
26+
x86_64-linux = "1ac6kv3kv087df6kdgfd7kbh24187cg9z7xhbz6rw6jjv4ci2zbi";
27+
aarch64-linux = "06iyjx4p4vp2i81wdy0vxai2k18pki972ff7k0scjqrgmnav1p8k";
28+
x86_64-darwin = "02hwbpsqdzb9mvfndgykvv44f1jig3w3a26l0h26hs5shsrp47jv";
29+
};
30+
31+
arch = rust.toRustTarget stdenv.hostPlatform;
32+
fetchlib = name: version: sha256: fetchurl {
33+
url = "https://github.com/denoland/${name}/releases/download/v${version}/librusty_v8_release_${arch}.a";
34+
sha256 = sha256."${stdenv.hostPlatform.system}";
35+
meta = { inherit version; };
36+
};
37+
in
38+
rustPlatform.buildRustPackage rec {
39+
inherit pname version cargoSha256;
40+
41+
src = denoSrc;
42+
43+
nativeBuildInputs = [
44+
# chromium/V8 requires python 2.7, we're not building V8 from source
45+
# but as a result rusty_v8's download script also uses python 2.7
46+
# tracking issue: https://bugs.chromium.org/p/chromium/issues/detail?id=942720
47+
python27
48+
49+
# Install completions post-install
50+
installShellFiles
51+
];
52+
53+
buildInputs = with stdenv.lib; [ ]
54+
++ optionals stdenv.isDarwin [ Security CoreServices ];
55+
56+
# The rusty_v8 package will try to download a `librusty_v8.a` release at build time to our read-only filesystem
57+
# To avoid this we pre-download the file and place it in the locations it will require it in advance
58+
preBuild = ''
59+
# Check the rusty_v8 lib downloaded matches the Cargo.lock file
60+
rusty_v8_ver="$(grep 'name = "rusty_v8"' -A 1 Cargo.lock | grep "version =" | cut -d\" -f2)"
61+
if [ "${rustyV8Lib.meta.version}" != "$rusty_v8_ver" ]; then
62+
printf "%s\n" >&2 \
63+
"version mismatch between 'rusty_v8' in Cargo.lock and downloaded library:" \
64+
" wanted: ${rustyV8Lib.meta.version}" \
65+
" got: $rusty_v8_ver"
66+
exit 1
67+
fi;
68+
69+
_rusty_v8_setup() {
70+
for v in "$@"; do
71+
dir="target/$v/gn_out/obj"
72+
mkdir -p "$dir" && cp "${rustyV8Lib}" "$dir/librusty_v8.a"
73+
done
74+
}
75+
76+
# Copy over the `librusty_v8.a` file inside target/XYZ/gn_out/obj, symlink not allowed
77+
_rusty_v8_setup "debug" "release" "${arch}/release"
78+
'';
79+
80+
# Set home to existing env var TMP dir so tests that write there work correctly
81+
preCheck = ''
82+
export HOME="$TMPDIR"
83+
'';
84+
85+
checkFlags = [
86+
# Strace not allowed on hydra
87+
"--skip benchmark_test"
88+
89+
# Tests that try to write to `/build/source/target/debug`
90+
"--skip _017_import_redirect"
91+
"--skip https_import"
92+
"--skip js_unit_tests"
93+
"--skip lock_write_fetch"
94+
95+
# Cargo test runs a deno test on the std lib with sub-benchmarking-tests,
96+
# The sub-sub-tests that are failing:
97+
# forAwaitFetchDenolandX10, promiseAllFetchDenolandX10is
98+
# Trying to access https://deno.land/ on build's limited network access
99+
"--skip std_tests"
100+
101+
# Fails on aarch64 machines
102+
# tracking issue: https://github.com/denoland/deno/issues/5324
103+
"--skip run_v8_flags"
104+
105+
# Skip for multiple reasons:
106+
# downloads x86_64 binary on aarch64 machines
107+
# tracking issue: https://github.com/denoland/deno/pull/5402
108+
# downloads a binary that needs ELF patching & tries to run imediately
109+
# upgrade will likely never work with nix as it tries to replace itself
110+
# code: https://github.com/denoland/deno/blob/v1.0.0/cli/upgrade.rs#L211
111+
"--skip upgrade_in_tmpdir"
112+
"--skip upgrade_with_version_in_tmpdir"
113+
];
114+
115+
# TODO: Move to enhanced installShellCompletion when merged: PR #83630
116+
postInstall = ''
117+
$out/bin/deno completions bash > deno.bash
118+
$out/bin/deno completions fish > deno.fish
119+
$out/bin/deno completions zsh > _deno
120+
installShellCompletion deno.{bash,fish} --zsh _deno
121+
'';
122+
123+
meta = with stdenv.lib; {
124+
homepage = "https://deno.land/";
125+
description = "A secure runtime for JavaScript and TypeScript";
126+
longDescription = ''
127+
Deno aims to be a productive and secure scripting environment for the modern programmer.
128+
Deno will always be distributed as a single executable.
129+
Given a URL to a Deno program, it is runnable with nothing more than the ~15 megabyte zipped executable.
130+
Deno explicitly takes on the role of both runtime and package manager.
131+
It uses a standard browser-compatible protocol for loading modules: URLs.
132+
Among other things, Deno is a great replacement for utility scripts that may have been historically written with
133+
bash or python.
134+
'';
135+
license = licenses.mit;
136+
maintainers = with maintainers; [ jk ];
137+
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ];
138+
};
139+
}

pkgs/top-level/all-packages.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,6 +2837,10 @@ in
28372837

28382838
deer = callPackage ../shells/zsh/zsh-deer { };
28392839

2840+
deno = callPackage ../development/web/deno {
2841+
inherit (darwin.apple_sdk.frameworks) Security CoreServices;
2842+
};
2843+
28402844
detox = callPackage ../tools/misc/detox { };
28412845

28422846
devilspie2 = callPackage ../applications/misc/devilspie2 {

0 commit comments

Comments
 (0)