Skip to content

Commit

Permalink
migrate to nixjs-rt
Browse files Browse the repository at this point in the history
  • Loading branch information
urbas committed Feb 11, 2024
1 parent 5faf412 commit c1d8109
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 43 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
46 changes: 23 additions & 23 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
'';
};
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.71.0"
channel = "1.76.0"
components = [ "clippy", "rust-analyzer", "rustfmt" ]
profile = "minimal"
17 changes: 9 additions & 8 deletions src/eval/nix_v8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,12 @@ fn nix_value_from_module(
namespace_obj: &v8::Local<v8::Object>,
) -> 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<v8::Function> =
nix_value.try_into().expect("Nix value must be a function.");

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c1d8109

Please sign in to comment.