difftreelog
fix make indicatif optional
in: trunk
7 files changed
cmds/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"]
cmds/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]
cmds/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"] }
crates/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"]
crates/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:?}");
}
lib/fleetLib.nixdiffbeforeafterboth1# Shared functions for fleet configuration, available as `fleet` module argument2{3 nixpkgs,4 hostNames,5}:6with nixpkgs.lib; rec {7 hostsToAttrs = f:8 listToAttrs (9 map (name: {10 inherit name;11 value = f name;12 })13 hostNames14 );15 hostsCartesian = remove null (16 unique (17 crossLists18 (19 a: b:20 if a == b21 then null22 else hostsPair a b23 ) [hostNames hostNames]24 )25 );26 hostsPair = this: other: let27 sorted = sort (a: b: a < b) [this other];28 in {29 a = elemAt sorted 0;30 b = elemAt sorted 1;31 };32 hostPairName = this: other:33 if this < other34 then "${this}-${other}"35 else "${other}-${this}";3637 # For places, where fleet knows better than nixpkgs defaults38 mkFleetDefault = mkOverride 999;39}1# Shared functions for fleet configuration, available as `fleet` module argument2{3 nixpkgs,4 hostNames,5}:6with nixpkgs.lib; rec {7 hostsToAttrs = f:8 listToAttrs (9 map (name: {10 inherit name;11 value = f name;12 })13 hostNames14 );15 hostsCartesian = remove null (16 unique (17 crossLists18 (19 a: b:20 if a == b21 then null22 else hostsPair a b23 ) [hostNames hostNames]24 )25 );26 hostsPair = this: other: let27 sorted = sort (a: b: a < b) [this other];28 in {29 a = elemAt sorted 0;30 b = elemAt sorted 1;31 };32 hostPairName = this: other:33 if this < other34 then "${this}-${other}"35 else "${other}-${this}";3637 # mkDefault = mkOverride 100038 # For places, where fleet knows better than nixpkgs defaults.39 mkFleetDefault = mkOverride 999;40 # Some generators use mkDefault, but optionDefault is set by nixpkgs.41 mkFleetGeneratorDefault = mkOverride 1001;42}modules/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;
})
];
};