git.delta.rocks / jrsonnet / refs/commits / 89d35672dcfd

difftreelog

refactor perform build using nix repl

Yaroslav Bolyukin2023-12-24parent: #e85b4da.patch.diff
in: trunk

8 files changed

modifiedcmds/fleet/src/better_nix_eval.rsdiffbeforeafterboth
before · cmds/fleet/src/better_nix_eval.rs
1use std::ffi::{OsStr, OsString};2use std::fmt::Display;3use std::process::Stdio;4use std::sync::{Arc, OnceLock};56use anyhow::{anyhow, bail, ensure, Context, Result};7use futures::StreamExt;8use itertools::Itertools;9use r2d2::{Pool, PooledConnection};10use serde::de::DeserializeOwned;11use serde::Deserialize;12use tokio::io::AsyncWriteExt;13use tokio::process::{ChildStderr, ChildStdin, ChildStdout, Command};14use tokio::select;15use tokio::sync::{mpsc, oneshot};16use tokio_util::codec::{FramedRead, LinesCodec};17use tracing::{debug, error, warn};1819use crate::command::{ClonableHandler, Handler, NixHandler, NoopHandler};2021const REPL_DELIMITER: &str = "\"FLEET_MAGIC_REPL_DELIMITER\"";2223pub struct NixSessionInner {24	full_delimiter: String,25	nix_handler: ClonableHandler<NixHandler>,26	out: OutputHandler,27	stdin: ChildStdin,28	string_wrapping: (String, String),29	number_wrapping: (String, String),3031	next_id: u32,32	free_list: Vec<u32>,33}34const TRAIN_STRING: &str = "\"TRAIN_STRING\"";35const TRAIN_NUMBER: &str = "13141516";3637#[must_use]38struct ErrorCollector<'i, H> {39	collected: Vec<String>,40	inner: &'i mut H,41}42impl<'i, H> ErrorCollector<'i, H> {43	fn new(inner: &'i mut H) -> Self {44		Self {45			collected: vec![],46			inner,47		}48	}49}50impl<H> ErrorCollector<'_, H> {51	fn handle_line_inner(&mut self, msg: &str) -> bool {52		let Some(msg) = msg.strip_prefix("@nix ") else {53			return false;54		};55		#[derive(Deserialize)]56		struct ErrorAction {57			action: String,58			level: u32,59			msg: String,60		}61		let Ok(act) = serde_json::from_str::<ErrorAction>(msg) else {62			return false;63		};64		if act.action != "msg" || act.level != 0 {65			return false;66		}67		self.collected.push(act.msg);68		true69	}70	fn finish(self) -> Result<()> {71		// fn dedent(s: String) -> String {72		// 	s.split('\n').filter(|s| !s.trim().is_empty()).map(|v| v.)73		// }74		if !self.collected.is_empty() {75			bail!("{}", self.collected.iter().map(|v| {76				if let Some(f) = v.strip_prefix("\u{1b}[31;1merror:\u{1b}[0m ") {77					let v = unindent::unindent(f.trim_start());78					v.trim().to_owned()79				} else {80					v.to_owned()81				}82			}).join("\n"));83		}84		Ok(())85	}86	fn flush(self) {87		for line in self.collected {88			warn!("{line}");89		}90	}91}92impl<H: Handler> Handler for ErrorCollector<'_, H> {93	fn handle_line(&mut self, e: &str) {94		if self.handle_line_inner(e) {95			return;96		}97		self.inner.handle_line(e)98	}99}100101enum OutputLine {102	Out(String),103	Err(String),104}105struct OutputHandler {106	rx: mpsc::Receiver<OutputLine>,107	_cancel_handle: oneshot::Receiver<()>,108}109impl OutputHandler {110	fn new(out: ChildStdout, err: ChildStderr) -> Self {111		let mut out = FramedRead::new(out, LinesCodec::new());112		let mut err = FramedRead::new(err, LinesCodec::new());113		let (tx, rx) = mpsc::channel(20);114		let (mut cancelled, _cancel_handle) = oneshot::channel();115		tokio::spawn(async move {116			loop {117				select! {118					// We should receive errors earlier than synchronization119					biased;120					e = err.next() => {121						let Some(Ok(e)) = e else {122							if e.is_some() {123								error!("bad repl stderr: {e:?}");124							}125							continue;126						};127						let _ = tx.send(OutputLine::Err(e)).await;128					}129					o = out.next() => {130						let Some(Ok(o)) = o else {131							if o.is_some() {132								error!("bad repl stdout: {o:?}");133							}134							continue;135						};136						let _ = tx.send(OutputLine::Out(o)).await;137					}138					// Reader doesn't care about stdout, as this is cancelled.139					// Error still might be useful, to process leftover span closures?140					_ = cancelled.closed() => {141						break;142					}143				}144			}145		});146		Self { rx, _cancel_handle }147	}148	async fn next(&mut self) -> Option<OutputLine> {149		self.rx.recv().await150	}151}152153impl NixSessionInner {154	async fn new(flake: &OsStr, extra_args: impl IntoIterator<Item = &OsStr>) -> Result<Self> {155		let mut cmd = Command::new("nix");156		cmd.arg("repl")157			.arg(flake)158			.arg("--log-format")159			.arg("internal-json");160		for arg in extra_args {161			cmd.arg(arg);162		}163		cmd.stdin(Stdio::piped());164		cmd.stdout(Stdio::piped());165		cmd.stderr(Stdio::piped());166		let cmd = cmd.spawn()?;167		let stdout = cmd.stdout.unwrap();168		let stderr = cmd.stderr.unwrap();169		let mut out = OutputHandler::new(stdout, stderr);170		let mut stdin = cmd.stdin.unwrap();171		// Standard repl hello doesn't work with internal-json logger172		stdin.write_all(REPL_DELIMITER.as_bytes()).await?;173		stdin.write_all(b"\n").await?;174		stdin.flush().await?;175		let nix_handler = NixHandler::default();176		let mut full_delimiter = None;177		while let Some(line) = out.next().await {178			let line = match line {179				OutputLine::Out(o) => o,180				OutputLine::Err(_e) => {181					// Handle startup errors, but skip repl hello?182					//nix_handler.handle_line(&e);183					continue;184				}185			};186			if line.contains(REPL_DELIMITER) {187				debug!("discovered repl delimiter with added colors: {line}");188				full_delimiter = Some(line.to_owned());189				break;190			}191		}192		let Some(full_delimiter) = full_delimiter else {193			bail!("failed to discover delimiter");194		};195		let mut res = Self {196			full_delimiter,197			nix_handler: ClonableHandler::new(nix_handler),198			out,199			stdin,200			string_wrapping: Default::default(),201			number_wrapping: Default::default(),202203			next_id: 0,204			free_list: vec![],205		};206		res.train().await?;207		Ok(res)208	}209	async fn train(&mut self) -> Result<()> {210		{211			let full_string = self212				.execute_expression_raw(TRAIN_STRING, &mut NoopHandler)213				.await?;214			let string_offset = full_string.find(TRAIN_STRING).expect("contained");215			let string_prefix = &full_string[..string_offset];216			let string_suffix = &full_string[string_offset + TRAIN_STRING.len()..];217			self.string_wrapping = (string_prefix.to_owned(), string_suffix.to_owned());218		}219		{220			let full_number = self221				.execute_expression_raw(TRAIN_NUMBER, &mut NoopHandler)222				.await?;223			let number_offset = full_number.find(TRAIN_NUMBER).expect("contained");224			let number_prefix = &full_number[..number_offset];225			let number_suffix = &full_number[number_offset + TRAIN_NUMBER.len()..];226			self.number_wrapping = (number_prefix.to_owned(), number_suffix.to_owned());227		}228		Ok(())229	}230	async fn send_command(&mut self, cmd: impl AsRef<[u8]>) -> Result<()> {231		self.stdin.write_all(cmd.as_ref()).await?;232		self.stdin.write_all(b"\n").await?;233		Ok(())234	}235	async fn read_until_delimiter(&mut self, err_handler: &mut dyn Handler) -> Result<String> {236		let mut out = String::new();237		while let Some(line) = self.out.next().await {238			let line = match line {239				OutputLine::Out(out) => out,240				OutputLine::Err(err) => {241					err_handler.handle_line(&err);242					continue;243				}244			};245			if line == self.full_delimiter {246				return Ok(out);247			}248			if !out.is_empty() {249				out.push('\n');250			}251			out.push_str(&line);252		}253		bail!("didn't reached delimiter");254	}255	async fn execute_expression_number(&mut self, expr: impl AsRef<[u8]>) -> Result<u64> {256		let num = self.number_wrapping.clone();257		let n = self.execute_expression_wrapping(expr, &num).await?;258		Ok(n.parse::<u64>()?)259	}260	async fn execute_expression_string(&mut self, expr: impl AsRef<[u8]>) -> Result<String> {261		let num = self.string_wrapping.clone();262		let n = self.execute_expression_wrapping(expr, &num).await?;263		let str: String = serde_json::from_str(&n)?;264		Ok(str)265	}266	async fn execute_expression_to_json<V: DeserializeOwned>(267		&mut self,268		expr: impl AsRef<[u8]>,269	) -> Result<V> {270		let mut fexpr = b"builtins.toJSON (".to_vec();271		fexpr.extend_from_slice(expr.as_ref());272		fexpr.push(b')');273		let v = self.execute_expression_string(fexpr).await?;274		Ok(serde_json::from_str(&v)?)275	}276	async fn execute_expression_wrapping(277		&mut self,278		expr: impl AsRef<[u8]>,279		wrapping: &(String, String),280	) -> Result<String> {281		let mut nix_handler = self.nix_handler.clone();282		let mut collected = ErrorCollector::new(&mut nix_handler);283		let res = self.execute_expression_raw(expr, &mut collected).await?;284		if res.is_empty() {285			collected.finish()?;286			bail!("expected expression, got nothing")287		} else {288			collected.flush()289		};290		let Some(res) = res.strip_prefix(&wrapping.0) else {291			bail!("invalid type")292		};293		let Some(res) = res.strip_suffix(&wrapping.1) else {294			bail!("invalid type")295		};296		Ok(res.to_owned())297	}298	async fn execute_expression_empty(&mut self, expr: impl AsRef<[u8]>) -> Result<()> {299		let mut nix_handler = self.nix_handler.clone();300		let mut collected = ErrorCollector::new(&mut nix_handler);301		let v = self.execute_expression_raw(expr, &mut collected).await?;302		collected.finish()?;303		ensure!(v.is_empty(), "unexpected expression result");304		Ok(())305	}306	async fn execute_expression_raw(307		&mut self,308		expr: impl AsRef<[u8]>,309		err_handler: &mut dyn Handler,310	) -> Result<String> {311		self.send_command(expr).await?;312		// It will be echoed313		self.send_command(REPL_DELIMITER).await?;314		self.read_until_delimiter(err_handler).await315	}316	async fn execute_assign(&mut self, expr: impl AsRef<str>) -> Result<u32> {317		let id = self.allocate_id();318		self.execute_expression_empty(format!("sess_field_{id} = {}", expr.as_ref()))319			.await?;320		Ok(id)321	}322323	/// Id should be immediately used324	fn allocate_id(&mut self) -> u32 {325		if let Some(free) = self.free_list.pop() {326			free327		} else {328			let v = self.next_id;329			self.next_id += 1;330			v331		}332	}333	// Nix has no way to deallocate variable, yet GC will correct everything not reachable.334	// async fn free_id(&mut self, id: u32) -> Result<()> {335	// 	self.execute_expression_empty(format!("sess_field_{id} = null"))336	// 		.await?;337	// 	self.free_list.push(id);338	// 	Ok(())339	// }340}341342#[derive(Clone)]343pub struct NixSession(Arc<tokio::sync::Mutex<PooledConnection<NixSessionPoolInner>>>);344345#[derive(Clone)]346enum Index {347	String(String),348	// Idx(u32),349}350impl Display for Index {351	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {352		match self {353			Index::String(k) => {354				let v = nixlike::format_identifier(k.as_str());355				write!(f, ".{v}")356			}357		}358	}359}360struct PathDisplay<'i>(&'i [Index]);361impl Display for PathDisplay<'_> {362	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {363		write!(f, "flake")?;364		for i in self.0 {365			write!(f, "{i}")?;366		}367		Ok(())368	}369}370pub struct Field {371	full_path: Vec<Index>,372	session: NixSession,373	value: Option<u32>,374}375impl Field {376	fn root(session: NixSession) -> Self {377		Self {378			full_path: vec![],379			session,380			value: None,381		}382	}383	pub async fn field(session: NixSession, field: &str) -> Result<Self> {384		Self::root(session).get_field_deep([field]).await385	}386	pub async fn get_json_deep<'a, V: DeserializeOwned>(387		&self,388		name: impl IntoIterator<Item = &'a str>,389	) -> Result<V> {390		let field = self.get_field_deep(name).await?;391		field.as_json().await392	}393	pub async fn get_field(&self, name: &str) -> Result<Self> {394		self.get_field_deep([name]).await395	}396	pub async fn get_field_deep<'a>(397		&self,398		name: impl IntoIterator<Item = &'a str>,399	) -> Result<Self> {400		let mut iter = name.into_iter();401402		let mut full_path = self.full_path.clone();403		let mut query = if let Some(id) = self.value {404			format!("sess_field_{id}")405		} else {406			let first = iter.next().expect("name not empty");407			ensure!(408				!(first.contains('.') | first.contains(' ')),409				"bad name for root query: {first}"410			);411			full_path.push(Index::String(first.to_string()));412			first.to_string()413		};414		for v in iter {415			full_path.push(Index::String(v.to_string()));416			// Escape417			let escaped = nixlike::serialize(v)?;418			let escaped = escaped.trim();419			query.push('.');420			query.push_str(escaped);421		}422423		let vid = self424			.session425			.0426			.lock()427			.await428			.execute_assign(&query)429			.await430			.with_context(|| format!("full path: {}", PathDisplay(&full_path)))?;431		Ok(Self {432			full_path,433			session: self.session.clone(),434			value: Some(vid),435		})436	}437	pub async fn as_json<V: DeserializeOwned>(&self) -> Result<V> {438		let id = self.value.expect("can't serialize root field");439		self.session440			.0441			.lock()442			.await443			.execute_expression_to_json(&format!("sess_field_{id}"))444			.await445			.with_context(|| format!("full path: {}", PathDisplay(&self.full_path)))446	}447	pub async fn list_fields(&self) -> Result<Vec<String>> {448		let id = self.value.expect("can't list root fields");449		self.session450			.0451			.lock()452			.await453			.execute_expression_to_json(&format!("builtins.attrNames sess_field_{id}"))454			.await455			.with_context(|| format!("full path: {}", PathDisplay(&self.full_path)))456	}457}458impl Drop for Field {459	fn drop(&mut self) {460		if let Some(id) = self.value {461			if let Ok(mut lock) = self.session.0.try_lock() {462				lock.free_list.push(id)463			}464			// Leaked465		}466	}467}468struct NixSessionPoolInner {469	flake: OsString,470	nix_args: Vec<OsString>,471}472473#[derive(Debug)]474pub struct NixPoolError(anyhow::Error);475impl From<anyhow::Error> for NixPoolError {476	fn from(value: anyhow::Error) -> Self {477		Self(value)478	}479}480impl std::error::Error for NixPoolError {}481impl std::fmt::Display for NixPoolError {482	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {483		self.0.fmt(f)484	}485}486impl r2d2::ManageConnection for NixSessionPoolInner {487	type Connection = NixSessionInner;488	type Error = NixPoolError;489	fn connect(&self) -> std::result::Result<Self::Connection, Self::Error> {490		let _v = TOKIO_RUNTIME491			.get()492			.expect("missed tokio runtime init!")493			.enter();494		Ok(futures::executor::block_on(NixSessionInner::new(495			self.flake.as_os_str(),496			self.nix_args.iter().map(OsString::as_os_str),497		))?)498	}499500	fn is_valid(&self, conn: &mut Self::Connection) -> std::result::Result<(), Self::Error> {501		let _v = TOKIO_RUNTIME502			.get()503			.expect("missed tokio runtime init!")504			.enter();505		let res = futures::executor::block_on(conn.execute_expression_number("2 + 2"))?;506		if res != 4 {507			return Err(anyhow!("sanity check failed").into());508		};509		Ok(())510	}511512	fn has_broken(&self, _conn: &mut Self::Connection) -> bool {513		false514	}515}516pub struct NixSessionPool(Pool<NixSessionPoolInner>);517impl NixSessionPool {518	pub async fn new(flake: OsString, nix_args: Vec<OsString>) -> Result<Self> {519		let inner = tokio::task::block_in_place(|| {520			r2d2::Builder::<NixSessionPoolInner>::new()521				.min_idle(Some(0))522				.build(NixSessionPoolInner { flake, nix_args })523		})?;524		Ok(Self(inner))525	}526	pub async fn get(&self) -> Result<NixSession> {527		let v = tokio::task::block_in_place(|| self.0.get())?;528		Ok(NixSession(Arc::new(tokio::sync::Mutex::new(v))))529	}530}531532pub static TOKIO_RUNTIME: OnceLock<tokio::runtime::Handle> = OnceLock::new();
after · cmds/fleet/src/better_nix_eval.rs
1use std::collections::HashMap;2use std::ffi::{OsStr, OsString};3use std::fmt::{self, Display};4use std::path::PathBuf;5use std::process::Stdio;6use std::sync::{Arc, OnceLock};78use anyhow::{anyhow, bail, ensure, Context, Result};9use futures::StreamExt;10use itertools::Itertools;11use r2d2::{Pool, PooledConnection};12use serde::de::DeserializeOwned;13use serde::{Deserialize, Serialize};14use tokio::io::AsyncWriteExt;15use tokio::process::{ChildStderr, ChildStdin, ChildStdout, Command};16use tokio::select;17use tokio::sync::{mpsc, oneshot};18use tokio_util::codec::{FramedRead, LinesCodec};19use tracing::{debug, error, warn};2021use crate::command::{ClonableHandler, Handler, NixHandler, NoopHandler};2223const REPL_DELIMITER: &str = "\"FLEET_MAGIC_REPL_DELIMITER\"";2425pub struct NixSessionInner {26	full_delimiter: String,27	nix_handler: ClonableHandler<NixHandler>,28	out: OutputHandler,29	stdin: ChildStdin,30	string_wrapping: (String, String),31	number_wrapping: (String, String),3233	next_id: u32,34	free_list: Vec<u32>,35}36const TRAIN_STRING: &str = "\"TRAIN_STRING\"";37const TRAIN_NUMBER: &str = "13141516";3839#[must_use]40struct ErrorCollector<'i, H> {41	collected: Vec<String>,42	inner: &'i mut H,43}44impl<'i, H> ErrorCollector<'i, H> {45	fn new(inner: &'i mut H) -> Self {46		Self {47			collected: vec![],48			inner,49		}50	}51}52impl<H> ErrorCollector<'_, H> {53	fn handle_line_inner(&mut self, msg: &str) -> bool {54		let Some(msg) = msg.strip_prefix("@nix ") else {55			return false;56		};57		#[derive(Deserialize)]58		struct ErrorAction {59			action: String,60			level: u32,61			msg: String,62		}63		let Ok(act) = serde_json::from_str::<ErrorAction>(msg) else {64			return false;65		};66		if act.action != "msg" || act.level != 0 {67			return false;68		}69		self.collected.push(act.msg);70		true71	}72	fn finish(self) -> Result<()> {73		// fn dedent(s: String) -> String {74		// 	s.split('\n').filter(|s| !s.trim().is_empty()).map(|v| v.)75		// }76		if !self.collected.is_empty() {77			bail!(78				"{}",79				self.collected80					.iter()81					.map(|v| {82						if let Some(f) = v.strip_prefix("\u{1b}[31;1merror:\u{1b}[0m ") {83							let v = unindent::unindent(f.trim_start());84							v.trim().to_owned()85						} else {86							v.to_owned()87						}88					})89					.join("\n")90			);91		}92		Ok(())93	}94	fn flush(self) {95		for line in self.collected {96			warn!("{line}");97		}98	}99}100impl<H: Handler> Handler for ErrorCollector<'_, H> {101	fn handle_line(&mut self, e: &str) {102		if self.handle_line_inner(e) {103			return;104		}105		self.inner.handle_line(e)106	}107}108109enum OutputLine {110	Out(String),111	Err(String),112}113struct OutputHandler {114	rx: mpsc::Receiver<OutputLine>,115	_cancel_handle: oneshot::Receiver<()>,116}117impl OutputHandler {118	fn new(out: ChildStdout, err: ChildStderr) -> Self {119		let mut out = FramedRead::new(out, LinesCodec::new());120		let mut err = FramedRead::new(err, LinesCodec::new());121		let (tx, rx) = mpsc::channel(20);122		let (mut cancelled, _cancel_handle) = oneshot::channel();123		tokio::spawn(async move {124			loop {125				select! {126					// We should receive errors earlier than synchronization127					biased;128					e = err.next() => {129						let Some(Ok(e)) = e else {130							if e.is_some() {131								error!("bad repl stderr: {e:?}");132							}133							continue;134						};135						let _ = tx.send(OutputLine::Err(e)).await;136					}137					o = out.next() => {138						let Some(Ok(o)) = o else {139							if o.is_some() {140								error!("bad repl stdout: {o:?}");141							}142							continue;143						};144						let _ = tx.send(OutputLine::Out(o)).await;145					}146					// Reader doesn't care about stdout, as this is cancelled.147					// Error still might be useful, to process leftover span closures?148					_ = cancelled.closed() => {149						break;150					}151				}152			}153		});154		Self { rx, _cancel_handle }155	}156	async fn next(&mut self) -> Option<OutputLine> {157		self.rx.recv().await158	}159}160161struct WarnHandler;162impl Handler for WarnHandler {163	fn handle_line(&mut self, e: &str) {164		warn!(target: "nix", "{e}")165	}166}167168impl NixSessionInner {169	async fn new(flake: &OsStr, extra_args: impl IntoIterator<Item = &OsStr>) -> Result<Self> {170		let mut cmd = Command::new("nix");171		cmd.arg("repl")172			.arg(flake)173			.arg("--log-format")174			.arg("internal-json");175		for arg in extra_args {176			cmd.arg(arg);177		}178		cmd.stdin(Stdio::piped());179		cmd.stdout(Stdio::piped());180		cmd.stderr(Stdio::piped());181		let cmd = cmd.spawn()?;182		let stdout = cmd.stdout.unwrap();183		let stderr = cmd.stderr.unwrap();184		let mut out = OutputHandler::new(stdout, stderr);185		let mut stdin = cmd.stdin.unwrap();186		// Standard repl hello doesn't work with internal-json logger187		stdin.write_all(REPL_DELIMITER.as_bytes()).await?;188		stdin.write_all(b"\n").await?;189		stdin.flush().await?;190		let nix_handler = NixHandler::default();191		let mut full_delimiter = None;192		let mut errors = vec![];193		while let Some(line) = out.next().await {194			let line = match line {195				OutputLine::Out(o) => o,196				OutputLine::Err(_e) => {197					// Handle startup errors, but skip repl hello?198					errors.push(_e);199					continue;200				}201			};202			if line.contains(REPL_DELIMITER) {203				debug!("discovered repl delimiter with added colors: {line}");204				full_delimiter = Some(line.to_owned());205				break;206			}207		}208		let Some(full_delimiter) = full_delimiter else {209			for e in errors {210				error!("{e}");211			}212			bail!("failed to discover delimiter");213		};214		let mut res = Self {215			full_delimiter,216			nix_handler: ClonableHandler::new(nix_handler),217			out,218			stdin,219			string_wrapping: Default::default(),220			number_wrapping: Default::default(),221222			next_id: 0,223			free_list: vec![],224		};225		res.train().await?;226		Ok(res)227	}228	async fn train(&mut self) -> Result<()> {229		{230			let full_string = self231				.execute_expression_raw(TRAIN_STRING, &mut NoopHandler)232				.await?;233			let string_offset = full_string.find(TRAIN_STRING).expect("contained");234			let string_prefix = &full_string[..string_offset];235			let string_suffix = &full_string[string_offset + TRAIN_STRING.len()..];236			self.string_wrapping = (string_prefix.to_owned(), string_suffix.to_owned());237		}238		{239			let full_number = self240				.execute_expression_raw(TRAIN_NUMBER, &mut NoopHandler)241				.await?;242			let number_offset = full_number.find(TRAIN_NUMBER).expect("contained");243			let number_prefix = &full_number[..number_offset];244			let number_suffix = &full_number[number_offset + TRAIN_NUMBER.len()..];245			self.number_wrapping = (number_prefix.to_owned(), number_suffix.to_owned());246		}247		Ok(())248	}249	async fn send_command(&mut self, cmd: impl AsRef<[u8]>) -> Result<()> {250		self.stdin.write_all(cmd.as_ref()).await?;251		self.stdin.write_all(b"\n").await?;252		Ok(())253	}254	async fn read_until_delimiter(&mut self, err_handler: &mut dyn Handler) -> Result<String> {255		let mut out = String::new();256		while let Some(line) = self.out.next().await {257			let line = match line {258				OutputLine::Out(out) => out,259				OutputLine::Err(err) => {260					err_handler.handle_line(&err);261					continue;262				}263			};264			if line == self.full_delimiter {265				return Ok(out);266			}267			if !out.is_empty() {268				out.push('\n');269			}270			out.push_str(&line);271		}272		bail!("didn't reached delimiter");273	}274	async fn execute_expression_number(&mut self, expr: impl AsRef<[u8]>) -> Result<u64> {275		let num = self.number_wrapping.clone();276		let n = self.execute_expression_wrapping(expr, &num).await?;277		Ok(n.parse::<u64>()?)278	}279	async fn execute_expression_string(&mut self, expr: impl AsRef<[u8]>) -> Result<String> {280		let num = self.string_wrapping.clone();281		let n = self.execute_expression_wrapping(expr, &num).await?;282		let str: String = serde_json::from_str(&n)?;283		Ok(str)284	}285	async fn execute_expression_to_json<V: DeserializeOwned>(286		&mut self,287		expr: impl AsRef<[u8]>,288	) -> Result<V> {289		let mut fexpr = b"builtins.toJSON (".to_vec();290		fexpr.extend_from_slice(expr.as_ref());291		fexpr.push(b')');292		let v = self.execute_expression_string(fexpr).await?;293		Ok(serde_json::from_str(&v)?)294	}295	async fn execute_expression_wrapping(296		&mut self,297		expr: impl AsRef<[u8]>,298		wrapping: &(String, String),299	) -> Result<String> {300		let mut nix_handler = self.nix_handler.clone();301		let mut collected = ErrorCollector::new(&mut nix_handler);302		let res = self.execute_expression_raw(expr, &mut collected).await?;303		if res.is_empty() {304			collected.finish()?;305			bail!("expected expression, got nothing")306		} else {307			collected.flush()308		};309		let Some(res) = res.strip_prefix(&wrapping.0) else {310			bail!("invalid type")311		};312		let Some(res) = res.strip_suffix(&wrapping.1) else {313			bail!("invalid type")314		};315		Ok(res.to_owned())316	}317	async fn execute_expression_empty(&mut self, expr: impl AsRef<[u8]>) -> Result<()> {318		let mut nix_handler = self.nix_handler.clone();319		let mut collected = ErrorCollector::new(&mut nix_handler);320		let v = self.execute_expression_raw(expr, &mut collected).await?;321		collected.finish()?;322		ensure!(v.is_empty(), "unexpected expression result");323		Ok(())324	}325	async fn execute_expression_raw(326		&mut self,327		expr: impl AsRef<[u8]>,328		err_handler: &mut dyn Handler,329	) -> Result<String> {330		self.send_command(expr).await?;331		// It will be echoed332		self.send_command(REPL_DELIMITER).await?;333		self.read_until_delimiter(err_handler).await334	}335	async fn execute_assign(&mut self, expr: impl AsRef<str>) -> Result<u32> {336		let id = self.allocate_id();337		self.execute_expression_empty(format!("sess_field_{id} = {}", expr.as_ref()))338			.await?;339		Ok(id)340	}341342	/// Id should be immediately used343	fn allocate_id(&mut self) -> u32 {344		if let Some(free) = self.free_list.pop() {345			free346		} else {347			let v = self.next_id;348			self.next_id += 1;349			v350		}351	}352	// Nix has no way to deallocate variable, yet GC will correct everything not reachable.353	// async fn free_id(&mut self, id: u32) -> Result<()> {354	// 	self.execute_expression_empty(format!("sess_field_{id} = null"))355	// 		.await?;356	// 	self.free_list.push(id);357	// 	Ok(())358	// }359}360361#[derive(Clone)]362pub struct NixSession(Arc<tokio::sync::Mutex<PooledConnection<NixSessionPoolInner>>>);363364#[macro_export]365macro_rules! nix_path {366	(@o($o:ident) $var:ident $($tt:tt)*) => {{367		$o.push(Index::var(stringify!($var)));368		nix_path!(@o($o) $($tt)*);369	}};370	(@o($o:ident) . $var:ident $($tt:tt)*) => {{371		$o.push(Index::attr(stringify!($var)));372		nix_path!(@o($o) $($tt)*);373	}};374	(@o($o:ident) . $var:literal $($tt:tt)*) => {{375		$o.push(Index::attr($var));376		nix_path!(@o($o) $($tt)*);377	}};378	(@o($o:ident) . { $var:expr } $($tt:tt)*) => {{379		$o.push(Index::attr($var));380		nix_path!(@o($o) $($tt)*);381	}};382	(@o($o:ident) [ $var:literal ] $($tt:tt)*) => {{383		$o.push(Index::idx($var));384		nix_path!(@o($o) $($tt)*);385	}};386	(@o($o:ident) ($e:expr) $($tt:tt)*) => {387		$o.push(Index::apply($e));388		nix_path!(@o($o) $($tt)*);389	};390	(@o($o:ident)) => {};391	($($tt:tt)+) => {{392		use $crate::{nix_path, better_nix_eval::Index};393		let mut out = vec![];394		nix_path!(@o(out) $($tt)*);395		out396	}}397}398399#[derive(Clone)]400pub enum Index {401	Var(String),402	String(String),403	Apply(String),404	Idx(u32),405}406impl Index {407	pub fn var(v: impl AsRef<str>) -> Self {408		let v = v.as_ref();409		assert!(410			!(v.contains('.') | v.contains(' ')),411			"bad variable name: {v}"412		);413		Self::Var(v.to_owned())414	}415	pub fn attr(v: impl AsRef<str>) -> Self {416		Self::String(v.as_ref().to_owned())417	}418	pub fn idx(v: u32) -> Self {419		Self::Idx(v)420	}421	pub fn apply(v: impl Serialize) -> Self {422		let serialized = nixlike::serialize(v).expect("invalid value for apply");423		Self::Apply(serialized)424	}425}426impl Display for Index {427	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {428		match self {429			Index::Var(v) => {430				write!(f, "{v}")431			}432			Index::String(k) => {433				let v = nixlike::format_identifier(k.as_str());434				write!(f, ".{v}")435			}436			Index::Apply(o) => {437				let v = nixlike::serialize(o).map_err(|_| fmt::Error)?;438				write!(f, "<apply>({v})")439			}440			Index::Idx(i) => {441				write!(f, "[{i}]")442			}443		}444	}445}446impl fmt::Debug for Index {447	fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {448		write!(f, "{self}")449	}450}451struct PathDisplay<'i>(&'i [Index]);452impl Display for PathDisplay<'_> {453	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {454		write!(f, "flake")?;455		for i in self.0 {456			write!(f, "{i}")?;457		}458		Ok(())459	}460}461pub struct Field {462	full_path: Vec<Index>,463	session: NixSession,464	value: Option<u32>,465}466impl Field {467	fn root(session: NixSession) -> Self {468		Self {469			full_path: vec![],470			session,471			value: None,472		}473	}474	pub async fn field(session: NixSession, field: &str) -> Result<Self> {475		Self::root(session)476			.select([Index::var(field)])477			.await478	}479	pub async fn get_json_deep<'a, V: DeserializeOwned>(480		&self,481		name: impl IntoIterator<Item = Index>,482	) -> Result<V> {483		let field = self.select(name).await?;484		field.as_json().await485	}486	pub async fn select<'a>(&self, name: impl IntoIterator<Item = Index>) -> Result<Self> {487		let mut name = name.into_iter();488489		let mut full_path = self.full_path.clone();490		let mut query = if let Some(id) = self.value {491			format!("sess_field_{id}")492		} else {493			let first = name.next();494			if let Some(Index::Var(i)) = first {495				full_path.push(Index::Var(i.clone()));496				i.clone()497			} else {498				panic!("first path item should be variable, got {first:?}")499			}500		};501		for v in name {502			full_path.push(v.clone());503			match v {504				Index::Var(_) => panic!("var item may only be first"),505				Index::String(s) => {506					let escaped = nixlike::serialize(s)?;507					query.push('.');508					query.push_str(escaped.trim());509				}510				Index::Apply(a) => {511					query.push(' ');512					query.push_str(&a);513				}514				Index::Idx(idx) => {515					query = format!("builtins.elemAt ({query}) {idx}");516				}517			}518		}519520		let vid = self521			.session522			.0523			.lock()524			.await525			.execute_assign(&query)526			.await527			.with_context(|| format!("full path: {}", PathDisplay(&full_path)))?;528		Ok(Self {529			full_path,530			session: self.session.clone(),531			value: Some(vid),532		})533	}534	pub async fn as_json<V: DeserializeOwned>(&self) -> Result<V> {535		let id = self.value.expect("can't serialize root field");536		self.session537			.0538			.lock()539			.await540			.execute_expression_to_json(&format!("sess_field_{id}"))541			.await542			.with_context(|| format!("full path: {}", PathDisplay(&self.full_path)))543	}544	pub async fn list_fields(&self) -> Result<Vec<String>> {545		let id = self.value.expect("can't list root fields");546		self.session547			.0548			.lock()549			.await550			.execute_expression_to_json(&format!("builtins.attrNames sess_field_{id}"))551			.await552			.with_context(|| format!("full path: {}", PathDisplay(&self.full_path)))553	}554	pub async fn build(&self) -> Result<HashMap<String, PathBuf>> {555		let id = self.value.expect("can't use build on not-value");556		let vid = self557			.session558			.0559			.lock()560			.await561			.execute_expression_raw(&format!(":b sess_field_{id}"), &mut NixHandler::default())562			.await?;563		ensure!(!vid.is_empty(), "build failed");564		let Some(vid) = vid.strip_prefix("This derivation produced the following outputs:\n")565		else {566			panic!("unexpected build output: {vid:?}");567		};568		let outputs = vid569			.split('\n')570			.filter(|v| !v.is_empty())571			.map(|v| v.split_once(" -> ").expect("unexpected build output"))572			.map(|(a, b)| (a.trim_start().to_owned(), PathBuf::from(b)))573			.collect();574		Ok(outputs)575	}576}577impl Drop for Field {578	fn drop(&mut self) {579		if let Some(id) = self.value {580			if let Ok(mut lock) = self.session.0.try_lock() {581				lock.free_list.push(id)582			}583			// Leaked584		}585	}586}587struct NixSessionPoolInner {588	flake: OsString,589	nix_args: Vec<OsString>,590}591592#[derive(Debug)]593pub struct NixPoolError(anyhow::Error);594impl From<anyhow::Error> for NixPoolError {595	fn from(value: anyhow::Error) -> Self {596		Self(value)597	}598}599impl std::error::Error for NixPoolError {}600impl std::fmt::Display for NixPoolError {601	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {602		self.0.fmt(f)603	}604}605impl r2d2::ManageConnection for NixSessionPoolInner {606	type Connection = NixSessionInner;607	type Error = NixPoolError;608	fn connect(&self) -> std::result::Result<Self::Connection, Self::Error> {609		let _v = TOKIO_RUNTIME610			.get()611			.expect("missed tokio runtime init!")612			.enter();613		Ok(futures::executor::block_on(NixSessionInner::new(614			self.flake.as_os_str(),615			self.nix_args.iter().map(OsString::as_os_str),616		))?)617	}618619	fn is_valid(&self, conn: &mut Self::Connection) -> std::result::Result<(), Self::Error> {620		let _v = TOKIO_RUNTIME621			.get()622			.expect("missed tokio runtime init!")623			.enter();624		let res = futures::executor::block_on(conn.execute_expression_number("2 + 2"))?;625		if res != 4 {626			return Err(anyhow!("sanity check failed").into());627		};628		Ok(())629	}630631	fn has_broken(&self, _conn: &mut Self::Connection) -> bool {632		false633	}634}635pub struct NixSessionPool(Pool<NixSessionPoolInner>);636impl NixSessionPool {637	pub async fn new(flake: OsString, nix_args: Vec<OsString>) -> Result<Self> {638		let inner = tokio::task::block_in_place(|| {639			r2d2::Builder::<NixSessionPoolInner>::new()640				.min_idle(Some(0))641				.build(NixSessionPoolInner { flake, nix_args })642		})?;643		Ok(Self(inner))644	}645	pub async fn get(&self) -> Result<NixSession> {646		let v = tokio::task::block_in_place(|| self.0.get())?;647		Ok(NixSession(Arc::new(tokio::sync::Mutex::new(v))))648	}649}650651pub static TOKIO_RUNTIME: OnceLock<tokio::runtime::Handle> = OnceLock::new();
modifiedcmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/build_systems.rs
+++ b/cmds/fleet/src/cmds/build_systems.rs
@@ -1,8 +1,10 @@
+use std::os::unix::fs::symlink;
 use std::path::PathBuf;
 use std::{env::current_dir, time::Duration};
 
 use crate::command::MyCommand;
 use crate::host::Config;
+use crate::nix_path;
 use anyhow::{anyhow, Result};
 use clap::Parser;
 use itertools::Itertools;
@@ -11,15 +13,9 @@
 
 #[derive(Parser, Clone)]
 pub struct BuildSystems {
-	/// Do not continue on error
-	#[clap(long)]
-	fail_fast: bool,
 	/// Disable automatic rollback
 	#[clap(long)]
 	disable_rollback: bool,
-	/// Run builds as sudo
-	#[clap(long)]
-	privileged_build: bool,
 	#[clap(subcommand)]
 	subcommand: Subcommand,
 }
@@ -294,34 +290,11 @@
 	async fn build_task(self, config: Config, host: String) -> Result<()> {
 		info!("building");
 		let action = Action::from(self.subcommand.clone());
-		let built = {
-			let dir = tempfile::tempdir()?;
-			dir.path().to_owned()
-		};
-
-		let mut nix_build = MyCommand::new("nix");
-		nix_build
-			.args([
-				"build",
-				"--impure",
-				"--json",
-				// "--show-trace",
-				"--no-link",
-			])
-			.comparg("--out-link", &built)
-			.arg(
-				config.configuration_attr_name(&format!(
-					"buildSystems.{}.{host}",
-					action.build_attr()
-				)),
-			)
-			.args(&config.nix_args);
-
-		if self.privileged_build {
-			nix_build = nix_build.sudo();
-		}
-
-		nix_build.run_nix().await.map_err(|e| {
+		let drv = config
+			.fleet_field
+			.select(nix_path!(.buildSystems.{action.build_attr()}.{&host}))
+			.await?;
+		let outputs = drv.build().await.map_err(|e| {
 			if action.build_attr() == "sdImage" {
 				info!("sd-image build failed");
 				info!("Make sure you have imported modulesPath/installer/sd-card/sd-image-<arch>[-installer].nix (For installer, you may want to check config)");
@@ -329,7 +302,9 @@
 			}
 			e
 		})?;
-		let built = std::fs::canonicalize(built)?;
+		let out_output = outputs
+			.get("out")
+			.ok_or_else(|| anyhow!("system build should produce \"out\" output"))?;
 
 		match action {
 			Action::Upload { action } => {
@@ -342,7 +317,7 @@
 							.arg("sign")
 							.comparg("--key-file", "/etc/nix/private-key")
 							.arg("-r")
-							.arg(&built);
+							.arg(out_output);
 						if let Err(e) = sign.sudo().run_nix().await {
 							warn!("Failed to sign store paths: {e}");
 						};
@@ -353,7 +328,7 @@
 						nix.arg("copy")
 							.arg("--substitute-on-destination")
 							.comparg("--to", format!("ssh-ng://{host}"))
-							.arg(&built);
+							.arg(out_output);
 						match nix.run_nix().await {
 							Ok(()) => break,
 							Err(e) if tries < 3 => {
@@ -366,53 +341,22 @@
 					}
 				}
 				if let Some(action) = action {
-					execute_upload(&self, &config, action, &host, built).await?
+					execute_upload(&self, &config, action, &host, out_output.clone()).await?
 				}
 			}
 			Action::Package(PackageAction::SdImage) => {
 				let mut out = current_dir()?;
 				out.push(format!("sd-image-{}", host));
 
-				info!("building sd image to {:?}", out);
-				let mut nix_build = MyCommand::new("nix");
-				nix_build
-					.args(["build", "--impure", "--no-link"])
-					.comparg("--out-link", &out)
-					.arg(config.configuration_attr_name(&format!("buildSystems.sdImage.{}", host,)))
-					.args(&config.nix_args);
-				if !self.fail_fast {
-					nix_build.arg("--keep-going");
-				}
-				if self.privileged_build {
-					nix_build = nix_build.sudo();
-				}
-
-				nix_build.run_nix().await?;
+				info!("linking sd image to {:?}", out);
+				symlink(out_output, out)?;
 			}
 			Action::Package(PackageAction::InstallationCd) => {
 				let mut out = current_dir()?;
 				out.push(format!("installation-cd-{}", host));
 
-				info!("building sd image to {:?}", out);
-				let mut nix_build = MyCommand::new("nix");
-				nix_build
-					.args(["build", "--impure", "--no-link"])
-					.comparg("--out-link", &out)
-					.arg(
-						config.configuration_attr_name(&format!(
-							"buildSystems.installationCd.{}",
-							host,
-						)),
-					)
-					.args(&config.nix_args);
-				if !self.fail_fast {
-					nix_build.arg("--keep-going");
-				}
-				if self.privileged_build {
-					nix_build = nix_build.sudo();
-				}
-
-				nix_build.run_nix().await?;
+				info!("linking iso image to {:?}", out);
+				symlink(out_output, out)?;
 			}
 		};
 		Ok(())
modifiedcmds/fleet/src/cmds/info.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/info.rs
+++ b/cmds/fleet/src/cmds/info.rs
@@ -1,6 +1,7 @@
 use std::collections::BTreeSet;
 
 use crate::host::Config;
+use crate::nix_path;
 use anyhow::{ensure, Result};
 use clap::Parser;
 
@@ -38,7 +39,7 @@
 					if !tagged.is_empty() {
 						let tags: Vec<String> = config
 							.fleet_field
-							.get_field_deep(["configuredSystems", &host.name, "config", "tags"])
+							.select(nix_path!(.configuredSystems.{&host.name}.config.tags))
 							.await?
 							.as_json()
 							.await?;
@@ -64,7 +65,7 @@
 				let host = config.system_config(&host).await?;
 				if external {
 					out.extend(
-						host.get_field_deep(["network", "externalIps"])
+						host.select(nix_path!(.network.externalIps))
 							.await?
 							.as_json::<Vec<String>>()
 							.await?,
@@ -72,7 +73,7 @@
 				}
 				if internal {
 					out.extend(
-						host.get_field_deep(["network", "internalIps"])
+						host.select(nix_path!(.network.internalIps))
 							.await?
 							.as_json::<Vec<String>>()
 							.await?,
modifiedcmds/fleet/src/cmds/secrets/mod.rsdiffbeforeafterboth
--- a/cmds/fleet/src/cmds/secrets/mod.rs
+++ b/cmds/fleet/src/cmds/secrets/mod.rs
@@ -1,6 +1,6 @@
 use crate::{
 	fleetdata::{FleetSecret, FleetSharedSecret},
-	host::Config,
+	host::Config, nix_path,
 };
 use anyhow::{bail, ensure, Context, Result};
 use chrono::Utc;
@@ -339,7 +339,7 @@
 					let mut data = config.shared_secret(name)?;
 					let expected_owners: Vec<String> = config
 						.config_field
-						.get_json_deep(["sharedSecrets", name, "expectedOwners"])
+						.get_json_deep(nix_path!(sharedSecrets.{name}.expectedOwners))
 						.await?;
 					if expected_owners.is_empty() {
 						warn!("secret was removed from fleet config: {name}, removing from data");
@@ -352,7 +352,7 @@
 					if set != expected_set {
 						let owner_dependent: bool = config
 							.config_field
-							.get_json_deep(["sharedSecrets", name, "ownerDependent"])
+							.get_json_deep(nix_path!(.sharedSecrets.{name}.ownerDependent))
 							.await?;
 						if !owner_dependent {
 							warn!("reencrypting secret '{name}' for new owner set");
modifiedcmds/fleet/src/command.rsdiffbeforeafterboth
--- a/cmds/fleet/src/command.rs
+++ b/cmds/fleet/src/command.rs
@@ -1,5 +1,4 @@
 use std::{
-	borrow::Cow,
 	collections::HashMap,
 	ffi::OsStr,
 	process::Stdio,
@@ -247,10 +246,14 @@
 pub struct NixHandler {
 	spans: HashMap<u64, Span>,
 }
-fn process_message(m: &str) -> Cow<'_, str> {
+fn process_message(m: &str) -> String {
 	static OSC_CLEANER: Lazy<Regex> =
 		Lazy::new(|| Regex::new(r"\x1B\]([^\x07\x1C]*[\x07\x1C])?|\r").unwrap());
-	OSC_CLEANER.replace_all(m, "")
+	static DETABBER: Lazy<Regex> = Lazy::new(|| Regex::new(r"\t").unwrap());
+	let m = OSC_CLEANER.replace_all(m, "");
+	// Indicatif can't format tabs. This is not the correct tab formatting, as correct one should be aligned,
+	// and not just be replaced with the constant number of spaces, but it's ok for now, as statuses are single-line.
+	DETABBER.replace_all(m.as_ref(), "  ").to_string()
 }
 impl Handler for NixHandler {
 	fn handle_line(&mut self, e: &str) {
modifiedcmds/fleet/src/host.rsdiffbeforeafterboth
--- a/cmds/fleet/src/host.rs
+++ b/cmds/fleet/src/host.rs
@@ -13,9 +13,10 @@
 use tempfile::NamedTempFile;
 
 use crate::{
-	better_nix_eval::{Field, NixSessionPool},
+	better_nix_eval::{Field, Index, NixSessionPool},
 	command::MyCommand,
 	fleetdata::{FleetData, FleetSecret, FleetSharedSecret},
+	nix_path,
 };
 
 pub struct FleetConfigInternals {
@@ -24,9 +25,9 @@
 	pub opts: FleetOpts,
 	pub data: Mutex<FleetData>,
 	pub nix_args: Vec<OsString>,
-	// fleetConfigurations.<name>
+	/// fleetConfigurations.<name>.<localSystem>
 	pub fleet_field: Field,
-	// fleet_config.configUnchecked
+	/// fleet_config.configUnchecked
 	pub config_field: Field,
 }
 
@@ -91,22 +92,12 @@
 			command = command.ssh(host);
 		}
 		command.run_string().await
-	}
-
-	pub fn configuration_attr_name(&self, name: &str) -> OsString {
-		let mut str = self.directory.as_os_str().to_owned();
-		str.push("#");
-		str.push(&format!(
-			"fleetConfigurations.default.{}.{}",
-			self.local_system, name
-		));
-		str
 	}
 
 	pub async fn list_hosts(&self) -> Result<Vec<ConfigHost>> {
 		let names = self
 			.fleet_field
-			.get_field_deep(["configuredHosts"])
+			.select(nix_path!(.configuredHosts))
 			.await?
 			.list_fields()
 			.await?;
@@ -118,7 +109,7 @@
 	}
 	pub async fn system_config(&self, host: &str) -> Result<Field> {
 		self.fleet_field
-			.get_field_deep(["configuredSystems", host, "config"])
+			.select(nix_path!(.configuredSystems.{host}.config))
 			.await
 	}
 
@@ -131,7 +122,7 @@
 	/// Shared secrets configured in fleet.nix or in flake
 	pub async fn list_configured_shared(&self) -> Result<Vec<String>> {
 		self.config_field
-			.get_field("sharedSecrets")
+			.select(nix_path!(.sharedSecrets))
 			.await?
 			.list_fields()
 			.await
@@ -221,7 +212,7 @@
 	}
 	pub async fn shared_secret_expected_owners(&self, secret: &str) -> Result<Vec<String>> {
 		self.config_field
-			.get_field_deep(["sharedSecrets", secret, "expectedOwners"])
+			.select(nix_path!(.sharedSecrets.{secret}.expectedOwners))
 			.await?
 			.as_json()
 			.await
@@ -279,7 +270,9 @@
 
 		if self.local_system == "detect" {
 			let builtins_field = Field::field(root_field.clone(), "builtins").await?;
-			let system = builtins_field.get_field("currentSystem").await?;
+			let system = builtins_field
+				.select(nix_path!(.currentSystem))
+				.await?;
 			self.local_system = system.as_json().await?;
 		}
 		let local_system = self.local_system.clone();
@@ -287,9 +280,11 @@
 		let fleet_root = Field::field(root_field, "fleetConfigurations").await?;
 
 		let fleet_field = fleet_root
-			.get_field_deep(["default", &local_system])
+			.select(nix_path!(.default.{&local_system}))
+			.await?;
+		let config_field = fleet_field
+			.select(nix_path!(.configUnchecked))
 			.await?;
-		let config_field = fleet_field.get_field("configUnchecked").await?;
 
 		let mut fleet_data_path = directory.clone();
 		fleet_data_path.push("fleet.nix");
modifiedcmds/fleet/src/main.rsdiffbeforeafterboth
--- a/cmds/fleet/src/main.rs
+++ b/cmds/fleet/src/main.rs
@@ -1,3 +1,4 @@
+#![recursion_limit = "512"]
 #![feature(try_blocks)]
 
 pub(crate) mod cmds;
modifiedflake.nixdiffbeforeafterboth
--- a/flake.nix
+++ b/flake.nix
@@ -19,6 +19,7 @@
       rustPlatform = pkgs.makeRustPlatform { cargo = rust; rustc = rust; };
     in
     {
+		packages = (import ./pkgs) pkgs pkgs;
       devShell = (pkgs.mkShell.override { stdenv = llvmPkgs.stdenv; }) {
         nativeBuildInputs = with pkgs; [
           rust