forked from denoland/deno
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
161 lines (139 loc) · 5.32 KB
/
flake.nix
File metadata and controls
161 lines (139 loc) · 5.32 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# This provides a Nix dev shell and Nix build for deno and denort binaries.
{
description = "Deno";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
inherit (nixpkgs.lib) mapAttrsToList concatStringsSep;
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
rustToolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
cargoToml = builtins.fromTOML (builtins.readFile ./cli/Cargo.toml);
denoVersion = cargoToml.package.version;
cargoLock = builtins.fromTOML (builtins.readFile ./Cargo.lock);
rustyV8Version = (builtins.head (builtins.filter (p: p.name == "v8") cargoLock.package)).version;
rustyV8Targets = {
"x86_64-linux" = "x86_64-unknown-linux-gnu";
"aarch64-linux" = "aarch64-unknown-linux-gnu";
"x86_64-darwin" = "x86_64-apple-darwin";
"aarch64-darwin" = "aarch64-apple-darwin";
};
rustyV8Target = rustyV8Targets.${system};
rustyV8 = pkgs.fetchurl {
url = "https://github.com/denoland/rusty_v8/releases/download/v${rustyV8Version}/librusty_v8_release_${rustyV8Target}.a.gz";
sha256 = {
"x86_64-linux" = "sha256-PYCBh8+RY1nvPOKXMCns5mDRo2j0SB3Edw/ut7npjxo=";
"aarch64-linux" = "sha256-EGlTttOowHhoFBy8FQeokCnbPLi4tfkIhSek28TfcGQ=";
"x86_64-darwin" = "sha256-61d4tQ/PcNPUvDuQsMNTNUO43zLZSVEHOjdGFG0u4W8=";
"aarch64-darwin" = "sha256-BMKybPdxP9+7QD/yfbnPnFxD8N7kHPUkMcEEf4P4iSE=";
}.${system};
};
commonNativeBuildInputs = with pkgs; [
rustToolchain
llvmPackages_20.clang
lld_20
llvmPackages_20.libllvm
pkg-config
cmake
protobuf
];
commonBuildInputs = with pkgs; [
openssl
] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [
glib
];
buildDenoBin = { pname, binName ? pname }: pkgs.rustPlatform.buildRustPackage {
inherit pname;
version = denoVersion;
src = ./.;
cargoLock.lockFile = ./Cargo.lock;
nativeBuildInputs = commonNativeBuildInputs;
buildInputs = commonBuildInputs;
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [
pkgs.llvmPackages_20.clang-unwrapped.lib
];
RUSTY_V8_ARCHIVE = rustyV8;
buildPhase = ''
unset AS
cargo build --release --bin ${binName}
'';
installPhase = ''
mkdir -p $out/bin
cp target/release/${binName} $out/bin/
'';
doCheck = false;
};
in
{
packages = {
deno = buildDenoBin { pname = "deno"; };
denort = buildDenoBin { pname = "denort"; };
default = self.packages.${system}.deno;
};
apps.nix-update-rusty-v8 = {
type = "app";
program = toString (pkgs.writeShellScript "update-rusty-v8" ''
set -euo pipefail
function update() {
sys=$1
target=$2
url="https://github.com/denoland/rusty_v8/releases/download/v${rustyV8Version}/librusty_v8_release_$target.a.gz"
hash=$(nix store prefetch-file --json "$url" | ${pkgs.lib.getExe pkgs.jq} -r '.hash')
sed -i "s|\"$sys\" = \"sha256-[^\"]*\";|\"$sys\" = \"$hash\";|" flake.nix
}
${concatStringsSep "\n" (mapAttrsToList (sys: target: "update ${sys} ${target}") rustyV8Targets)}
'');
};
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
rustToolchain
llvmPackages_20.clang
lld_20
llvmPackages_20.libllvm
pkg-config
cmake
protobuf
openssl
] ++ lib.optionals stdenv.isLinux [
glib
];
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [
pkgs.llvmPackages_20.clang-unwrapped.lib
];
# Allow cargo to download crates
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
shellHook = ''
# Fix invalid option errors during linking
unset AS
'' + pkgs.lib.optionalString pkgs.stdenv.isLinux ''
# On non-NixOS Linux, prevent Nix from setting the interpreter and rpath
# which would make compiled binaries dependent on the Nix store.
# See: https://matklad.github.io/2022/03/14/rpath-or-why-lld-doesnt-work-on-nixos.html
if ! [ -e /etc/NIXOS ]; then
set -- $NIX_LDFLAGS
for i; do
shift
if [ "$i" = -rpath ]; then
shift
else
set -- "$@" "$i"
fi
done
export NIX_DYNAMIC_LINKER=$(patchelf --print-interpreter /usr/bin/env)
export NIX_DONT_SET_RPATH=1
export NIX_LDFLAGS="$@"
fi
'';
};
});
}