git.delta.rocks / jrsonnet / refs/commits / d5b0f6a487f6

difftreelog

refactor nix-eval macro-support

loprwqwnYaroslav Bolyukin2026-03-12parent: #493bea4.patch.diff
in: trunk

3 files changed

modifiedcmds/repl-plugin-unstable/src/lib.rsdiffbeforeafterboth
--- a/cmds/repl-plugin-unstable/src/lib.rs
+++ b/cmds/repl-plugin-unstable/src/lib.rs
@@ -1,5 +1,6 @@
 use fleet_base::primops::init_primops;
 
+/// SAFETY: expected plugin dynamic library entry point
 #[unsafe(no_mangle)]
 fn nix_plugin_entry() {
 	init_primops();
modifiedcrates/nix-eval/src/lib.rsdiffbeforeafterboth
--- a/crates/nix-eval/src/lib.rs
+++ b/crates/nix-eval/src/lib.rs
@@ -46,6 +46,14 @@
 pub mod logging;
 #[doc(hidden)]
 pub mod macros;
+
+#[doc(hidden)]
+pub mod __macro_support {
+	pub use std::collections::hash_map::HashMap;
+
+	pub use anyhow::Context;
+	pub use tokio::task::block_in_place;
+}
 pub mod util;
 
 #[allow(
modifiedcrates/nix-eval/src/macros.rsdiffbeforeafterboth
18 (@obj($o:ident)) => {{}};18 (@obj($o:ident)) => {{}};
19 (Obj { }) => {{19 (Obj { }) => {{
20 use $crate::{nix_expr_inner};20 use $crate::{nix_expr_inner};
21 let out = std::collections::hash_map::HashMap::new();21 let out = $crate::__macro_support::HashMap::new();
22 Value::new_attrs(out)22 Value::new_attrs(out)
23 }};23 }};
24 (Obj { $($tt:tt)+ }) => {{24 (Obj { $($tt:tt)+ }) => {{
25 use $crate::{nix_expr_inner};25 use $crate::{nix_expr_inner};
26 let mut out = std::collections::hash_map::HashMap::new();26 let mut out = $crate::__macro_support::HashMap::new();
27 nix_expr_inner!(@obj(out) $($tt)*);27 nix_expr_inner!(@obj(out) $($tt)*);
28 Value::new_attrs(out)28 Value::new_attrs(out)
29 }};29 }};
68#[macro_export]68#[macro_export]
69macro_rules! nix_go {69macro_rules! nix_go {
70 (@o($o:expr, $path:expr) . $var:ident $($tt:tt)*) => {{70 (@o($o:expr, $path:expr) . $var:ident $($tt:tt)*) => {{
71 nix_go!(@o(tokio::task::block_in_place(|| $o.get_field(stringify!($var))).context(concat!("getting nested ", $path))?, $path) $($tt)*)71 nix_go!(@o($crate::__macro_support::block_in_place(|| $o.get_field(stringify!($var))).context(concat!("getting nested ", $path))?, $path) $($tt)*)
72 }};72 }};
73 (@o($o:expr, $path:expr) [ $v:expr ] $($tt:tt)*) => {{73 (@o($o:expr, $path:expr) [ $v:expr ] $($tt:tt)*) => {{
74 nix_go!(@o(tokio::task::block_in_place(|| $o.get_field($v)).context(concat!("getting nested ", $path))?, $path) $($tt)*)74 nix_go!(@o($crate::__macro_support::block_in_place(|| $o.get_field($v)).context(concat!("getting nested ", $path))?, $path) $($tt)*)
75 }};75 }};
76 (@o($o:expr, $path:expr) ($($var:tt)*) $($tt:tt)*) => {76 (@o($o:expr, $path:expr) ($($var:tt)*) $($tt:tt)*) => {
77 nix_go!(@o(tokio::task::block_in_place(|| $o.call($crate::nix_expr_inner!($($var)+))).context(concat!("getting nested ", $path))?, $path) $($tt)*)77 nix_go!(@o($crate::__macro_support::block_in_place(|| $o.call($crate::nix_expr_inner!($($var)+))).context(concat!("getting nested ", $path))?, $path) $($tt)*)
78 };78 };
79 (@o($o:expr, $path:expr)) => {$o};79 (@o($o:expr, $path:expr)) => {$o};
80 ($field:ident $($tt:tt)+) => {{80 ($field:ident $($tt:tt)+) => {{
81 use $crate::nix_go;81 use $crate::nix_go;
82 use ::anyhow::Context;82 use $crate::__macro_support::Context;
83 let out = $field.clone();83 let out = $field.clone();
84 nix_go!(@o(out, ::std::stringify!($($tt)*)) $($tt)*)84 nix_go!(@o(out, stringify!($($tt)*)) $($tt)*)
85 }}85 }}
86}86}
87#[macro_export]87#[macro_export]
88macro_rules! nix_go_json {88macro_rules! nix_go_json {
89 ($($tt:tt)*) => {{89 ($($tt:tt)*) => {{
90 tokio::task::block_in_place(|| $crate::nix_go!($($tt)*).as_json())?90 $crate::__macro_support::block_in_place(|| $crate::nix_go!($($tt)*).as_json())?
91 }};91 }};
92}92}
9393