difftreelog
fix make indicatif optional
in: trunk
7 files changed
cmds/fleet/Cargo.tomldiffbeforeafterboth1[package]2name = "fleet"3description = "NixOS configuration management"4version = "0.2.0"5authors = ["Yaroslav Bolyukin <iam@lach.pw>"]6edition = "2021"78[dependencies]9nixlike.workspace = true10better-command.workspace = true11tokio.workspace = true12anyhow = "1.0"13serde = { version = "1.0", features = ["derive"] }14serde_json = "1.0"15time = { version = "0.3", features = ["serde"] }16tempfile = "3.10"17once_cell = "1.19"18hostname = "0.3"19age-core = "0.10"20peg = "0.8"21age = { version = "0.10", features = ["ssh", "armor"] }22base64 = "0.21"23chrono = { version = "0.4", features = ["serde"] }24z85 = "3.0"25clap = { version = "4.5", features = [26 "derive",27 "env",28 "wrap_help",29 "unicode",30] }31tracing = "0.1"32tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }33tokio-util = { version = "0.7", features = ["codec"] }34async-trait = "0.1"35futures = "0.3"36tracing-indicatif = "0.3"37indicatif = "0.17"38itertools = "0.12"39shlex = "1.3"40tabled = { version = "0.15" }41owo-colors = { version = "4.0", features = ["supports-color", "supports-colors"] }42r2d2 = "0.8.10"43abort-on-drop = "0.2"44unindent = "0.2"45regex = "1.10"46openssh = "0.10"47human-repr = "1.1"1[package]2name = "fleet"3description = "NixOS configuration management"4version = "0.2.0"5authors = ["Yaroslav Bolyukin <iam@lach.pw>"]6edition = "2021"78[dependencies]9nixlike.workspace = true10better-command.workspace = true11tokio.workspace = true12anyhow = "1.0"13serde = { version = "1.0", features = ["derive"] }14serde_json = "1.0"15time = { version = "0.3", features = ["serde"] }16tempfile = "3.10"17once_cell = "1.19"18hostname = "0.3"19age-core = "0.10"20peg = "0.8"21age = { version = "0.10", features = ["ssh", "armor"] }22base64 = "0.21"23chrono = { version = "0.4", features = ["serde"] }24z85 = "3.0"25clap = { version = "4.5", features = ["derive", "env", "wrap_help", "unicode"] }26tracing = "0.1"27tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }28tokio-util = { version = "0.7", features = ["codec"] }29async-trait = "0.1"30futures = "0.3"31itertools = "0.12"32shlex = "1.3"33tabled = { version = "0.15" }34owo-colors = { version = "4.0", features = [35 "supports-color",36 "supports-colors",37] }38r2d2 = "0.8.10"39abort-on-drop = "0.2"40unindent = "0.2"41regex = "1.10"42openssh = "0.10"4344tracing-indicatif = { version = "0.3", optional = true }45human-repr = { version = "1.1", optional = true }46indicatif = { version = "0.17", optional = true }4748[features]49# Not quite stable50indicatif = ["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.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;
}
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;
})
];
};