From c1d8109c945f95704f8eb6fea49bdd7c25dbeb8b Mon Sep 17 00:00:00 2001 From: Matej Urbas Date: Sat, 10 Feb 2024 09:20:30 +0000 Subject: [PATCH] migrate to nixjs-rt --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- flake.lock | 46 ++++++++++++++++++++++----------------------- flake.nix | 19 +++++++++++-------- rust-toolchain.toml | 2 +- src/eval/nix_v8.rs | 17 +++++++++-------- 6 files changed, 47 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4942224..175143c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -683,9 +683,9 @@ dependencies = [ [[package]] name = "v8" -version = "0.74.1" +version = "0.80.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1202e0bd078112bf8d521491560645e1fd6955c4afd975c75b05596a7e7e4eea" +checksum = "959eead7f97b80b08ec7154262c3abef0d9c4de2f4b80c100762d7fa880258fe" dependencies = [ "bitflags 1.3.2", "fslock", diff --git a/Cargo.toml b/Cargo.toml index 10ad2a8..47defa4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,4 +32,4 @@ serde = { version = "1.0.147", features = ["derive"] } serde_json = "1.0.87" tempfile = "3.3.0" uuid = { version = "1.2.1", features = ["v4"] } -v8 = "0" +v8 = "0.80.0" diff --git a/flake.lock b/flake.lock index 07f12ba..f4d9dcb 100644 --- a/flake.lock +++ b/flake.lock @@ -1,12 +1,30 @@ { "nodes": { + "nixjs-rt": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1707640111, + "narHash": "sha256-H4VMvxvN2+l0gZalvFyxEALWlYjZm1+Vh6m3VEFs/mU=", + "owner": "urbas", + "repo": "nixjs-rt", + "rev": "d01121bab47082d1986f00c88cbb887890d5b69f", + "type": "github" + }, + "original": { + "owner": "urbas", + "repo": "nixjs-rt", + "type": "github" + } + }, "nixpkgs": { "locked": { - "lastModified": 1689631193, - "narHash": "sha256-AGSkBZaiTODQc8eT1rZDrQIjtb8JtFwJ0wVPzArlrnM=", + "lastModified": 1707451808, + "narHash": "sha256-UwDBUNHNRsYKFJzyTMVMTF5qS4xeJlWoeyJf+6vvamU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "57695599bdc4f7bfe5d28cfa23f14b3d8bdf8a5f", + "rev": "442d407992384ed9c0e6d352de75b69079904e4e", "type": "github" }, "original": { @@ -30,28 +48,10 @@ "type": "indirect" } }, - "nixrt": { - "inputs": { - "nixpkgs": "nixpkgs_2" - }, - "locked": { - "lastModified": 1689706907, - "narHash": "sha256-A+jUzcZraJYQ9YyfOmKub1ItPl5r/fzlkWr5gNTUOeg=", - "owner": "urbas", - "repo": "nixrt", - "rev": "304a8c13e4b7b8082692ef93a19b92da677908eb", - "type": "github" - }, - "original": { - "owner": "urbas", - "repo": "nixrt", - "type": "github" - } - }, "root": { "inputs": { - "nixpkgs": "nixpkgs", - "nixrt": "nixrt" + "nixjs-rt": "nixjs-rt", + "nixpkgs": "nixpkgs_2" } } }, diff --git a/flake.nix b/flake.nix index 1f58d32..ba37f07 100644 --- a/flake.nix +++ b/flake.nix @@ -2,30 +2,33 @@ description = "A reimplementation or nix in Rust."; inputs.nixpkgs.url = "nixpkgs/nixpkgs-unstable"; - inputs.nixrt.url = "github:urbas/nixrt"; + inputs.nixjs-rt.url = "github:urbas/nixjs-rt"; - outputs = { self, nixpkgs, nixrt }: + outputs = { self, nixpkgs, nixjs-rt }: let supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; - forSupportedSystems = f: with nixpkgs.lib; foldl' (resultAttrset: system: recursiveUpdate resultAttrset (f { inherit system; pkgs = import nixpkgs { inherit system; }; })) {} supportedSystems; + forSupportedSystems = f: with nixpkgs.lib; foldl' (resultAttrset: system: recursiveUpdate resultAttrset (f { inherit system; pkgs = import nixpkgs { inherit system; }; })) { } supportedSystems; - in forSupportedSystems ({ pkgs, system, ... }: + in + forSupportedSystems ({ pkgs, system, ... }: let buildInputs = with pkgs; [ busybox-sandbox-shell coreutils nix - nixrt.packages.${system}.default + nixjs-rt.packages.${system}.default + nixpkgs-fmt rustup ]; - in { - packages.${system} = { inherit nixrt pkgs; }; + in + { + packages.${system} = { inherit nixjs-rt pkgs; }; devShells.${system}.default = pkgs.stdenv.mkDerivation { name = "rix"; inherit buildInputs; shellHook = '' - export RIX_NIXRT_JS_MODULE=${nixrt.packages.${system}.default}/lib/node_modules/nixrt/dist/lib.js + export RIX_NIXRT_JS_MODULE=${nixjs-rt.packages.${system}.default}/lib/node_modules/nixjs-rt/dist/lib.js export RUSTFLAGS=-Dwarnings ''; }; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 338c5de..c978288 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,4 +1,4 @@ [toolchain] -channel = "1.71.0" +channel = "1.76.0" components = [ "clippy", "rust-analyzer", "rustfmt" ] profile = "minimal" \ No newline at end of file diff --git a/src/eval/nix_v8.rs b/src/eval/nix_v8.rs index 9f68160..5e9d08e 100644 --- a/src/eval/nix_v8.rs +++ b/src/eval/nix_v8.rs @@ -476,10 +476,12 @@ fn nix_value_from_module( namespace_obj: &v8::Local, ) -> EvalResult { let nix_value_attr = v8::String::new(scope, "__nixValue").unwrap(); - let Some(nix_value) = namespace_obj - .get(scope, nix_value_attr.into()) else { - todo!("Could not find the nix value: {:?}", namespace_obj.to_rust_string_lossy(scope)) - }; + let Some(nix_value) = namespace_obj.get(scope, nix_value_attr.into()) else { + todo!( + "Could not find the nix value: {:?}", + namespace_obj.to_rust_string_lossy(scope) + ) + }; let nix_value: v8::Local = nix_value.try_into().expect("Nix value must be a function."); @@ -516,10 +518,9 @@ fn call_js_function<'s>( // TODO: Again, the stack trace needs to be source-mapped. See TODO above. let err_msg = scope .stack_trace() - .map_or( - "Unknown evaluation error.".to_owned(), - |stack| stack.to_rust_string_lossy(scope), - ); + .map_or("Unknown evaluation error.".to_owned(), |stack| { + stack.to_rust_string_lossy(scope) + }); return Err(err_msg); }; Ok(strict_nix_value)