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
26use futures::stream::FuturesUnordered;26use futures::stream::FuturesUnordered;
27use futures::TryStreamExt;27use futures::TryStreamExt;
28use host::{Config, FleetOpts};28use host::{Config, FleetOpts};
29#[cfg(feature = "indicatif")]
29use human_repr::HumanCount;30use human_repr::HumanCount;
31#[cfg(feature = "indicatif")]
30use indicatif::{ProgressState, ProgressStyle};32use indicatif::{ProgressState, ProgressStyle};
31use tracing::{error, info};33use tracing::{error, info};
32use tracing::{info_span, Instrument};34use tracing::{info_span, Instrument};
35#[cfg(feature = "indicatif")]
33use tracing_indicatif::IndicatifLayer;36use tracing_indicatif::IndicatifLayer;
34use tracing_subscriber::{prelude::*, EnvFilter};37use tracing_subscriber::{prelude::*, EnvFilter};
3538
108}111}
109112
110fn setup_logging() {113fn setup_logging() {
114 #[cfg(feature = "indicatif")]
111 let indicatif_layer = IndicatifLayer::new().with_progress_style(115 let indicatif_layer = IndicatifLayer::new().with_progress_style(
112 ProgressStyle::with_template(116 ProgressStyle::with_template(
113 "{color_start}{span_child_prefix} {span_name}{{{span_fields}}}{color_end} {wide_msg} {color_start}{download_progress} {elapsed}{color_end}",117 "{color_start}{span_child_prefix} {span_name}{{{span_fields}}}{color_end} {wide_msg} {color_start}{download_progress} {elapsed}{color_end}",
127 .with_key(131 .with_key(
128 "color_start",132 "color_start",
129 |state: &ProgressState, writer: &mut dyn std::fmt::Write| {133 |state: &ProgressState, writer: &mut dyn std::fmt::Write| {
134 use std::time::Duration;
130 let elapsed = state.elapsed();135 let elapsed = state.elapsed();
131136
132 if elapsed > Duration::from_secs(60) {137 if elapsed > Duration::from_secs(60) {
150155
151 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));156 let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("info"));
152157
153 tracing_subscriber::registry()158 let reg = tracing_subscriber::registry().with({
154 .with(
155 tracing_subscriber::fmt::layer()159 let sub = tracing_subscriber::fmt::layer()
156 .without_time()160 .without_time()
157 .with_target(true)161 .with_target(true);
162 #[cfg(feature = "indicatif")]
158 .with_writer(indicatif_layer.get_stdout_writer())163 let sub = sub.with_writer(indicatif_layer.get_stdout_writer());
159 .with_filter(filter), // .withou,164 sub.with_filter(filter) // .withou,
160 )165 });
161 .with(indicatif_layer)166 // #[cfg(feature = "indicatif")]
162 .init();167 #[cfg(feature = "indicatif")]
168 let reg = reg.with(indicatif_layer);
169 reg.init();
163}170}
164171
165#[tokio::main]172#[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
--- a/crates/better-command/src/handler.rs
+++ b/crates/better-command/src/handler.rs
@@ -6,7 +6,8 @@
 use once_cell::sync::Lazy;
 use regex::Regex;
 use serde::Deserialize;
-use tracing::{Span, info, warn, info_span};
+use tracing::{info, info_span, warn, Span};
+#[cfg(feature = "indicatif")]
 use tracing_indicatif::span_ext::IndicatifSpanExt as _;
 
 pub trait Handler: Send {
@@ -141,6 +142,7 @@
 						}
 						info!(target: "nix","building {}", drv);
 						let span = info_span!("build", drv);
+						#[cfg(feature = "indicatif")]
 						span.pb_start();
 						self.spans.insert(id, span);
 					} else {
@@ -167,6 +169,7 @@
 						}
 						info!(target: "nix","copying {} {} -> {}", drv, from, to);
 						let span = info_span!("copy", from, to, drv);
+						#[cfg(feature = "indicatif")]
 						span.pb_start();
 						self.spans.insert(id, span);
 					} else {
@@ -183,8 +186,11 @@
 						&& !(text.starts_with("copying '") && text.ends_with("' to the store"))
 					{
 						let span = info_span!("job");
-						span.pb_start();
-						span.pb_set_message(&process_message(text.trim()));
+						#[cfg(feature = "indicatif")]
+						{
+							span.pb_start();
+							span.pb_set_message(&process_message(text.trim()));
+						}
 						self.spans.insert(id, span);
 						info!(target: "nix", "{}", text);
 					}
@@ -254,6 +260,7 @@
 						}
 					}
 					let span = info_span!("waiting on drv", drv);
+					#[cfg(feature = "indicatif")]
 					span.pb_start();
 					self.spans.insert(id, span);
 					// Concurrent build of the same message
@@ -264,7 +271,10 @@
 				NixLog::Result { fields, id, typ } if typ == 101 && !fields.is_empty() => {
 					if let Some(span) = self.spans.get(&id) {
 						if let LogField::String(s) = &fields[0] {
+							#[cfg(feature = "indicatif")]
 							span.pb_set_message(&process_message(s.trim()));
+							#[cfg(not(feature = "indicatif"))]
+							info!("{}", process_message(s));
 						} else {
 							warn!("bad fields: {fields:?}");
 						}
@@ -278,8 +288,12 @@
 						if let [LogField::Num(done), LogField::Num(expected), LogField::Num(_running), LogField::Num(_failed)] =
 							&fields[..4]
 						{
-							span.pb_set_length(*expected);
-							span.pb_set_position(*done);
+							#[cfg(feature = "indicatif")]
+							{
+								span.pb_set_length(*expected);
+								span.pb_set_position(*done);
+							}
+							let _ = (span, done, expected);
 						} else {
 							warn!("bad fields: {fields:?}");
 						}
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;
           })
         ];
       };