Merge pull request #164 from nix-community/improve-malformed-gen-log

tool: improve log message about malformed gens
This commit is contained in:
nikstur 2023-04-27 17:44:26 +02:00 committed by GitHub
commit c60e039ee9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 12 deletions

View File

@ -1,8 +1,9 @@
use std::collections::BTreeMap; use std::collections::{BTreeMap, BTreeSet};
use std::fs; use std::fs;
use std::os::unix::prelude::PermissionsExt; use std::os::unix::prelude::PermissionsExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use std::string::ToString;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use nix::unistd::sync; use nix::unistd::sync;
@ -18,7 +19,7 @@ use crate::systemd::SystemdVersion;
use crate::utils::{file_hash, SecureTempDirExt}; use crate::utils::{file_hash, SecureTempDirExt};
pub struct Installer { pub struct Installer {
enable_gc: bool, broken_gens: BTreeSet<u64>,
gc_roots: Roots, gc_roots: Roots,
lanzaboote_stub: PathBuf, lanzaboote_stub: PathBuf,
systemd: PathBuf, systemd: PathBuf,
@ -44,7 +45,7 @@ impl Installer {
gc_roots.extend(esp_paths.to_iter()); gc_roots.extend(esp_paths.to_iter());
Self { Self {
enable_gc: true, broken_gens: BTreeSet::new(),
gc_roots, gc_roots,
lanzaboote_stub, lanzaboote_stub,
systemd, systemd,
@ -87,7 +88,7 @@ impl Installer {
self.install_systemd_boot()?; self.install_systemd_boot()?;
if self.enable_gc { if self.broken_gens.is_empty() {
log::info!("Collecting garbage..."); log::info!("Collecting garbage...");
// Only collect garbage in these two directories. This way, no files that do not belong to // Only collect garbage in these two directories. This way, no files that do not belong to
// the NixOS installation are deleted. Lanzatool takes full control over the esp/EFI/nixos // the NixOS installation are deleted. Lanzatool takes full control over the esp/EFI/nixos
@ -104,16 +105,15 @@ impl Installer {
.map_or(false, |n| n.starts_with("nixos-")) .map_or(false, |n| n.starts_with("nixos-"))
})?; })?;
} else { } else {
// Garbage collection can only be disabled if there are malformed generations. If // This might produce a ridiculous message if you have a lot of malformed generations.
// garbage collection can ever be disabled differently, the below log message most let warning = indoc::formatdoc! {"
// likely does not make sense anymore.
log::warn!(indoc::indoc! {"
Garbage collection is disabled because you have malformed NixOS generations that do Garbage collection is disabled because you have malformed NixOS generations that do
not contain a readable bootspec document. not contain a readable bootspec document.
Remove the malformed generations with `nix-env --delete-generations` to re-enable Remove the malformed generations to re-enable garbage collection with
garbage collection. `nix-env --delete-generations {}`
"}) ", self.broken_gens.iter().map(ToString::to_string).collect::<Vec<String>>().join(" ")};
log::warn!("{warning}");
}; };
log::info!("Successfully installed Lanzaboote."); log::info!("Successfully installed Lanzaboote.");
@ -192,7 +192,7 @@ impl Installer {
// to manually intervene by getting rid of the old generations to re-enable // to manually intervene by getting rid of the old generations to re-enable
// garbage collection. This safeguard against catastrophic failure in case of // garbage collection. This safeguard against catastrophic failure in case of
// unhandled upstream changes to NixOS. // unhandled upstream changes to NixOS.
self.enable_gc = false; self.broken_gens.insert(link.version);
} }
generation_result.ok() generation_result.ok()