difftreelog
fix carry more settings from environment
in: trunk
8 files changed
Cargo.lockdiffbeforeafterboth--- a/Cargo.lock
+++ b/Cargo.lock
@@ -738,6 +738,12 @@
]
[[package]]
+name = "cursor-icon"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "96a6ac251f4a2aca6b3f91340350eab87ae57c3f127ffeb585e92bd336717991"
+
+[[package]]
name = "curve25519-dalek"
version = "4.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1956,6 +1962,7 @@
"tokio-util",
"tracing",
"tracing-indicatif",
+ "vte 0.15.0",
]
[[package]]
@@ -3666,7 +3673,7 @@
"itoa",
"log",
"unicode-width 0.1.14",
- "vte",
+ "vte 0.11.1",
]
[[package]]
@@ -3681,6 +3688,19 @@
]
[[package]]
+name = "vte"
+version = "0.15.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a5924018406ce0063cd67f8e008104968b74b563ee1b85dde3ed1f7cb87d3dbd"
+dependencies = [
+ "arrayvec",
+ "bitflags",
+ "cursor-icon",
+ "log",
+ "memchr",
+]
+
+[[package]]
name = "vte_generate_state_changes"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
crates/fleet-base/src/opts.rsdiffbeforeafterboth1use std::{2 collections::BTreeMap,3 env::current_dir,4 ffi::OsString,5 str::FromStr,6 sync::{Arc, Mutex},7};89use anyhow::{Context, Result, bail};10use nix_eval::{11 FetchSettings, FlakeReference, FlakeReferenceParseFlags, FlakeSettings, Value, nix_go,12 util::assert_warn,13};14use nom::{15 Parser,16 bytes::complete::take_while1,17 character::complete::char,18 combinator::{map, opt},19 multi::separated_list1,20 sequence::{preceded, separated_pair},21};2223use crate::{24 fleetdata::FleetData,25 host::{Config, ConfigHost, FleetConfigInternals},26};2728#[derive(Clone)]29pub enum HostItem {30 Host {31 name: String,32 attrs: BTreeMap<String, String>,33 },34 Tag {35 name: String,36 attrs: BTreeMap<String, String>,37 },38}39fn host_item_parser(input: &str) -> Result<HostItem, String> {40 fn err_to_string(err: nom::Err<nom::error::Error<&str>>) -> String {41 err.to_string()42 }4344 let (input, is_tag) = map(opt(char('@')), |c| c.is_some())45 .parse_complete(input)46 .map_err(err_to_string)?;47 let (input, name) = map(48 take_while1(|v| v != ',' && v != '?' && v != '@'),49 str::to_owned,50 )51 .parse_complete(input)52 .map_err(err_to_string)?;5354 let kw_item = separated_pair(55 map(take_while1(|v| v != '&' && v != '='), str::to_owned),56 char('='),57 map(take_while1(|v| v != '&'), str::to_owned),58 );59 let kw = map(separated_list1(char('&'), kw_item), |vec| {60 vec.into_iter().collect::<BTreeMap<_, _>>()61 });62 let mut opt_kw = map(opt(preceded(char('?'), kw)), Option::unwrap_or_default);6364 let (input, attrs) = opt_kw.parse_complete(input).map_err(err_to_string)?;6566 if !input.is_empty() {67 return Err(format!("unexpected trailing input: {input:?}"));68 }69 Ok(if is_tag {70 HostItem::Tag { name, attrs }71 } else {72 HostItem::Host { name, attrs }73 })74}7576// TODO: Rename to HostSelector77#[derive(clap::Parser, Clone)]78pub struct FleetOpts {79 /// All hosts except those would be skipped80 #[clap(long, number_of_values = 1, value_parser = host_item_parser)]81 pub only: Vec<HostItem>,8283 /// Hosts to skip84 #[clap(long, number_of_values = 1)]85 pub skip: Vec<String>,8687 /// Host, which should be threaten as current machine88 // TODO: Replace with connectivity refactor89 #[clap(long, default_value_t = hostname::get().expect("unknown hostname").to_str().expect("hostname is not utf-8").to_owned())]90 pub localhost: String,9192 /// Override detected system for host, to perform builds via93 /// binfmt-declared qemu instead of trying to crosscompile94 #[clap(long, default_value = env!("NIX_SYSTEM"))]95 pub local_system: String,9697 /// By default fleet continues on single derivation build failure98 /// this flag makes command fail immediately99 ///100 /// Opposite of Nix's --keep-going101 #[clap(long)]102 pub fail_fast: bool,103}104105impl FleetOpts {106 pub async fn filter_skipped(107 &self,108 hosts: impl IntoIterator<Item = ConfigHost>,109 ) -> Result<Vec<ConfigHost>> {110 let mut out = Vec::new();111 for host in hosts {112 if self.should_skip(&host).await? {113 continue;114 }115 out.push(host);116 }117 Ok(out)118 }119 pub async fn should_skip(&self, host: &ConfigHost) -> Result<bool> {120 if self.skip.iter().any(|h| h as &str == host.name) {121 return Ok(true);122 }123 if self.only.is_empty() {124 return Ok(false);125 }126 let mut have_group_matches = false;127 for item in self.only.iter() {128 match item {129 HostItem::Host { name, .. } if *name == host.name => {130 return Ok(false);131 }132 HostItem::Tag { .. } => {133 have_group_matches = true;134 }135 _ => {}136 }137 }138 if have_group_matches {139 let host_tags = host.tags().await?;140 for item in self.only.iter() {141 match item {142 HostItem::Tag { name, .. } if host_tags.contains(name) => {143 return Ok(false);144 }145 _ => {}146 }147 }148 }149 Ok(true)150 }151 pub async fn action_attr<T: FromStr>(&self, host: &ConfigHost, attr: &str) -> Result<Option<T>>152 where153 T::Err: Sync,154 anyhow::Error: From<T::Err>,155 {156 let str = self.action_attr_str(host, attr).await?;157 Ok(str.map(|v| T::from_str(&v)).transpose()?)158 }159 pub async fn action_attr_str(&self, host: &ConfigHost, attr: &str) -> Result<Option<String>> {160 if self.only.is_empty() {161 return Ok(None);162 }163 let mut have_group_matches = false;164 for item in self.only.iter() {165 match item {166 HostItem::Host { name, attrs }167 if *name == host.name && attrs.contains_key(attr) =>168 {169 return Ok(attrs.get(attr).cloned());170 }171 HostItem::Tag { attrs, .. } if attrs.contains_key(attr) => {172 have_group_matches = true;173 }174 _ => {}175 }176 }177 if have_group_matches {178 let host_tags = host.tags().await?;179 for item in self.only.iter() {180 match item {181 HostItem::Tag { name, attrs }182 if host_tags.contains(name) && attrs.contains_key(attr) =>183 {184 return Ok(attrs.get(attr).cloned());185 }186 _ => {}187 }188 }189 }190 Ok(None)191 }192 pub fn is_local(&self, host: &str) -> bool {193 self.localhost == host194 }195196 // TODO: Config should be detached from opts.197 pub async fn build(&self, nix_args: Vec<OsString>, assert: bool) -> Result<Config> {198 let cwd = current_dir()?;199 let mut directory = cwd.clone();200 let mut fleet_data_path = directory.join("fleet.nix");201 while !fleet_data_path.is_file() {202 // fleet.nix203 fleet_data_path.pop();204 if !directory.pop() || !fleet_data_path.pop() {205 bail!(206 "fleet.nix not found at {} or any of the parent directories",207 cwd.display()208 );209 }210 fleet_data_path.push("fleet.nix");211 }212 let bytes =213 std::fs::read_to_string(&fleet_data_path).context("reading fleet state (fleet.nix)")?;214 let data: Mutex<FleetData> = nixlike::parse_str(&bytes)?;215216 let mut fetch_settings = FetchSettings::new();217 fetch_settings.set(c"warn-dirty", c"false");218219 let mut flake_settings = FlakeSettings::new()?;220 let mut parse = FlakeReferenceParseFlags::new(&flake_settings)?;221 // For some reason, lazy trees not being used when there is no base dir set222 parse.set_base_dir("/")?;223224 let (mut flake, _) = FlakeReference::new(225 directory226 .to_str()227 .ok_or_else(|| anyhow::anyhow!("fleet dir should have utf-8 path"))?,228 &flake_settings,229 &parse,230 &fetch_settings,231 )?;232 let flake = flake.lock(&fetch_settings)?;233234 let flake = flake.get_attrs(&mut flake_settings)?;235236 let builtins_field = Value::eval("builtins")?;237238 let fleet_root = flake.get_field("fleetConfigurations")?;239 let data_val = Value::serialized(&data)?;240 let fleet_field = nix_go!(fleet_root.default(data_val));241242 let config_field = nix_go!(fleet_field.config);243244 if assert {245 assert_warn("fleet config evaluation", &config_field)246 .await247 .context("failed to verify assertions")?;248 }249250 let import = nix_go!(builtins_field.import);251 let overlays = nix_go!(config_field.nixpkgs.overlays);252 let nixpkgs = nix_go!(config_field.nixpkgs.buildUsing);253 let nixpkgs_imported = nix_go!(import(nixpkgs));254255 let default_pkgs = nix_go!(nixpkgs_imported(Obj {256 overlays,257 system: self.local_system.clone(),258 }));259260 Ok(Config(Arc::new(FleetConfigInternals {261 directory,262 data,263 local_system: self.local_system.clone(),264 nix_args,265 config_field,266 default_pkgs,267 nixpkgs,268 localhost: self.localhost.to_owned(),269 })))270 }271}1use std::{2 collections::BTreeMap,3 env::current_dir,4 ffi::OsString,5 str::FromStr,6 sync::{Arc, Mutex},7};89use anyhow::{Context, Result, bail};10use nix_eval::{11 FetchSettings, FlakeLockFlags, FlakeReference, FlakeReferenceParseFlags, FlakeSettings, Value,12 nix_go, util::assert_warn,13};14use nom::{15 Parser,16 bytes::complete::take_while1,17 character::complete::char,18 combinator::{map, opt},19 multi::separated_list1,20 sequence::{preceded, separated_pair},21};2223use crate::{24 fleetdata::FleetData,25 host::{Config, ConfigHost, FleetConfigInternals},26};2728#[derive(Clone)]29pub enum HostItem {30 Host {31 name: String,32 attrs: BTreeMap<String, String>,33 },34 Tag {35 name: String,36 attrs: BTreeMap<String, String>,37 },38}39fn host_item_parser(input: &str) -> Result<HostItem, String> {40 fn err_to_string(err: nom::Err<nom::error::Error<&str>>) -> String {41 err.to_string()42 }4344 let (input, is_tag) = map(opt(char('@')), |c| c.is_some())45 .parse_complete(input)46 .map_err(err_to_string)?;47 let (input, name) = map(48 take_while1(|v| v != ',' && v != '?' && v != '@'),49 str::to_owned,50 )51 .parse_complete(input)52 .map_err(err_to_string)?;5354 let kw_item = separated_pair(55 map(take_while1(|v| v != '&' && v != '='), str::to_owned),56 char('='),57 map(take_while1(|v| v != '&'), str::to_owned),58 );59 let kw = map(separated_list1(char('&'), kw_item), |vec| {60 vec.into_iter().collect::<BTreeMap<_, _>>()61 });62 let mut opt_kw = map(opt(preceded(char('?'), kw)), Option::unwrap_or_default);6364 let (input, attrs) = opt_kw.parse_complete(input).map_err(err_to_string)?;6566 if !input.is_empty() {67 return Err(format!("unexpected trailing input: {input:?}"));68 }69 Ok(if is_tag {70 HostItem::Tag { name, attrs }71 } else {72 HostItem::Host { name, attrs }73 })74}7576// TODO: Rename to HostSelector77#[derive(clap::Parser, Clone)]78pub struct FleetOpts {79 /// All hosts except those would be skipped80 #[clap(long, number_of_values = 1, value_parser = host_item_parser)]81 pub only: Vec<HostItem>,8283 /// Hosts to skip84 #[clap(long, number_of_values = 1)]85 pub skip: Vec<String>,8687 /// Host, which should be threaten as current machine88 // TODO: Replace with connectivity refactor89 #[clap(long, default_value_t = hostname::get().expect("unknown hostname").to_str().expect("hostname is not utf-8").to_owned())]90 pub localhost: String,9192 /// Override detected system for host, to perform builds via93 /// binfmt-declared qemu instead of trying to crosscompile94 #[clap(long, default_value = env!("NIX_SYSTEM"))]95 pub local_system: String,9697 /// By default fleet continues on single derivation build failure98 /// this flag makes command fail immediately99 ///100 /// Opposite of Nix's --keep-going101 #[clap(long)]102 pub fail_fast: bool,103}104105impl FleetOpts {106 pub async fn filter_skipped(107 &self,108 hosts: impl IntoIterator<Item = ConfigHost>,109 ) -> Result<Vec<ConfigHost>> {110 let mut out = Vec::new();111 for host in hosts {112 if self.should_skip(&host).await? {113 continue;114 }115 out.push(host);116 }117 Ok(out)118 }119 pub async fn should_skip(&self, host: &ConfigHost) -> Result<bool> {120 if self.skip.iter().any(|h| h as &str == host.name) {121 return Ok(true);122 }123 if self.only.is_empty() {124 return Ok(false);125 }126 let mut have_group_matches = false;127 for item in self.only.iter() {128 match item {129 HostItem::Host { name, .. } if *name == host.name => {130 return Ok(false);131 }132 HostItem::Tag { .. } => {133 have_group_matches = true;134 }135 _ => {}136 }137 }138 if have_group_matches {139 let host_tags = host.tags().await?;140 for item in self.only.iter() {141 match item {142 HostItem::Tag { name, .. } if host_tags.contains(name) => {143 return Ok(false);144 }145 _ => {}146 }147 }148 }149 Ok(true)150 }151 pub async fn action_attr<T: FromStr>(&self, host: &ConfigHost, attr: &str) -> Result<Option<T>>152 where153 T::Err: Sync,154 anyhow::Error: From<T::Err>,155 {156 let str = self.action_attr_str(host, attr).await?;157 Ok(str.map(|v| T::from_str(&v)).transpose()?)158 }159 pub async fn action_attr_str(&self, host: &ConfigHost, attr: &str) -> Result<Option<String>> {160 if self.only.is_empty() {161 return Ok(None);162 }163 let mut have_group_matches = false;164 for item in self.only.iter() {165 match item {166 HostItem::Host { name, attrs }167 if *name == host.name && attrs.contains_key(attr) =>168 {169 return Ok(attrs.get(attr).cloned());170 }171 HostItem::Tag { attrs, .. } if attrs.contains_key(attr) => {172 have_group_matches = true;173 }174 _ => {}175 }176 }177 if have_group_matches {178 let host_tags = host.tags().await?;179 for item in self.only.iter() {180 match item {181 HostItem::Tag { name, attrs }182 if host_tags.contains(name) && attrs.contains_key(attr) =>183 {184 return Ok(attrs.get(attr).cloned());185 }186 _ => {}187 }188 }189 }190 Ok(None)191 }192 pub fn is_local(&self, host: &str) -> bool {193 self.localhost == host194 }195196 // TODO: Config should be detached from opts.197 pub async fn build(&self, nix_args: Vec<OsString>, assert: bool) -> Result<Config> {198 let cwd = current_dir()?;199 let mut directory = cwd.clone();200 let mut fleet_data_path = directory.join("fleet.nix");201 while !fleet_data_path.is_file() {202 // fleet.nix203 fleet_data_path.pop();204 if !directory.pop() || !fleet_data_path.pop() {205 bail!(206 "fleet.nix not found at {} or any of the parent directories",207 cwd.display()208 );209 }210 fleet_data_path.push("fleet.nix");211 }212 let bytes =213 std::fs::read_to_string(&fleet_data_path).context("reading fleet state (fleet.nix)")?;214 let data: Mutex<FleetData> = nixlike::parse_str(&bytes)?;215216 let mut fetch_settings = FetchSettings::new();217 fetch_settings.set(c"warn-dirty", c"false");218219 let mut flake_settings = FlakeSettings::new()?;220 let mut parse = FlakeReferenceParseFlags::new(&flake_settings)?;221 // For some reason, lazy trees not being used when there is no base dir set222 parse.set_base_dir("/")?;223224 let (mut flake, _) = FlakeReference::new(225 directory226 .to_str()227 .ok_or_else(|| anyhow::anyhow!("fleet dir should have utf-8 path"))?,228 &flake_settings,229 &parse,230 &fetch_settings,231 )?;232233 let lock = FlakeLockFlags::new(&flake_settings)?;234235 let flake = flake.lock(&fetch_settings, &flake_settings, &lock)?;236237 let flake = flake.get_attrs(&mut flake_settings)?;238239 let builtins_field = Value::eval("builtins")?;240241 let fleet_root = flake.get_field("fleetConfigurations")?;242 let data_val = Value::serialized(&data)?;243 let fleet_field = nix_go!(fleet_root.default(data_val));244245 let config_field = nix_go!(fleet_field.config);246247 if assert {248 assert_warn("fleet config evaluation", &config_field)249 .await250 .context("failed to verify assertions")?;251 }252253 let import = nix_go!(builtins_field.import);254 let overlays = nix_go!(config_field.nixpkgs.overlays);255 let nixpkgs = nix_go!(config_field.nixpkgs.buildUsing);256 let nixpkgs_imported = nix_go!(import(nixpkgs));257258 let default_pkgs = nix_go!(nixpkgs_imported(Obj {259 overlays,260 system: self.local_system.clone(),261 }));262263 Ok(Config(Arc::new(FleetConfigInternals {264 directory,265 data,266 local_system: self.local_system.clone(),267 nix_args,268 config_field,269 default_pkgs,270 nixpkgs,271 localhost: self.localhost.to_owned(),272 })))273 }274}crates/nix-eval/Cargo.tomldiffbeforeafterboth--- a/crates/nix-eval/Cargo.toml
+++ b/crates/nix-eval/Cargo.toml
@@ -19,6 +19,7 @@
itertools = "0.14.0"
test-log = { version = "0.2.18", features = ["trace"] }
tracing-indicatif = { version = "0.3.13", optional = true }
+vte = { version = "0.15.0", features = ["ansi"] }
[build-dependencies]
bindgen = "0.72.0"
crates/nix-eval/src/lib.rsdiffbeforeafterboth--- a/crates/nix-eval/src/lib.rs
+++ b/crates/nix-eval/src/lib.rs
@@ -19,12 +19,11 @@
alloc_value, c_context, c_context_create, err_code, err_info_msg, eval_state_build,
eval_state_builder_new, expr_eval_from_string, fetchers_settings, fetchers_settings_free,
fetchers_settings_new, flake_lock, flake_lock_flags, flake_lock_flags_free,
- flake_lock_flags_new, flake_lock_flags_set_mode_virtual, flake_reference_parse_flags,
- flake_reference_parse_flags_free, 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_incref,
+ flake_lock_flags_new, flake_reference_parse_flags, flake_reference_parse_flags_free,
+ flake_reference_parse_flags_new, flake_reference_parse_flags_set_base_directory,
+ flake_settings, flake_settings_free, flake_settings_new, get_string, init_bool, init_int,
+ init_string, locked_flake_free, locked_flake_get_output_attrs, set_err_msg, setting_set,
+ state_free, value_decref, value_incref,
};
// Contains macros helpers
@@ -226,11 +225,15 @@
fn new() -> Result<Self> {
let mut ctx = NixContext::new();
let store = ctx
- .run_in_context(|c| unsafe { nix_raw::store_open(c, c"daemon".as_ptr(), null_mut()) })
+ .run_in_context(|c| unsafe { nix_raw::store_open(c, c"auto".as_ptr(), null_mut()) })
.map(Store)?;
let builder = ctx.run_in_context(|c| unsafe { eval_state_builder_new(c, store.0) })?;
ctx.run_in_context(|c| {
+ unsafe { nix_raw::eval_state_builder_load(c, builder) }
+ // eval_s
+ })?;
+ ctx.run_in_context(|c| {
unsafe {
nix_raw::eval_state_builder_set_eval_setting(
c,
@@ -363,12 +366,12 @@
}
}
}
-struct FlakeLockFlags(*mut flake_lock_flags);
+pub struct FlakeLockFlags(*mut flake_lock_flags);
impl FlakeLockFlags {
- fn new(settings: &mut FlakeSettings) -> Result<Self> {
+ pub fn new(settings: &FlakeSettings) -> Result<Self> {
let o = with_default_context(|c, _| unsafe { flake_lock_flags_new(c, settings.0) })
.map(Self)?;
- with_default_context(|c, _| unsafe { flake_lock_flags_set_mode_virtual(c, o.0) })?;
+ // with_default_context(|c, _| unsafe { flake_lock_flags_set_mode_virtual(c, o.0) })?;
Ok(o)
}
@@ -432,14 +435,15 @@
Ok((Self(out), fragment))
}
- #[instrument(name = "lock-flake", skip(self, fetch))]
- pub fn lock(&mut self, fetch: &FetchSettings) -> Result<LockedFlake> {
- let mut settings = FlakeSettings::new()?;
- let lock_flags = FlakeLockFlags::new(&mut settings)?;
- with_default_context(|c, es| unsafe {
- flake_lock(c, fetch.0, settings.0, es, lock_flags.0, self.0)
- })
- .map(LockedFlake)
+ #[instrument(name = "lock-flake", skip(self, fetch, flake, lock))]
+ pub fn lock(
+ &mut self,
+ fetch: &FetchSettings,
+ flake: &FlakeSettings,
+ lock: &FlakeLockFlags,
+ ) -> Result<LockedFlake> {
+ with_default_context(|c, es| unsafe { flake_lock(c, fetch.0, flake.0, es, lock.0, self.0) })
+ .map(LockedFlake)
}
}
unsafe impl Send for FlakeReference {}
@@ -611,8 +615,17 @@
.expect("get_type should not fail");
NixType::from_int(ty)
}
+ fn builtin_to_string(&self) -> Result<Self> {
+ let builtin = Self::eval("builtins.toString")?;
+ builtin.call(self.clone())
+ }
pub fn to_string(&self) -> Result<String> {
- Ok(self.to_realised_string()?.as_str().to_owned())
+ let mut str_out = String::new();
+ with_default_context(|c, _| unsafe {
+ get_string(c, self.0, Some(copy_nix_str), (&raw mut str_out).cast())
+ })?;
+
+ Ok(str_out)
}
pub fn to_realised_string(&self) -> Result<RealisedString> {
with_default_context(|c, es| unsafe { nix_raw::string_realise(c, es, self.0, false) })
@@ -751,10 +764,11 @@
self.clone()
};
// to_string here blocks until the path is built
- let drv_path = tokio::task::spawn_blocking(move || v.get_field("outPath")?.to_string())
- .await
- .expect("should not fail")?;
- Ok(PathBuf::from(drv_path))
+ let drv_path =
+ tokio::task::spawn_blocking(move || v.builtin_to_string()?.to_realised_string())
+ .await
+ .expect("spawn should not fail")?;
+ Ok(PathBuf::from(drv_path.as_str()))
}
pub fn as_json<T: DeserializeOwned>(&self) -> Result<T> {
let to_json = Self::eval("builtins.toJSON")?;
@@ -835,6 +849,9 @@
pub fn init_libraries() {
unsafe { nix_raw::GC_allow_register_threads() };
+ unsafe {
+ nix_raw::GC_init();
+ };
let mut ctx = NixContext::new();
ctx.run_in_context(|c| unsafe { nix_raw::libutil_init(c) })
crates/nix-eval/src/logging.ccdiffbeforeafterboth--- a/crates/nix-eval/src/logging.cc
+++ b/crates/nix-eval/src/logging.cc
@@ -60,5 +60,6 @@
extern "C" {
void apply_tracing_logger() {
logger = std::make_unique<TracingLogger>();
+ // verbosity = lvlVomit;
}
}
crates/nix-eval/src/logging.rsdiffbeforeafterboth--- a/crates/nix-eval/src/logging.rs
+++ b/crates/nix-eval/src/logging.rs
@@ -8,6 +8,7 @@
};
#[cfg(feature = "indicatif")]
use tracing_indicatif::span_ext::IndicatifSpanExt as _;
+use vte::Parser;
#[derive(Debug)]
enum ActivityType {
@@ -374,6 +375,7 @@
}
};
if !s.trim().is_empty() {
+ let s = ansi_filter(s);
#[cfg(feature = "indicatif")]
{
span.pb_set_message(s);
@@ -413,7 +415,8 @@
match (&res, self.fields.as_slice()) {
// ResultType::FileLinked => todo!(),
(ResultType::BuildLogLine, [Str(s)]) => {
- info!("{s:?}");
+ let s = ansi_filter(s);
+ info!("{s}");
}
// ResultType::UntrustedPath => todo!(),
// ResultType::CorruptedPath => todo!(),
@@ -468,6 +471,68 @@
}
}
+struct AnsiFiltered {
+ output: String,
+}
+impl vte::Perform for AnsiFiltered {
+ fn print(&mut self, c: char) {
+ self.output.push(c);
+ }
+
+ fn execute(&mut self, byte: u8) {
+ // We don't want \r, bells, etc
+ if byte == b'\n' {
+ self.output.push('\n');
+ } else if byte == b'\t' {
+ // TODO: align output to the correct multiplier?
+ self.output.push('\t');
+ }
+ }
+
+ fn osc_dispatch(&mut self, _params: &[&[u8]], _bell_terminated: bool) {}
+ fn esc_dispatch(&mut self, _intermediates: &[u8], _ignore: bool, _byte: u8) {}
+
+ fn csi_dispatch(
+ &mut self,
+ params: &vte::Params,
+ _intermediates: &[u8],
+ _ignore: bool,
+ action: char,
+ ) {
+ use std::fmt::Write;
+ if action != 'm' {
+ // Only plain colors are enabled, everything other might corrupt the output
+ return;
+ }
+ self.output.push_str("IDK\x1b[");
+ for (i, par) in params.iter().enumerate() {
+ if i != 0 {
+ let _ = write!(self.output, ";");
+ }
+ for (i, sub) in par.iter().enumerate() {
+ if i != 0 {
+ let _ = write!(self.output, ":");
+ }
+ let _ = write!(self.output, "{sub}");
+ }
+ }
+ self.output.push(action);
+ }
+}
+fn ansi_filter(i: &str) -> String {
+ let mut out = AnsiFiltered {
+ output: String::new(),
+ };
+ let mut parser = Parser::new();
+
+ // For some reason it gets stuck with longer inputs
+ for chunk in i.as_bytes().chunks(50) {
+ parser.advance(&mut out, chunk);
+ }
+
+ out.output
+}
+
#[cxx::bridge]
pub mod nix_logging_cxx {
extern "Rust" {
flake.lockdiffbeforeafterboth--- a/flake.lock
+++ b/flake.lock
@@ -104,10 +104,10 @@
"nixpkgs-regression": "nixpkgs-regression"
},
"locked": {
- "lastModified": 1757000273,
+ "lastModified": 1757031817,
"owner": "deltarocks",
"repo": "nix",
- "rev": "eba1f549ec21208cf98343f1351a95e2e6eb3fbb",
+ "rev": "2261305161dc02496c8aedcdda14ace04b9b1dc1",
"type": "github"
},
"original": {
lib/flakePart.nixdiffbeforeafterboth--- a/lib/flakePart.nix
+++ b/lib/flakePart.nix
@@ -65,25 +65,28 @@
normalEval = bootstrapNixpkgs.lib.evalModules {
modules = (import ../modules/module-list.nix) ++ [
module
- ({inputs', ...}: {
- config = {
- data = if isPath data then import data else data;
- nixpkgs.buildUsing = mkOptionDefault bootstrapNixpkgs;
- nixpkgs.overlays = [
- (final: prev: {
- inherit
- (import ../pkgs {
- inherit (prev) callPackage;
- inherit inputs';
- craneLib = crane.mkLib prev;
- })
- fleet-install-secrets
- fleet-generator-helper
- ;
- })
- ];
- };
- })
+ (
+ { inputs', ... }:
+ {
+ config = {
+ data = if isPath data then import data else data;
+ nixpkgs.buildUsing = mkOptionDefault bootstrapNixpkgs;
+ nixpkgs.overlays = [
+ (final: prev: {
+ inherit
+ (import ../pkgs {
+ inherit (prev) callPackage;
+ inherit inputs';
+ craneLib = crane.mkLib prev;
+ })
+ fleet-install-secrets
+ fleet-generator-helper
+ ;
+ })
+ ];
+ };
+ }
+ )
];
specialArgs = {
inherit inputs self;