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

difftreelog

refactor cleanup bindings

rptrmlslYaroslav Bolyukin2025-09-04parent: #521a658.patch.diff
in: trunk

12 files changed

modifiedCargo.lockdiffbeforeafterboth
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -729,22 +729,6 @@
 ]
 
 [[package]]
-name = "ctor"
-version = "0.5.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "67773048316103656a637612c4a62477603b777d91d9c62ff2290f9cde178fdb"
-dependencies = [
- "ctor-proc-macro",
- "dtor",
-]
-
-[[package]]
-name = "ctor-proc-macro"
-version = "0.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e2931af7e13dc045d8e9d26afccc6fa115d64e115c9c84b1166288b46f6782c2"
-
-[[package]]
 name = "ctr"
 version = "0.9.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -916,21 +900,6 @@
 ]
 
 [[package]]
-name = "dtor"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e58a0764cddb55ab28955347b45be00ade43d4d6f3ba4bf3dc354e4ec9432934"
-dependencies = [
- "dtor-proc-macro",
-]
-
-[[package]]
-name = "dtor-proc-macro"
-version = "0.0.6"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f678cf4a922c215c63e0de95eb1ff08a958a81d47e485cf9da1e27bf6305cfa5"
-
-[[package]]
 name = "ed25519"
 version = "2.2.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1973,17 +1942,12 @@
 version = "0.1.0"
 dependencies = [
  "anyhow",
- "better-command",
  "bindgen",
- "ctor",
  "cxx",
  "cxx-build",
- "futures",
  "itertools 0.14.0",
  "nixlike",
  "pkg-config",
- "r2d2",
- "regex",
  "serde",
  "serde_json",
  "test-log",
@@ -1992,7 +1956,6 @@
  "tokio-util",
  "tracing",
  "tracing-indicatif",
- "unindent",
 ]
 
 [[package]]
@@ -2454,17 +2417,6 @@
 version = "5.3.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
-
-[[package]]
-name = "r2d2"
-version = "0.8.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "51de85fb3fb6524929c8a2eb85e6b6d363de4e8c48f9e2c2eac4944abc181c93"
-dependencies = [
- "log",
- "parking_lot",
- "scheduled-thread-pool",
-]
 
 [[package]]
 name = "rand"
@@ -2829,15 +2781,6 @@
 ]
 
 [[package]]
-name = "scheduled-thread-pool"
-version = "0.2.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3cbc66816425a074528352f5789333ecff06ca41b36b0b0efdfbb29edc391a19"
-dependencies = [
- "parking_lot",
-]
-
-[[package]]
 name = "scopeguard"
 version = "1.2.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3673,12 +3616,6 @@
 version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "39ec24b3121d976906ece63c9daad25b85969647682eee313cb5779fdd69e14e"
-
-[[package]]
-name = "unindent"
-version = "0.2.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
 
 [[package]]
 name = "unit-prefix"
modifiedcmds/fleet/Cargo.tomldiffbeforeafterboth
--- a/cmds/fleet/Cargo.toml
+++ b/cmds/fleet/Cargo.toml
@@ -55,4 +55,5 @@
 	"dep:indicatif",
 	"dep:human-repr",
 	"better-command/indicatif",
+	"nix-eval/indicatif",
 ]
modifiedcmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/build_systems.rs
+++ b/cmds/fleet/src/cmds/build_systems.rs
@@ -28,18 +28,12 @@
 	build_attr: String,
 }
 
-async fn build_task(
-	config: Config,
-	hostname: String,
-	build_attr: &str,
-	// batch: Option<NixBuildBatch>,
-) -> Result<PathBuf> {
+async fn build_task(config: Config, hostname: String, build_attr: &str) -> Result<PathBuf> {
 	info!("building");
 	let host = config.host(&hostname).await?;
 	// let action = Action::from(self.subcommand.clone());
 	let nixos = host.nixos_config().await?;
 	let drv = nix_go!(nixos.system.build[{ build_attr }]);
-	// let outputs = drv.build_maybe_batch(batch).await?;
 	let out_output = drv.build("out").await?;
 
 	// We already have system profiles for backups.
@@ -66,17 +60,11 @@
 		let hosts = opts.filter_skipped(config.list_hosts().await?).await?;
 		let set = LocalSet::new();
 		let build_attr = self.build_attr.clone();
-		// let batch = (hosts.len() > 1).then(|| {
-		// 	config
-		// 		.nix_session
-		// 		.new_build_batch("build-hosts".to_string())
-		// });
 		for host in hosts {
 			let config = config.clone();
 			let span = info_span!("build", host = field::display(&host.name));
 			let hostname = host.name;
 			let build_attr = build_attr.clone();
-			// let batch = batch.clone();
 			set.spawn_local(
 				(async move {
 					let built = match build_task(config, hostname.clone(), &build_attr).await {
@@ -107,11 +95,6 @@
 	pub async fn run(self, config: &Config, opts: &FleetOpts) -> Result<()> {
 		let hosts = opts.filter_skipped(config.list_hosts().await?).await?;
 		let set = LocalSet::new();
-		// let batch = (hosts.len() > 1).then(|| {
-		// 	config
-		// 		.nix_session
-		// 		.new_build_batch("deploy-hosts".to_string())
-		// });
 		for host in hosts.into_iter() {
 			let config = config.clone();
 			let span = info_span!("deploy", host = field::display(&host.name));
modifiedcmds/fleet/src/cmds/secrets/mod.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/secrets/mod.rs
+++ b/cmds/fleet/src/cmds/secrets/mod.rs
@@ -169,7 +169,6 @@
 	expected_owners: &[String],
 	expected_generation_data: serde_json::Value,
 	prefer_identities: &[String],
-	// batch: Option<NixBuildBatch>,
 ) -> Result<FleetSharedSecret> {
 	let original_set = secret.owners.clone();
 
@@ -207,12 +206,10 @@
 			field,
 			expected_owners.to_vec(),
 			expected_generation_data,
-			// batch,
 		)
 		.await?;
 		Ok(generated)
 	} else {
-		// drop(batch);
 		let identity_holder = if !prefer_identities.is_empty() {
 			prefer_identities
 				.iter()
@@ -264,7 +261,6 @@
 	default_generator: Value,
 	expected_owners: &[String],
 	expected_generation_data: serde_json::Value,
-	// batch: Option<NixBuildBatch>,
 ) -> Result<FleetSecret> {
 	let generator = nix_go!(secret.generator);
 	let on: Option<String> = nix_go_json!(default_generator.impureOn);
@@ -292,7 +288,6 @@
 
 	let generator = nix_go!(call_package(generator)(Obj {}));
 
-	// let generator = generator.build_maybe_batch(batch).await?;
 	let generator = generator.build("out").await?;
 	let generator = host.remote_derivation(&generator).await?;
 
@@ -347,12 +342,11 @@
 	secret: Value,
 	expected_owners: &[String],
 	expected_generation_data: serde_json::Value,
-	// batch: Option<NixBuildBatch>,
 ) -> Result<FleetSecret> {
 	let generator = nix_go!(secret.generator);
 	// Can't properly check on nix module system level
 	{
-		let gen_ty = generator.type_of()?;
+		let gen_ty = generator.type_of();
 		if matches!(gen_ty, NixType::Null) {
 			bail!("secret has no generator defined, can't automatically generate it.");
 		}
@@ -394,7 +388,6 @@
 				default_generator,
 				expected_owners,
 				expected_generation_data,
-				// batch,
 			)
 			.await
 		}
@@ -416,7 +409,6 @@
 	secret: Value,
 	expected_owners: Vec<String>,
 	expected_generation_data: serde_json::Value,
-	// batch: Option<NixBuildBatch>,
 ) -> Result<FleetSharedSecret> {
 	// let owners: Vec<String> = nix_go_json!(secret.expectedOwners);
 	Ok(FleetSharedSecret {
@@ -426,7 +418,6 @@
 			secret,
 			&expected_owners,
 			expected_generation_data,
-			// batch,
 		)
 		.await?,
 		owners: expected_owners,
@@ -747,7 +738,6 @@
 				let stored_shared_set = config.list_shared().into_iter().collect::<HashSet<_>>();
 				{
 					// Generate missing shared
-					// let shared_batch = None;
 					let _span = info_span!("shared").entered();
 					let expected_shared_set = config
 						.list_configured_shared()
@@ -772,7 +762,6 @@
 							secret,
 							expected_owners,
 							expected_generation_data,
-							// shared_batch.clone(),
 						)
 						.in_current_span()
 						.await?;
@@ -780,7 +769,6 @@
 					}
 				}
 				if !skip_hosts {
-					// let hosts_batch = None;
 					for host in config.list_hosts().await? {
 						if opts.should_skip(&host).await? {
 							continue;
@@ -808,7 +796,6 @@
 								secret,
 								slice::from_ref(&host.name),
 								expected_generation_data,
-								// hosts_batch.clone(),
 							)
 							.in_current_span()
 							.await
@@ -834,7 +821,6 @@
 									secret,
 									slice::from_ref(&host.name),
 									expected_generation_data,
-									// hosts_batch.clone(),
 								)
 								.in_current_span()
 								.await
modifiedcmds/fleet/src/cmds/tf.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/tf.rs
+++ b/cmds/fleet/src/cmds/tf.rs
@@ -1,8 +1,4 @@
-use std::{
-	collections::{BTreeMap, HashMap},
-	ffi::OsString,
-	path::PathBuf,
-};
+use std::{collections::BTreeMap, ffi::OsString, path::PathBuf};
 
 use anyhow::{Context, Result};
 use clap::Parser;
modifiedcrates/nix-eval/Cargo.tomldiffbeforeafterboth
--- a/crates/nix-eval/Cargo.toml
+++ b/crates/nix-eval/Cargo.toml
@@ -7,26 +7,23 @@
 
 [dependencies]
 anyhow.workspace = true
-better-command.workspace = true
 nixlike.workspace = true
 serde = { workspace = true, features = ["derive"] }
 serde_json.workspace = true
 thiserror.workspace = true
-tokio = { workspace = true, features = ["io-util", "process"] }
+tokio = { workspace = true }
 tokio-util.workspace = true
 tracing.workspace = true
 
 cxx = "1.0.168"
-futures = "0.3.31"
 itertools = "0.14.0"
-r2d2 = "0.8.10"
-regex = "1.11.1"
 test-log = { version = "0.2.18", features = ["trace"] }
-unindent = "0.2.4"
-tracing-indicatif = "0.3.13"
-ctor = "0.5.0"
+tracing-indicatif = { version = "0.3.13", optional = true }
 
 [build-dependencies]
 bindgen = "0.72.0"
 cxx-build = "1.0.168"
 pkg-config = "0.3.30"
+
+[features]
+indicatif = ["dep:tracing-indicatif"]
modifiedcrates/nix-eval/src/lib.rsdiffbeforeafterboth
--- a/crates/nix-eval/src/lib.rs
+++ b/crates/nix-eval/src/lib.rs
@@ -1,8 +1,3 @@
-//! This whole library should be replaced with either binding to nix libexpr,
-//! or with tvix (once it is able to build NixOS).
-//!
-//! Current api is awful, little effort was put into this implementation.
-
 use std::borrow::Cow;
 use std::cell::RefCell;
 use std::ffi::{CStr, CString, c_char, c_int, c_uint, c_void};
@@ -11,7 +6,7 @@
 use std::sync::LazyLock;
 use std::{collections::HashMap, path::PathBuf};
 
-use anyhow::{Context, bail};
+use anyhow::{Context, anyhow, bail};
 use serde::Serialize;
 use serde::de::DeserializeOwned;
 
@@ -27,17 +22,21 @@
 	flake_reference_parse_flags_new, flake_reference_parse_flags_set_base_directory,
 	flake_settings, flake_settings_free, flake_settings_new, init_bool, init_int, init_string,
 	locked_flake_free, locked_flake_get_output_attrs, set_err_msg, setting_set, state_free,
-	value_decref, value_force, value_incref,
+	value_decref, value_incref,
 };
 
-mod value;
 // Contains macros helpers
 pub mod logging;
 #[doc(hidden)]
 pub mod macros;
 pub mod util;
 
-#[allow(non_upper_case_globals, non_camel_case_types, non_snake_case)]
+#[allow(
+	non_upper_case_globals,
+	non_camel_case_types,
+	non_snake_case,
+	dead_code
+)]
 mod nix_raw {
 	include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
 }
@@ -88,6 +87,11 @@
 	}
 }
 
+enum FunctorKind {
+	Function,
+	Functor,
+}
+
 #[derive(Debug)]
 #[repr(i32)]
 enum NixErrorKind {
@@ -130,9 +134,9 @@
 	unsafe { nix_raw::GC_unregister_my_thread() };
 }
 
-struct ThreadRegisterGuard {}
+pub struct ThreadRegisterGuard {}
 impl ThreadRegisterGuard {
-	fn new() -> Self {
+	pub fn new() -> Self {
 		gc_register_my_thread();
 		Self {}
 	}
@@ -143,12 +147,12 @@
 	}
 }
 
-struct NixContext(*mut c_context);
+pub struct NixContext(*mut c_context);
 impl NixContext {
-	fn set_err(&mut self, err: NixErrorKind, msg: &CStr) {
+	pub fn set_err(&mut self, err: NixErrorKind, msg: &CStr) {
 		unsafe { set_err_msg(self.0, err as c_int, msg.as_ptr()) };
 	}
-	fn new() -> Self {
+	pub fn new() -> Self {
 		let ctx = unsafe { c_context_create() };
 		Self(ctx)
 	}
@@ -174,12 +178,6 @@
 		// but it looks ugly
 		let str = unsafe { nix_raw::err_msg(null_mut(), self.0, null_mut()) };
 		Some(unsafe { CStr::from_ptr(str) }.to_string_lossy())
-
-		// TODO: There is also nix_err_info_msg, but I don't understand when it should be used
-		// Some(match self.error_kind()? {
-		// 	NixErrorKind::Generic => {
-		// 	}
-		// })
 	}
 	fn clean_err(&mut self) {
 		unsafe {
@@ -210,6 +208,8 @@
 	}
 }
 struct GlobalState {
+	// Store should be valid as long as EvalState is valid
+	#[allow(dead_code)]
 	store: Store,
 	state: EvalState,
 }
@@ -269,7 +269,7 @@
 	v
 }
 
-fn set_setting(s: &CStr, v: &CStr) -> Result<()> {
+pub fn set_setting(s: &CStr, v: &CStr) -> Result<()> {
 	with_default_context(|c, _| unsafe { setting_set(c, s.as_ptr(), v.as_ptr()) }).map(|_| ())
 }
 
@@ -289,6 +289,13 @@
 }
 unsafe impl Send for FetchSettings {}
 unsafe impl Sync for FetchSettings {}
+
+impl Default for FetchSettings {
+	fn default() -> Self {
+		Self::new()
+	}
+}
+
 impl Drop for FetchSettings {
 	fn drop(&mut self) {
 		unsafe { fetchers_settings_free(self.0) };
@@ -310,13 +317,13 @@
 	}
 }
 
-struct FlakeReferenceParseFlags(*mut flake_reference_parse_flags);
+pub struct FlakeReferenceParseFlags(*mut flake_reference_parse_flags);
 impl FlakeReferenceParseFlags {
-	fn new(settings: &mut FlakeSettings) -> Result<Self> {
+	pub fn new(settings: &mut FlakeSettings) -> Result<Self> {
 		with_default_context(|c, _| unsafe { flake_reference_parse_flags_new(c, settings.0) })
 			.map(Self)
 	}
-	fn set_base_dir(&mut self, dir: &str) -> Result<()> {
+	pub fn set_base_dir(&mut self, dir: &str) -> Result<()> {
 		with_default_context(|c, _| {
 			unsafe {
 				flake_reference_parse_flags_set_base_directory(
@@ -361,19 +368,9 @@
 unsafe impl Sync for Store {}
 
 struct EvalState(*mut nix_raw::EvalState);
-impl EvalState {
-	// TODO: store ownership
-	fn new_raw(store: *mut nix_raw::Store) -> Result<Self> {
-		let builder =
-			with_default_context(|c, _| unsafe { nix_raw::eval_state_builder_new(c, store) })?;
-
-		with_default_context(|c, _| unsafe { eval_state_build(c, builder) }).map(Self)
-
-		// with_default_context(|c| state_create(c))
-	}
-}
 unsafe impl Send for EvalState {}
 unsafe impl Sync for EvalState {}
+
 impl Drop for EvalState {
 	fn drop(&mut self) {
 		unsafe {
@@ -386,9 +383,7 @@
 impl FlakeReference {
 	pub fn new(s: &str, fetch: &FetchSettings) -> Result<(Self, String)> {
 		let mut flake_settings = FlakeSettings::new()?;
-		let mut parse_flags = FlakeReferenceParseFlags::new(&mut flake_settings)?;
-
-		// parse_flags.set_base_dir("/home/lach/build/fleet")?;
+		let parse_flags = FlakeReferenceParseFlags::new(&mut flake_settings)?;
 
 		let mut out = null_mut();
 		let mut fragment = String::new();
@@ -461,16 +456,16 @@
 }
 
 impl RealisedString {
-	fn as_str(&self) -> &str {
+	pub fn as_str(&self) -> &str {
 		let len = unsafe { nix_raw::realised_string_get_buffer_size(self.0) };
 		let data: *const u8 = unsafe { nix_raw::realised_string_get_buffer_start(self.0) }.cast();
 		let data = unsafe { std::slice::from_raw_parts(data, len) };
 		std::str::from_utf8(data).expect("non-utf8 strings not supported")
 	}
-	fn path_count(&self) -> usize {
+	pub fn path_count(&self) -> usize {
 		unsafe { nix_raw::realised_string_get_store_path_count(self.0) }
 	}
-	fn path(&self, i: usize) -> String {
+	pub fn path(&self, i: usize) -> String {
 		assert!(i < self.path_count());
 		let path = unsafe { nix_raw::realised_string_get_store_path(self.0, i) };
 		let mut err_out = String::new();
@@ -482,8 +477,7 @@
 unsafe impl Send for RealisedString {}
 impl Drop for RealisedString {
 	fn drop(&mut self) {
-		with_default_context(|c, _| unsafe { nix_raw::realised_string_free(self.0) })
-			.expect("string free should not fail")
+		unsafe { nix_raw::realised_string_free(self.0) }
 	}
 }
 
@@ -541,46 +535,53 @@
 }
 
 impl Value {
-	pub fn new_attrs(v: HashMap<&str, Value>) -> Result<Self> {
-		let out = Self::new_uninit()?;
+	pub fn new_attrs(v: HashMap<&str, Value>) -> Self {
+		let out = Self::new_uninit();
 		let mut b = AttrsBuilder::new(v.len());
 		for (k, v) in v {
 			b.insert(&k, v);
 		}
-		with_default_context(|c, _| unsafe { nix_raw::make_attrs(c, out.0, b.0) })?;
-		Ok(out)
+		with_default_context(|c, _| unsafe { nix_raw::make_attrs(c, out.0, b.0) })
+			.expect("attrs initialization should not fail");
+		out
 	}
-	fn new_list<T: Into<Self>>(v: Vec<T>) -> Result<Self> {
+	fn new_list<T: Into<Self>>(v: Vec<T>) -> Self {
 		todo!()
 	}
-	fn new_uninit() -> Result<Self> {
-		let out = with_default_context(|c, es| unsafe { alloc_value(c, es) })?;
-		Ok(Self(out))
+	fn new_uninit() -> Self {
+		let out = with_default_context(|c, es| unsafe { alloc_value(c, es) })
+			.expect("value allocation should not fail");
+		Self(out)
 	}
-	fn new_str(v: &str) -> Result<Self> {
+	pub fn new_str(v: &str) -> Self {
 		let s = CString::new(v).expect("string should not contain NULs");
-		let uninit = Self::new_uninit()?;
+		let out = Self::new_uninit();
 		// String is copied, `s` is free to be dropped
-		with_default_context(|c, _| unsafe { init_string(c, uninit.0, s.as_ptr()) })?;
-		Ok(uninit)
+		with_default_context(|c, _| unsafe { init_string(c, out.0, s.as_ptr()) })
+			.expect("string initialization should not fail");
+		out
 	}
-	fn new_int(i: i64) -> Result<Self> {
-		let uninit = Self::new_uninit()?;
-		with_default_context(|c, _| unsafe { init_int(c, uninit.0, i) })?;
-		Ok(uninit)
+	pub fn new_int(i: i64) -> Self {
+		let out = Self::new_uninit();
+		with_default_context(|c, _| unsafe { init_int(c, out.0, i) })
+			.expect("int initialization should not fail");
+		out
 	}
-	fn new_bool(v: bool) -> Result<Self> {
-		let uninit = Self::new_uninit()?;
-		with_default_context(|c, _| unsafe { init_bool(c, uninit.0, v) })?;
-		Ok(uninit)
+	pub fn new_bool(v: bool) -> Self {
+		let out = Self::new_uninit();
+		with_default_context(|c, _| unsafe { init_bool(c, out.0, v) })
+			.expect("bool initialization should not fail");
+		out
 	}
-	fn force(&mut self, st: &mut EvalState) -> Result<()> {
-		with_default_context(|c, _| unsafe { value_force(c, st.0, self.0) })?;
-		Ok(())
-	}
-	pub fn type_of(&self) -> Result<NixType> {
-		let ty = with_default_context(|c, _| unsafe { nix_raw::get_type(c, self.0) })?;
-		Ok(NixType::from_int(ty))
+	// TODO: As far as I can see, there is no way to get Thunks from nix public C api, so this function is useless
+	// fn force(&mut self, st: &mut EvalState) -> Result<()> {
+	// 	with_default_context(|c, _| unsafe { value_force(c, st.0, self.0) })?;
+	// 	Ok(())
+	// }
+	pub fn type_of(&self) -> NixType {
+		let ty = with_default_context(|c, _| unsafe { nix_raw::get_type(c, self.0) })
+			.expect("get_type should not fail");
+		NixType::from_int(ty)
 	}
 	pub fn to_string(&self) -> Result<String> {
 		Ok(self.to_realised_string()?.as_str().to_owned())
@@ -608,7 +609,7 @@
 	// 	nix_raw::real
 	// }
 	pub fn list_fields(&self) -> Result<Vec<String>> {
-		if !matches!(self.type_of()?, NixType::Attrs) {
+		if !matches!(self.type_of(), NixType::Attrs) {
 			bail!("invalid type: expected attrs");
 		}
 
@@ -625,7 +626,7 @@
 		Ok(out)
 	}
 	pub fn get_elem(&self, v: usize) -> Result<Self> {
-		if !matches!(self.type_of()?, NixType::List) {
+		if !matches!(self.type_of(), NixType::List) {
 			bail!("invalid type: expected list");
 		}
 		let len =
@@ -659,10 +660,10 @@
 		for f in b_fields.iter() {
 			out.insert(f.as_str(), other.get_field(f)?);
 		}
-		Self::new_attrs(out)
+		Ok(Self::new_attrs(out))
 	}
 	pub fn get_field(&self, name: impl AsFieldName) -> Result<Self> {
-		if !matches!(self.type_of()?, NixType::Attrs) {
+		if !matches!(self.type_of(), NixType::Attrs) {
 			bail!("invalid type: expected attrs");
 		}
 
@@ -675,19 +676,33 @@
 		.with_context(|| format!("getting field {:?}", name.to_field_name()))
 	}
 	pub fn call(&self, v: Value) -> Result<Self> {
-		if !matches!(self.type_of()?, NixType::Function) {
-			// TODO: Functors
-			bail!("invalid type: expected function");
-		}
+		let kind = self
+			.functor_kind()
+			.ok_or_else(|| anyhow!("can only call function or functor"))?;
+
+		let function = match kind {
+			FunctorKind::Function => self.clone(),
+			FunctorKind::Functor => {
+				let f = self.get_field("__functor")?;
+				assert_eq!(
+					f.type_of(),
+					NixType::Function,
+					"invalid functor encountered"
+				);
+				f
+			}
+		};
 
-		let out = Value::new_uninit()?;
-		with_default_context(|c, es| unsafe { nix_raw::value_call(c, es, self.0, v.0, out.0) })?;
+		let out = Value::new_uninit();
+		with_default_context(|c, es| unsafe {
+			nix_raw::value_call(c, es, function.0, v.0, out.0)
+		})?;
 
 		Ok(out)
 	}
 	pub fn eval(v: &str) -> Result<Self> {
 		let s = CString::new(v).expect("expression shouldn't have internal NULs");
-		let out = Self::new_uninit()?;
+		let out = Self::new_uninit();
 		with_default_context(|c, es| unsafe {
 			expr_eval_from_string(c, es, s.as_ptr(), c"/homeless-shelter".as_ptr(), out.0)
 		})?;
@@ -723,13 +738,13 @@
 	}
 
 	// Convert to string/evaluate derivations/etc
-	fn to_string_weak(&self) -> Result<String> {
-		// TODO
-		self.to_string()
-	}
+	// fn to_string_weak(&self) -> Result<String> {
+	// 	// TODO: For now, it works exactly like to_string, see the comment for fn force()
+	// 	self.to_string()
+	// }
 
 	fn is_derivation(&self) -> bool {
-		if !matches!(self.type_of(), Ok(NixType::Attrs)) {
+		if !matches!(self.type_of(), NixType::Attrs) {
 			return false;
 		}
 		let Some(ty) = self.get_field("type").ok() else {
@@ -737,21 +752,34 @@
 		};
 		matches!(ty.to_string().as_deref(), Ok("derivation"))
 	}
+	fn functor_kind(&self) -> Option<FunctorKind> {
+		match self.type_of() {
+			NixType::Attrs => self
+				.has_field("__functor")
+				.expect("has_field shouldn't fail for attrs")
+				.then_some(FunctorKind::Functor),
+			NixType::Function => Some(FunctorKind::Function),
+			_ => None,
+		}
+	}
+	pub fn is_function(&self) -> bool {
+		self.functor_kind().is_some()
+	}
 }
 
 impl From<String> for Value {
 	fn from(value: String) -> Self {
-		Value::new_str(&value).expect("todo: TryFrom")
+		Value::new_str(&value)
 	}
 }
 impl From<bool> for Value {
 	fn from(value: bool) -> Self {
-		Value::new_bool(value).expect("todo: TryFrom")
+		Value::new_bool(value)
 	}
 }
 impl From<&str> for Value {
 	fn from(value: &str) -> Self {
-		Value::new_str(&value).expect("todo: TryFrom")
+		Value::new_str(value)
 	}
 }
 impl<T> From<Vec<T>> for Value
@@ -759,7 +787,7 @@
 	T: Into<Value>,
 {
 	fn from(value: Vec<T>) -> Self {
-		Value::new_list(value).expect("todo: TryFrom")
+		Value::new_list(value)
 	}
 }
 
@@ -793,102 +821,24 @@
 
 #[test_log::test]
 fn test_native() -> Result<()> {
+	init_libraries();
+
 	let mut fetch_settings = FetchSettings::new();
 	fetch_settings.set(c"warn-dirty", c"false");
-	//
 
-	let (mut r, _) = FlakeReference::new("/home/lach/build/fleet", &fetch_settings)?;
+	let manifest = format!("{}/../../", env!("CARGO_MANIFEST_DIR"));
+	let (mut r, _) = FlakeReference::new(&manifest, &fetch_settings)?;
 	let locked = r.lock(&fetch_settings)?;
 	let attrs = locked.get_attrs(&mut FlakeSettings::new()?)?;
 
 	let builtins = Value::eval("builtins")?;
-	dbg!(builtins.type_of()?);
+	assert_eq!(builtins.type_of(), NixType::Attrs);
 
-	dbg!(attrs.type_of()?);
-	dbg!(attrs.list_fields()?);
-	dbg!(
-		attrs
-			.get_field("packages")?
-			.get_field("x86_64-linux")?
-			.get_field("fleet")?
-			.get_field("outPath")?
-			.to_string()
-	);
+	assert_eq!(attrs.type_of(), NixType::Attrs);
+	let test_data = nix_go!(attrs.testData);
 
+	let test_string: String = nix_go_json!(test_data.testString);
+	assert_eq!(test_string, "hello");
+
 	Ok(())
 }
-
-// struct NixBuildTask(Value, oneshot::Sender<Result<HashMap<String, PathBuf>>>);
-//
-// #[derive(Clone)]
-// pub struct NixBuildBatch {
-// 	tx: mpsc::UnboundedSender<NixBuildTask>,
-// }
-//
-// #[instrument(skip(values))]
-// async fn build_multiple(name: String, values: Vec<Value>) -> Result<()> {
-// 	let builtins = Value::eval("builtins")?;
-// 	let drv = nix_go!(builtins.derivation(Obj {
-// 		// FIXME: pass system from localSystem or fleet args
-// 		// system,
-// 		name,
-// 		builder: "/bin/sh",
-// 		// we want nothing from this derivation, it is only used to perform multiple builds at once.
-// 		args: vec!["-c", "echo > $out"],
-// 		preferLocalBuild: true,
-// 		allowSubstitutes: false,
-// 		buildInputs: values,
-// 	}));
-// 	drv.build()?;
-// 	Ok(())
-// }
-//
-// impl NixBuildBatch {
-// 	fn new(name: String) -> Self {
-// 		let (tx, mut rx) = mpsc::unbounded_channel::<NixBuildTask>();
-//
-// 		tokio::task::spawn(async move {
-// 			let mut deps = vec![];
-// 			let mut build_data = vec![];
-// 			while let Some(task) = rx.recv().await {
-// 				build_data.push(task.0.clone());
-// 				deps.push(task);
-// 			}
-// 			if deps.is_empty() {
-// 				return;
-// 			}
-// 			match build_multiple(name, build_data).await {
-// 				Ok(_) => {
-// 					for NixBuildTask(v, o) in deps {
-// 						let _ = o.send(v.build());
-// 					}
-// 				}
-// 				Err(e) => {
-// 					for NixBuildTask(v, o) in deps {
-// 						let s = v.to_string_weak();
-// 						let s = match s {
-// 							Ok(s) => s,
-// 							Err(e) => {
-// 								let _ = o.send(Err(e));
-// 								continue;
-// 							}
-// 						};
-// 						if PathBuf::from(s).exists() {
-// 							let _ = o.send(v.build());
-// 						} else {
-// 							let _ = o.send(Err(e.clone()));
-// 						}
-// 					}
-// 				}
-// 			};
-// 		});
-// 		Self { tx }
-// 	}
-// 	pub async fn submit(self, task: Value) -> Result<HashMap<String, PathBuf>> {
-// 		let Self { tx: task_tx } = self;
-// 		let (tx, rx) = oneshot::channel();
-// 		let _ = task_tx.send(NixBuildTask(task, tx));
-// 		drop(task_tx);
-// 		rx.await.expect("shoudn't be cancelled here")
-// 	}
-// }
modifiedcrates/nix-eval/src/logging.rsdiffbeforeafterboth
before · crates/nix-eval/src/logging.rs
1use std::collections::HashMap;2use std::fmt::Arguments;3use std::sync::{LazyLock, Mutex};45use tracing::{6	Level, Metadata, Span, debug, debug_span, error, error_span, event, info, info_span, trace,7	trace_span, warn, warn_span,8};9use tracing_indicatif::span_ext::IndicatifSpanExt as _;1011#[derive(Debug)]12enum ActivityType {13	Unknown = 0,14	CopyPath = 100,15	FileTransfer = 101,16	Realise = 102,17	CopyPaths = 103,18	Builds = 104,19	Build = 105,20	OptimiseStore = 106,21	VerifyPaths = 107,22	Substitute = 108,23	QueryPathInfo = 109,24	PostBuildHook = 110,25	BuildWaiting = 111,26	FetchTree = 112,27}2829fn strip_prefix_suffix<'s, 'p>(a: &'s str, pref: &'p str, suff: &'p str) -> Option<&'s str> {30	a.strip_prefix(pref)?.strip_suffix(suff)31}3233fn parse_path(path: &str) -> &str {34	let path = strip_prefix_suffix(path, "\x1b[35;1m", "\x1b[0m").unwrap_or(path);35	path36}3738fn parse_drv(drv: &str) -> &str {39	let drv = parse_path(drv);40	if let Some(pkg) = drv.strip_prefix("/nix/store/") {41		let mut it = pkg.splitn(2, '-');42		it.next();43		if let Some(pkg) = it.next() {44			return pkg;45		}46	}47	drv48}49fn parse_host(host: &str) -> &str {50	if host.is_empty() || host == "local" {51		return "local";52	}53	// https/ssh is the default54	host.strip_prefix("https://").unwrap_or(host)55}5657impl ActivityType {58	fn name(&self) -> &'static str {59		match self {60			ActivityType::Unknown => "nix",61			ActivityType::CopyPath => "nix::copy-path",62			ActivityType::FileTransfer => "nix::file-transfer",63			ActivityType::Realise => "nix::realise",64			ActivityType::CopyPaths => "nix::copy-paths",65			ActivityType::Builds => "nix::builds",66			ActivityType::Build => "nix::build",67			ActivityType::OptimiseStore => "nix::optimise-store",68			ActivityType::VerifyPaths => "nix::verify-paths",69			ActivityType::Substitute => "nix::substitute",70			ActivityType::QueryPathInfo => "nix::query-path-info",71			ActivityType::PostBuildHook => "nix::post-build-hook",72			ActivityType::BuildWaiting => "nix::build-waiting",73			ActivityType::FetchTree => "nix::fetch-tree",74		}75	}76	fn format(77		&self,78		values: &[FieldValue],79		s: &str,80		into: impl FnOnce(Arguments<'_>) -> Span,81	) -> Span {82		use FieldValue::*;83		match (self, values) {84			(ActivityType::QueryPathInfo, [Str(drv), Str(host)]) => {85				let drv = parse_drv(drv);86				let host = parse_host(host);87				debug_span!(target: "nix::query-path-info", "querying", drv, host)88			}89			(ActivityType::Substitute, [Str(drv), Str(host)]) => {90				let drv = parse_drv(drv);91				let host = parse_host(host);92				debug_span!(target: "nix::substitute", "substituting", drv, host)93			}94			(ActivityType::CopyPath, [Str(drv), Str(from), Str(to)]) => {95				let drv = parse_drv(drv);96				let from = parse_host(from);97				let to = parse_host(to);98				debug_span!(target: "nix::copy-path", "copying", drv, from, to)99			}100			(ActivityType::Build, [Str(drv), Str(host), Int(_), Int(_)]) => {101				let drv = parse_drv(drv);102				let host = parse_host(host);103				info_span!(target: "nix::build", "building", drv, host)104			}105			(ActivityType::FileTransfer, [Str(file)]) => {106				info_span!(target: "nix::file-transfer", "downloading", file)107			}108			(ActivityType::Realise, []) => {109				debug_span!(target: "nix::realise", "realising")110			}111			(ActivityType::CopyPaths, []) => {112				debug_span!(target: "nix::copy-paths", "copying paths")113			}114			(ActivityType::Unknown, [])115				if s.starts_with("copying \"") && s.ends_with("\" to the store") =>116			{117				let tree = s118					.trim_start_matches("copying \"")119					.trim_end_matches("\" to the store");120				debug_span!(target: "nix::trees", "copying", tree)121			}122			(ActivityType::Unknown, [])123				if s.starts_with("copying '") && s.ends_with("' to the store") =>124			{125				let tree = s126					.trim_start_matches("copying '")127					.trim_end_matches("' to the store");128				debug_span!(target: "nix::trees", "copying", tree)129			}130			(ActivityType::Unknown, []) if s.starts_with("hashing '") && s.ends_with("'") => {131				let tree = s.trim_start_matches("hashing '").trim_end_matches("'");132				debug_span!(target: "nix::trees", "hashing", tree)133			}134			(ActivityType::Unknown, []) if s.starts_with("connecting to '") && s.ends_with("'") => {135				let host = s136					.trim_start_matches("connecting to '")137					.trim_end_matches("'");138				debug_span!(target: "nix::remote", "connecting", host)139			}140			(ActivityType::Unknown, [])141				if s.starts_with("copying outputs from '") && s.ends_with("'") =>142			{143				let host = s144					.trim_start_matches("copying outputs from '")145					.trim_end_matches("'");146				debug_span!(target: "nix::remote", "copying outputs", host)147			}148			(ActivityType::Unknown, [])149				if s.starts_with("copying dependencies to '") && s.ends_with("'") =>150			{151				let host = s152					.trim_start_matches("copying dependencies to '")153					.trim_end_matches("'");154				debug_span!(target: "nix::remote", "copying dependencies", host)155			}156			(ActivityType::Unknown, [])157				if s.starts_with("waiting for the upload lock to '") && s.ends_with("'") =>158			{159				let host = s160					.trim_start_matches("waiting for the upload lock to '")161					.trim_end_matches("'");162				debug_span!(target: "nix::remote", "waiting for upload lock", host)163			}164			(ActivityType::BuildWaiting, [])165				if s.starts_with("waiting for a machine to build '") && s.ends_with("'") =>166			{167				let drv = parse_drv(168					s.trim_start_matches("waiting for a machine to build '")169						.trim_end_matches("'"),170				);171				debug_span!(target: "nix::build-waiting", "waiting for available builder", drv)172			}173			(ActivityType::Unknown, []) if s == "querying info about missing paths" => {174				debug_span!(target: "nix::remote", "querying")175			}176			_ => into(format_args!("{}({values:?})", self.name())),177		}178	}179	fn from_int(v: u32) -> Self {180		match v {181			0 => Self::Unknown,182			100 => Self::CopyPath,183			101 => Self::FileTransfer,184			102 => Self::Realise,185			103 => Self::CopyPaths,186			104 => Self::Builds,187			105 => Self::Build,188			106 => Self::OptimiseStore,189			107 => Self::VerifyPaths,190			108 => Self::Substitute,191			109 => Self::QueryPathInfo,192			110 => Self::PostBuildHook,193			111 => Self::BuildWaiting,194			112 => Self::FetchTree,195			_ => {196				warn!("unknown nix action: {v}");197				Self::Unknown198			}199		}200	}201}202203#[derive(Debug)]204enum ResultType {205	FileLinked = 100,206	BuildLogLine = 101,207	UntrustedPath = 102,208	CorruptedPath = 103,209	SetPhase = 104,210	Progress = 105,211	SetExpected = 106,212	PostBuildLogLine = 107,213	FetchStatus = 108,214215	Unknown = 999,216}217impl ResultType {218	fn from_int(v: u32) -> Self {219		match v {220			100 => Self::FileLinked,221			101 => Self::BuildLogLine,222			102 => Self::UntrustedPath,223			103 => Self::CorruptedPath,224			104 => Self::SetPhase,225			105 => Self::Progress,226			106 => Self::SetExpected,227			107 => Self::PostBuildLogLine,228			108 => Self::FetchStatus,229230			_ => {231				warn!("unknown nix result: {v}");232				Self::Unknown233			}234		}235	}236}237#[derive(Clone, Copy)]238enum Verbosity {239	Error,240	Warn,241	Notice,242	Info,243	Talkative,244	Chatty,245	Debug,246	Vomit,247}248impl Into<tracing::Level> for Verbosity {249	fn into(self) -> tracing::Level {250		match self {251			Verbosity::Error => Level::ERROR,252			Verbosity::Warn => Level::WARN,253			Verbosity::Notice => Level::WARN,254			Verbosity::Info => Level::INFO,255			Verbosity::Talkative => Level::DEBUG,256			Verbosity::Chatty => Level::DEBUG,257			Verbosity::Debug => Level::DEBUG,258			Verbosity::Vomit => Level::TRACE,259		}260	}261}262impl Verbosity {263	fn from_int(u: u32) -> Self {264		[265			Self::Error,266			Self::Warn,267			Self::Notice,268			Self::Info,269			Self::Talkative,270			Self::Chatty,271			Self::Debug,272			Self::Vomit,273		]274		.get(u as usize)275		.cloned()276		.unwrap_or_else(|| {277			warn!("unknown log level: {u}");278			Verbosity::Vomit279		})280	}281}282283#[derive(Hash, PartialEq, Eq, Clone, Copy)]284enum MetadataKind {285	Span,286	Event,287}288// impl MetadataKind {289// 	fn kind(&self) -> Kind {290// 		match self {291// 			MetadataKind::Span => Kind::SPAN,292// 			MetadataKind::Event => Kind::EVENT,293// 		}294// 	}295// }296297#[derive(Hash, PartialEq, Eq)]298struct ForeignMetadataInfo {299	target: &'static str,300	level: Level,301	kind: MetadataKind,302	name: &'static str,303	module: Option<&'static str>,304	file: Option<&'static str>,305	line: Option<u32>,306	names: &'static [&'static str],307}308309struct FakeCallsite;310impl tracing::callsite::Callsite for FakeCallsite {311	fn set_interest(&self, interest: tracing::subscriber::Interest) {312		unreachable!()313	}314315	fn metadata(&self) -> &Metadata<'_> {316		unreachable!()317	}318}319const FAKE_CALLSITE: FakeCallsite = FakeCallsite;320321#[cfg(false)]322#[derive(Default)]323struct ForeignSpanData {324	interned: HashSet<&'static str>,325	metadatas: HashMap<ForeignMetadataInfo, &'static Metadata<'static>>,326}327#[cfg(false)]328impl ForeignSpanData {329	fn intern(&mut self, s: &str) -> &'static str {330		if let Some(v) = self.interned.get(s) {331			return *v;332		}333		let leaked: Box<str> = s.into();334		let leaked = Box::leak(leaked);335		self.interned.insert(leaked);336		return leaked;337	}338	fn alloc_metadata<'t>(339		&'t mut self,340		target: &'static str,341		level: Level,342		kind: MetadataKind,343		name: &'static str,344		module: Option<&'static str>,345		file: Option<&'static str>,346		line: Option<u32>,347		names: &'static [&'static str],348	) -> &'static Metadata<'static> {349		let info = ForeignMetadataInfo {350			target,351			level,352			kind,353			name,354			module,355			file,356			line,357			names,358		};359		if let Some(v) = self.metadatas.get(&info) {360			return *v;361		}362		let fake = FakeCallsite;363		let metadata = Box::leak::<'static>(Box::new(Metadata::new(364			name,365			target,366			level,367			file,368			line,369			module,370			FieldSet::new(names, tracing::callsite::Identifier(&FAKE_CALLSITE)),371			kind.kind(),372		)));373374		let meta_raw = &raw const *metadata;375		let fields_raw = &raw const *metadata.fields();376377		// SAFETY: FieldSet struct should be inside of metadata struct... Which we assume here, but do not test378		// FIXME: Safety comment above might be invalidated at any time, this should actually be covered by unit test (or, better: runtime assertion... Somehow.)379		let fields_offset = unsafe { fields_raw.cast::<u8>().offset_from(meta_raw.cast()) };380		let field_set = unsafe {381			((&raw mut *metadata).cast::<()>())382				.byte_offset(fields_offset)383				.cast::<FieldSet>()384		};385		// FIXME: metadata borrow here invalidates our &mut borrow of 'static Metadata, and 'static FieldSet so this construction should be replaced with raw pointers or idk.386		// Something should be better done inside of tracing crate itself, someting like interior mutability.387		let callsite = Box::leak(Box::new(tracing::callsite::DefaultCallsite::new(metadata)));388		unsafe { *field_set = FieldSet::new(names, tracing::callsite::Identifier(callsite)) };389390		tracing::callsite::register(&*callsite);391392		self.metadatas.insert(info, metadata);393		return metadata;394	}395}396397#[cfg(false)]398static FOREIGN_SPAN_DATA: LazyLock<Mutex<ForeignSpanData>> =399	LazyLock::new(|| Mutex::new(ForeignSpanData::default()));400static NIX_SPAN_MAPPING: LazyLock<Mutex<HashMap<u64, Span>>> =401	LazyLock::new(|| Mutex::new(HashMap::new()));402403#[derive(Debug)]404enum FieldValue {405	Int(i32),406	Str(String),407}408409struct StartActivityBuilder {410	activity_id: u64,411	verbosity: Verbosity,412	typ: ActivityType,413	fields: Vec<FieldValue>,414}415impl StartActivityBuilder {416	fn add_int_field(&mut self, i: i32) {417		self.fields.push(FieldValue::Int(i));418	}419	fn add_string_field(&mut self, v: &str) {420		self.fields.push(FieldValue::Str(v.to_owned()));421	}422	fn emit(&mut self, parent: u64, s: &str) {423		let mut mapping = NIX_SPAN_MAPPING.lock().expect("not poisoned");424425		let parent = mapping.get(&parent);426427		// let meta = spans.alloc_metadata(428		// 	self.typ.name(),429		// 	self.verbosity.into(),430		// 	MetadataKind::Span,431		// 	"nix activity start",432		// 	None,433		// 	None,434		// 	None,435		// 	self.typ.fields(),436		// );437		//438		// let mut fields = meta.fields().iter();439		// let span = if let Some(parent) = parent {440		// 	let s = Span::new(441		// 		meta,442		// 		&match meta.fields().len() {443		// 			1 => meta.fields().value_set(444		// 				&<[_; 1]>::try_from([(445		// 					&fields.next().expect("has field"),446		// 					Some(&format_args!("Test") as &dyn tracing::Value),447		// 				)])448		// 				.expect("valid size"),449		// 			),450		// 			_ => unreachable!(),451		// 		},452		// 	);453		// 	s.follows_from(parent);454		// 	s455		// } else {456		// 	Span::new_root(457		// 		meta,458		// 		&match meta.fields().len() {459		// 			1 => meta.fields().value_set(460		// 				&<[_; 1]>::try_from([(461		// 					&fields.next().expect("has field"),462		// 					Some(&format_args!("Test") as &dyn tracing::Value),463		// 				)])464		// 				.expect("valid size"),465		// 			),466		// 			_ => unreachable!(),467		// 		},468		// 	)469		// };470		//471		// let id = span.id().expect("id created");472473		let span = {474			let _in_parent = parent.map(|p| p.enter());475			let level: Level = self.verbosity.into();476			if level == Level::ERROR {477				self.typ478					.format(&self.fields, s, |v| error_span!("action", v))479			} else if level == Level::WARN {480				self.typ481					.format(&self.fields, s, |v| warn_span!("action", v))482			} else if level == Level::INFO {483				self.typ484					.format(&self.fields, s, |v| info_span!("action", v))485			} else if level == Level::DEBUG {486				self.typ487					.format(&self.fields, s, |v| debug_span!("action", v))488			} else {489				self.typ490					.format(&self.fields, s, |v| trace_span!("action", v))491			}492		};493		if !s.trim().is_empty() {494			span.pb_set_message(s);495			let _e = span.enter();496			let level: Level = self.verbosity.into();497			if level == Level::ERROR {498				error!(target: "nix", "{}", s)499			} else if level == Level::WARN {500				warn!(target: "nix", "{}", s)501			} else if level == Level::INFO {502				info!(target: "nix", "{}", s)503			} else if level == Level::DEBUG {504				debug!(target: "nix", "{}", s)505			} else {506				trace!(target: "nix", "{}", s)507			}508		} else {509			span.pb_start();510		}511		mapping.insert(self.activity_id, span);512	}513	fn emit_result(&mut self, ty: u32) {514		let mut mapping = NIX_SPAN_MAPPING.lock().expect("not poisoned");515516		let Some(parent) = mapping.get(&self.activity_id) else {517			panic!("unexpected result for dead parent");518		};519520		let _in_parent = parent.enter();521		let res = ResultType::from_int(ty);522523		use FieldValue::*;524		match (&res, self.fields.as_slice()) {525			// ResultType::FileLinked => todo!(),526			(ResultType::BuildLogLine, [Str(s)]) => {527				info!("{s:?}");528			}529			// ResultType::UntrustedPath => todo!(),530			// ResultType::CorruptedPath => todo!(),531			// ResultType::SetPhase => todo!(),532			(ResultType::SetExpected, [Int(act_ty), Int(_expected)]) => {533				let _act_ty = ActivityType::from_int(*act_ty as u32);534			}535			(ResultType::SetPhase, [Str(phase)]) => {536				// parent.pb_set_message(phase);537				debug!(target: "nix::phase", phase)538			}539			(ResultType::Progress, [Int(done), Int(expected), Int(_), Int(_)]) => {540				parent.pb_set_length(*expected as u64);541				parent.pb_set_position(*done as u64);542			}543			_ => warn!("unknown progress report: {:?}({:?})", &res, &self.fields),544		}545	}546}547fn new_start_activity(activity_id: u64, lvl: u32, typ: u32) -> Box<StartActivityBuilder> {548	Box::new(StartActivityBuilder {549		activity_id,550		verbosity: Verbosity::from_int(lvl),551		typ: ActivityType::from_int(typ),552		fields: vec![],553	})554}555556fn emit_warn(v: &str) {557	warn!(target: "nix::eval", "{v}")558}559fn emit_stop(v: u64) {560	let mut mapping = NIX_SPAN_MAPPING.lock().expect("not poisoned");561	mapping.remove(&v);562}563fn emit_log(lvl: u32, v: &str) {564	let verbosity = Verbosity::from_int(lvl);565	let level: Level = verbosity.into();566	if level == Level::ERROR {567		error!(target: "nix", "{v}")568	} else if level == Level::WARN {569		warn!(target: "nix", "{v}")570	} else if level == Level::INFO {571		info!(target: "nix", "{v}")572	} else if level == Level::DEBUG {573		debug!(target: "nix", "{v}")574	} else {575		trace!(target: "nix", "{v}")576	}577}578579// fn start_activity(act: u64, lvl: u32, act_ty: u32, s: &str, parent: u32) {580// 	tracing::Span::new(meta, values)581// }582583#[cxx::bridge]584pub mod nix_logging_cxx {585	extern "Rust" {586		type StartActivityBuilder;587		fn new_start_activity(activity_id: u64, lvl: u32, typ: u32) -> Box<StartActivityBuilder>;588		fn add_int_field(&mut self, i: i32);589		fn add_string_field(&mut self, v: &str);590		fn emit(&mut self, parent: u64, s: &str);591		fn emit_result(&mut self, ty: u32);592593		fn emit_warn(v: &str);594		fn emit_stop(id: u64);595		fn emit_log(lvl: u32, v: &str);596	}597	unsafe extern "C++" {598		include!("nix-eval/src/logging.hh");599600		fn apply_tracing_logger();601	}602}
modifiedcrates/nix-eval/src/macros.rsdiffbeforeafterboth
--- a/crates/nix-eval/src/macros.rs
+++ b/crates/nix-eval/src/macros.rs
@@ -20,7 +20,7 @@
 		use $crate::{nix_expr_inner};
 		let mut out = std::collections::hash_map::HashMap::new();
 		nix_expr_inner!(@obj(out) $($tt)*);
-		Value::new_attrs(out)?
+		Value::new_attrs(out)
 	}};
 	(@field($o:ident) . $var:ident $($tt:tt)*) => {{
 		$o.index_attr(stringify!($var));
deletedcrates/nix-eval/src/value.rsdiffbeforeafterboth
--- a/crates/nix-eval/src/value.rs
+++ /dev/null
@@ -1,6 +0,0 @@
-use std::{collections::HashMap, fmt, path::PathBuf, sync::Arc};
-
-use better_command::NixHandler;
-use serde::{Serialize, de::DeserializeOwned};
-
-use crate::{Result, Value, nix_go};
modifiedflake.lockdiffbeforeafterboth
--- a/flake.lock
+++ b/flake.lock
@@ -104,14 +104,18 @@
         "nixpkgs-regression": "nixpkgs-regression"
       },
       "locked": {
-        "lastModified": 1756860322,
-        "narHash": "sha256-mT01CpWVdqSm79L270dSkjdYbdc37r+Hq9vk4GTp7Ao=",
-        "path": "/home/lach/build/nix-src",
-        "type": "path"
+        "lastModified": 1757000273,
+        "narHash": "sha256-9AKhwsSlegWnNFy8++OMNctrxJUUIE7nG4s4ZHmFPic=",
+        "owner": "deltarocks",
+        "repo": "nix",
+        "rev": "eba1f549ec21208cf98343f1351a95e2e6eb3fbb",
+        "type": "github"
       },
       "original": {
-        "path": "/home/lach/build/nix-src",
-        "type": "path"
+        "owner": "deltarocks",
+        "ref": "fleet",
+        "repo": "nix",
+        "type": "github"
       }
     },
     "nixpkgs": {
modifiedflake.nixdiffbeforeafterboth
--- a/flake.nix
+++ b/flake.nix
@@ -19,7 +19,7 @@
     };
     # DeterminateSystem's nix fork is controversial, but I don't mind it,
     # and it has lazy-trees support which is useful for fleet.
-    nix.url = "/home/lach/build/nix-src";
+    nix.url = "github:deltarocks/nix/fleet";
   };
   outputs =
     inputs:
@@ -44,10 +44,13 @@
 
           fleetModules.tf = ./modules/extras/tf.nix;
 
-          testObj = {
-            v = "Hello";
+          # Used to test nix-eval bindings
+          testData = {
+            testObj = {
+              v = "Hello";
+            };
+            testString = "hello";
           };
-          testString = "hello";
 
           # To be used with https://github.com/NixOS/nix/pull/8892
           schemas =