git.delta.rocks / jrsonnet / refs/commits / 754b45cdacd0

difftreelog

fix make indicatif optional

Yaroslav Bolyukin2024-03-24parent: #9b6d5bf.patch.diff
in: trunk

7 files changed

modifiedcmds/fleet/Cargo.tomldiffbeforeafterboth
--- a/cmds/fleet/Cargo.toml
+++ b/cmds/fleet/Cargo.toml
@@ -22,26 +22,29 @@
 base64 = "0.21"
 chrono = { version = "0.4", features = ["serde"] }
 z85 = "3.0"
-clap = { version = "4.5", features = [
-	"derive",
-	"env",
-	"wrap_help",
-	"unicode",
-] }
+clap = { version = "4.5", features = ["derive", "env", "wrap_help", "unicode"] }
 tracing = "0.1"
 tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
 tokio-util = { version = "0.7", features = ["codec"] }
 async-trait = "0.1"
 futures = "0.3"
-tracing-indicatif = "0.3"
-indicatif = "0.17"
 itertools = "0.12"
 shlex = "1.3"
 tabled = { version = "0.15" }
-owo-colors = { version = "4.0", features = ["supports-color", "supports-colors"] }
+owo-colors = { version = "4.0", features = [
+	"supports-color",
+	"supports-colors",
+] }
 r2d2 = "0.8.10"
 abort-on-drop = "0.2"
 unindent = "0.2"
 regex = "1.10"
 openssh = "0.10"
-human-repr = "1.1"
+
+tracing-indicatif = { version = "0.3", optional = true }
+human-repr = { version = "1.1", optional = true }
+indicatif = { version = "0.17", optional = true }
+
+[features]
+# Not quite stable
+indicatif = ["tracing-indicatif", "dep:indicatif", "human-repr", "better-command/indicatif"]
modifiedcmds/fleet/src/main.rsdiffbeforeafterboth
--- a/cmds/fleet/src/main.rs
+++ b/cmds/fleet/src/main.rs
@@ -26,10 +26,13 @@
 use futures::stream::FuturesUnordered;
 use futures::TryStreamExt;
 use host::{Config, FleetOpts};
+#[cfg(feature = "indicatif")]
 use human_repr::HumanCount;
+#[cfg(feature = "indicatif")]
 use indicatif::{ProgressState, ProgressStyle};
 use tracing::{error, info};
 use tracing::{info_span, Instrument};
+#[cfg(feature = "indicatif")]
 use tracing_indicatif::IndicatifLayer;
 use tracing_subscriber::{prelude::*, EnvFilter};
 
@@ -108,6 +111,7 @@
 }
 
 fn setup_logging() {
+	#[cfg(feature = "indicatif")]
 	let indicatif_layer = IndicatifLayer::new().with_progress_style(
 		ProgressStyle::with_template(
 			"{color_start}{span_child_prefix} {span_name}{{{span_fields}}}{color_end} {wide_msg} {color_start}{download_progress} {elapsed}{color_end}",
@@ -127,6 +131,7 @@
 		.with_key(
 			"color_start",
 			|state: &ProgressState, writer: &mut dyn std::fmt::Write| {
+				use std::time::Duration;
 				let elapsed = state.elapsed();
 
 				if elapsed > Duration::from_secs(60) {
@@ -150,16 +155,18 @@
 
 	let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
 
-	tracing_subscriber::registry()
-		.with(
-			tracing_subscriber::fmt::layer()
-				.without_time()
-				.with_target(true)
-				.with_writer(indicatif_layer.get_stdout_writer())
-				.with_filter(filter), // .withou,
-		)
-		.with(indicatif_layer)
-		.init();
+	let reg = tracing_subscriber::registry().with({
+		let sub = tracing_subscriber::fmt::layer()
+			.without_time()
+			.with_target(true);
+		#[cfg(feature = "indicatif")]
+		let sub = sub.with_writer(indicatif_layer.get_stdout_writer());
+		sub.with_filter(filter) // .withou,
+	});
+	// #[cfg(feature = "indicatif")]
+	#[cfg(feature = "indicatif")]
+	let reg = reg.with(indicatif_layer);
+	reg.init();
 }
 
 #[tokio::main]
modifiedcmds/install-secrets/Cargo.tomldiffbeforeafterboth
--- a/cmds/install-secrets/Cargo.toml
+++ b/cmds/install-secrets/Cargo.toml
@@ -6,7 +6,7 @@
 [dependencies]
 age = { version = "0.10.0", features = ["ssh"] }
 anyhow = "1.0.79"
-tracing-subscriber = "0.3"
+tracing-subscriber = { version = "0.3", features = ["env-filter"] }
 tracing = "0.1"
 nix = {version = "0.27.1", features = ["user", "fs"]}
 serde = { version = "1.0.196", features = ["derive"] }
modifiedcrates/better-command/Cargo.tomldiffbeforeafterboth
--- a/crates/better-command/Cargo.toml
+++ b/crates/better-command/Cargo.toml
@@ -9,4 +9,8 @@
 serde = { version = "1.0", features = ["derive"] }
 serde_json = "1.0"
 tracing = "0.1"
-tracing-indicatif = "0.3"
+
+tracing-indicatif = { version = "0.3", optional = true }
+
+[features]
+indicatif = ["tracing-indicatif"]
modifiedcrates/better-command/src/handler.rsdiffbeforeafterboth
6use once_cell::sync::Lazy;6use once_cell::sync::Lazy;
7use regex::Regex;7use regex::Regex;
8use serde::Deserialize;8use serde::Deserialize;
9use tracing::{Span, info, warn, info_span};9use tracing::{info, info_span, warn, Span};
10#[cfg(feature = "indicatif")]
10use tracing_indicatif::span_ext::IndicatifSpanExt as _;11use tracing_indicatif::span_ext::IndicatifSpanExt as _;
1112
12pub trait Handler: Send {13pub trait Handler: Send {
141 }142 }
142 info!(target: "nix","building {}", drv);143 info!(target: "nix","building {}", drv);
143 let span = info_span!("build", drv);144 let span = info_span!("build", drv);
145 #[cfg(feature = "indicatif")]
144 span.pb_start();146 span.pb_start();
145 self.spans.insert(id, span);147 self.spans.insert(id, span);
146 } else {148 } else {
167 }169 }
168 info!(target: "nix","copying {} {} -> {}", drv, from, to);170 info!(target: "nix","copying {} {} -> {}", drv, from, to);
169 let span = info_span!("copy", from, to, drv);171 let span = info_span!("copy", from, to, drv);
172 #[cfg(feature = "indicatif")]
170 span.pb_start();173 span.pb_start();
171 self.spans.insert(id, span);174 self.spans.insert(id, span);
172 } else {175 } else {
183 && !(text.starts_with("copying '") && text.ends_with("' to the store"))186 && !(text.starts_with("copying '") && text.ends_with("' to the store"))
184 {187 {
185 let span = info_span!("job");188 let span = info_span!("job");
189 #[cfg(feature = "indicatif")]
190 {
186 span.pb_start();191 span.pb_start();
187 span.pb_set_message(&process_message(text.trim()));192 span.pb_set_message(&process_message(text.trim()));
193 }
188 self.spans.insert(id, span);194 self.spans.insert(id, span);
189 info!(target: "nix", "{}", text);195 info!(target: "nix", "{}", text);
190 }196 }
254 }260 }
255 }261 }
256 let span = info_span!("waiting on drv", drv);262 let span = info_span!("waiting on drv", drv);
263 #[cfg(feature = "indicatif")]
257 span.pb_start();264 span.pb_start();
258 self.spans.insert(id, span);265 self.spans.insert(id, span);
259 // Concurrent build of the same message266 // Concurrent build of the same message
264 NixLog::Result { fields, id, typ } if typ == 101 && !fields.is_empty() => {271 NixLog::Result { fields, id, typ } if typ == 101 && !fields.is_empty() => {
265 if let Some(span) = self.spans.get(&id) {272 if let Some(span) = self.spans.get(&id) {
266 if let LogField::String(s) = &fields[0] {273 if let LogField::String(s) = &fields[0] {
274 #[cfg(feature = "indicatif")]
267 span.pb_set_message(&process_message(s.trim()));275 span.pb_set_message(&process_message(s.trim()));
276 #[cfg(not(feature = "indicatif"))]
277 info!("{}", process_message(s));
268 } else {278 } else {
269 warn!("bad fields: {fields:?}");279 warn!("bad fields: {fields:?}");
270 }280 }
278 if let [LogField::Num(done), LogField::Num(expected), LogField::Num(_running), LogField::Num(_failed)] =288 if let [LogField::Num(done), LogField::Num(expected), LogField::Num(_running), LogField::Num(_failed)] =
279 &fields[..4]289 &fields[..4]
290 {
291 #[cfg(feature = "indicatif")]
280 {292 {
281 span.pb_set_length(*expected);293 span.pb_set_length(*expected);
282 span.pb_set_position(*done);294 span.pb_set_position(*done);
283 } else {295 }
296 let _ = (span, done, expected);
297 } else {
284 warn!("bad fields: {fields:?}");298 warn!("bad fields: {fields:?}");
285 }299 }
modifiedlib/fleetLib.nixdiffbeforeafterboth
--- a/lib/fleetLib.nix
+++ b/lib/fleetLib.nix
@@ -34,6 +34,9 @@
     then "${this}-${other}"
     else "${other}-${this}";
 
-  # For places, where fleet knows better than nixpkgs defaults
+  # mkDefault = mkOverride 1000
+  # For places, where fleet knows better than nixpkgs defaults.
   mkFleetDefault = mkOverride 999;
+  # Some generators use mkDefault, but optionDefault is set by nixpkgs.
+  mkFleetGeneratorDefault = mkOverride 1001;
 }
modifiedmodules/fleet/meta.nixdiffbeforeafterboth
--- a/modules/fleet/meta.nix
+++ b/modules/fleet/meta.nix
@@ -34,9 +34,14 @@
           type = unspecified;
           description = "Nixos configuration";
         };
+        nixpkgs = mkOption {
+          type = unspecified;
+          description = "Nixpkgs override";
+          default = nixpkgs;
+        };
       };
       config = {
-        nixosSystem = nixpkgs.lib.nixosSystem {
+        nixosSystem = hostConfig.config.nixpkgs.lib.nixosSystem {
           inherit (hostConfig.config) system modules;
           specialArgs = {
             inherit fleetLib;
@@ -45,7 +50,7 @@
         };
         modules = [
           ({...}: {
-            networking.hostName = mkFleetDefault hostName;
+            networking.hostName = mkFleetGeneratorDefault hostName;
           })
         ];
       };