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

difftreelog

feat adopt keep-going-by-default behavior

Lach2025-05-12parent: #03574ae.patch.diff
in: trunk

4 files changed

modifiedcrates/fleet-base/src/opts.rsdiffbeforeafterboth
--- a/crates/fleet-base/src/opts.rs
+++ b/crates/fleet-base/src/opts.rs
@@ -87,6 +87,13 @@
 	/// binfmt-declared qemu instead of trying to crosscompile
 	#[clap(long, default_value = env!("NIX_SYSTEM"))]
 	pub local_system: String,
+
+	/// By default fleet continues on single derivation build failure
+	/// this flag makes command fail immediately
+	///
+	/// Opposite of Nix's --keep-going
+	#[clap(long)]
+	pub fail_fast: bool,
 }
 
 impl FleetOpts {
@@ -204,6 +211,7 @@
 			directory.as_os_str().to_owned(),
 			nix_args.clone(),
 			self.local_system.clone(),
+			self.fail_fast,
 		)
 		.await?;
 		let nix_session = pool.get().await?;
modifiedcrates/nix-eval/src/pool.rsdiffbeforeafterboth
before · crates/nix-eval/src/pool.rs
1use std::{2	ffi::OsString,3	sync::{Arc, OnceLock},4};56use r2d2::Pool;78use crate::{session::NixSessionInner, Error, NixSession, Result};910pub struct NixSessionPool(Pool<NixSessionPoolInner>);11impl NixSessionPool {12	pub async fn new(flake: OsString, nix_args: Vec<OsString>, nix_system: String) -> Result<Self> {13		let inner = tokio::task::block_in_place(|| {14			r2d2::Builder::<NixSessionPoolInner>::new()15				.min_idle(Some(0))16				.build(NixSessionPoolInner {17					flake,18					nix_args,19					nix_system,20				})21		})?;22		Ok(Self(inner))23	}24	pub async fn get(&self) -> Result<NixSession> {25		let v = tokio::task::block_in_place(|| self.0.get())?;26		Ok(NixSession(Arc::new(tokio::sync::Mutex::new(v))))27	}28}2930pub(crate) struct NixSessionPoolInner {31	flake: OsString,32	nix_args: Vec<OsString>,33	pub(crate) nix_system: String,34}3536impl r2d2::ManageConnection for NixSessionPoolInner {37	type Connection = NixSessionInner;38	type Error = Error;39	fn connect(&self) -> std::result::Result<Self::Connection, Self::Error> {40		let _v = TOKIO_RUNTIME41			.get()42			.expect("missed tokio runtime init!")43			.enter();44		Ok(futures::executor::block_on(NixSessionInner::new(45			self.flake.as_os_str(),46			self.nix_args.iter().map(OsString::as_os_str),47			self.nix_system.clone(),48		))?)49	}5051	fn is_valid(&self, conn: &mut Self::Connection) -> std::result::Result<(), Self::Error> {52		let _v = TOKIO_RUNTIME53			.get()54			.expect("missed tokio runtime init!")55			.enter();56		let res = futures::executor::block_on(conn.execute_expression_number("2 + 2"))?;57		if res != 4 {58			// just in case, should fail much earlier59			return Err(Error::SessionInit("misbehaving session"));60		};61		Ok(())62	}6364	fn has_broken(&self, _conn: &mut Self::Connection) -> bool {65		false66	}67}68pub static TOKIO_RUNTIME: OnceLock<tokio::runtime::Handle> = OnceLock::new();
after · crates/nix-eval/src/pool.rs
1use std::{2	ffi::OsString,3	sync::{Arc, OnceLock},4};56use r2d2::Pool;78use crate::{session::NixSessionInner, Error, NixSession, Result};910pub struct NixSessionPool(Pool<NixSessionPoolInner>);11impl NixSessionPool {12	pub async fn new(13		flake: OsString,14		nix_args: Vec<OsString>,15		nix_system: String,16		fail_fast: bool,17	) -> Result<Self> {18		let inner = tokio::task::block_in_place(|| {19			r2d2::Builder::<NixSessionPoolInner>::new()20				.min_idle(Some(0))21				.build(NixSessionPoolInner {22					flake,23					nix_args,24					nix_system,25					fail_fast,26				})27		})?;28		Ok(Self(inner))29	}30	pub async fn get(&self) -> Result<NixSession> {31		let v = tokio::task::block_in_place(|| self.0.get())?;32		Ok(NixSession(Arc::new(tokio::sync::Mutex::new(v))))33	}34}3536pub(crate) struct NixSessionPoolInner {37	flake: OsString,38	nix_args: Vec<OsString>,39	fail_fast: bool,40	pub(crate) nix_system: String,41}4243impl r2d2::ManageConnection for NixSessionPoolInner {44	type Connection = NixSessionInner;45	type Error = Error;46	fn connect(&self) -> std::result::Result<Self::Connection, Self::Error> {47		let _v = TOKIO_RUNTIME48			.get()49			.expect("missed tokio runtime init!")50			.enter();51		futures::executor::block_on(NixSessionInner::new(52			self.flake.as_os_str(),53			self.nix_args.iter().map(OsString::as_os_str),54			self.nix_system.clone(),55			self.fail_fast,56		))57	}5859	fn is_valid(&self, conn: &mut Self::Connection) -> std::result::Result<(), Self::Error> {60		let _v = TOKIO_RUNTIME61			.get()62			.expect("missed tokio runtime init!")63			.enter();64		let res = futures::executor::block_on(conn.execute_expression_number("2 + 2"))?;65		if res != 4 {66			// just in case, should fail much earlier67			return Err(Error::SessionInit("misbehaving session"));68		};69		Ok(())70	}7172	fn has_broken(&self, _conn: &mut Self::Connection) -> bool {73		false74	}75}76pub static TOKIO_RUNTIME: OnceLock<tokio::runtime::Handle> = OnceLock::new();
modifiedcrates/nix-eval/src/session.rsdiffbeforeafterboth
--- a/crates/nix-eval/src/session.rs
+++ b/crates/nix-eval/src/session.rs
@@ -225,6 +225,7 @@
 		flake: &OsStr,
 		extra_args: impl IntoIterator<Item = &OsStr>,
 		nix_system: String,
+		fail_fast: bool,
 	) -> Result<Self> {
 		let mut cmd = Command::new("nix");
 		cmd.arg("repl")
@@ -232,6 +233,9 @@
 			.arg(flake)
 			.arg("--log-format")
 			.arg("internal-json");
+		if !fail_fast {
+			cmd.arg("--keep-going");
+		}
 		for arg in extra_args {
 			cmd.arg(arg);
 		}
modifiedflake.nixdiffbeforeafterboth
--- a/flake.nix
+++ b/flake.nix
@@ -136,7 +136,7 @@
                 inherit (packages) fleet-install-secrets;
               })
               // {
-                checks.formatting = treefmt.check self;
+                formatting = treefmt.check self;
               };
             # TODO: It should be possible to move lib.mkIf to default attribute, instead of disabling the whole
             # devShells block, yet nix flake check fails here, due to no default shell found. It is nix or flake-parts bug?