From cc4299b11a7bab262d3e1f87aad582659f4e183c Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Thu, 18 Sep 2025 20:10:53 +0000 Subject: [PATCH] refactor: nix-eval is now fully sync, parallelism should be explicit at the callsite --- --- a/Cargo.lock +++ b/Cargo.lock @@ -2070,8 +2070,6 @@ "serde_json", "test-log", "thiserror 2.0.16", - "tokio", - "tokio-util", "tracing", "tracing-indicatif", "vte 0.15.0", --- a/cmds/fleet/src/cmds/build_systems.rs +++ b/cmds/fleet/src/cmds/build_systems.rs @@ -8,7 +8,7 @@ opts::FleetOpts, }; use nix_eval::nix_go; -use tokio::task::LocalSet; +use tokio::task::{LocalSet, spawn_blocking}; use tracing::{Instrument, error, field, info, info_span, warn}; #[derive(Parser)] @@ -34,7 +34,9 @@ // let action = Action::from(self.subcommand.clone()); let nixos = host.nixos_config().await?; let drv = nix_go!(nixos.system.build[{ build_attr }]); - let out_output = drv.build("out").await?; + let out_output = spawn_blocking(move || drv.build("out")) + .await + .expect("system derivation build should not panic")?; // We already have system profiles for backups. if !host.local { --- a/cmds/fleet/src/cmds/secrets/mod.rs +++ b/cmds/fleet/src/cmds/secrets/mod.rs @@ -19,7 +19,7 @@ use owo_colors::OwoColorize; use serde::Deserialize; use tabled::{Table, Tabled}; -use tokio::fs::read; +use tokio::{fs::read, task::spawn_blocking}; use tracing::{Instrument, error, info, info_span, warn}; #[derive(Parser)] @@ -288,7 +288,9 @@ let generator = nix_go!(call_package(generator)(Obj {})); - let generator = generator.build("out").await?; + let generator = spawn_blocking(move || generator.build("out")) + .await + .expect("nix build shouldn't fail")?; let generator = host.remote_derivation(&generator).await?; let out_parent = host.mktemp_dir().await?; --- a/cmds/fleet/src/cmds/tf.rs +++ b/cmds/fleet/src/cmds/tf.rs @@ -10,6 +10,7 @@ use tokio::{ fs::{self, create_dir_all}, process::Command, + task::spawn_blocking, }; use tracing::debug; @@ -38,7 +39,10 @@ debug!("generating terraform configs"); let system = &config.local_system; let config = &config.config_field; - let data: PathBuf = nix_go!(config.tf({ system })).build("out").await?; + let data = nix_go!(config.tf({ system })); + let data: PathBuf = spawn_blocking(move || data.build("out")) + .await + .expect("tf.json derivation should not fail")?; let data = fs::read(&data).await?; create_dir_all(&dir).await?; --- a/crates/nix-eval/Cargo.toml +++ b/crates/nix-eval/Cargo.toml @@ -11,8 +11,6 @@ serde = { workspace = true, features = ["derive"] } serde_json.workspace = true thiserror.workspace = true -tokio = { workspace = true } -tokio-util.workspace = true tracing.workspace = true cxx = "1.0.168" --- a/crates/nix-eval/src/lib.rs +++ b/crates/nix-eval/src/lib.rs @@ -750,7 +750,7 @@ })?; Ok(out) } - pub async fn build(&self, output: &str) -> Result { + pub fn build(&self, output: &str) -> Result { if !self.is_derivation() { bail!("expected derivation to build") } -- gitstuff