use std::path::{Path, PathBuf};
const SLIM_INPUTS: &[&str] = &[
"flake.nix",
"flake.lock",
".flk/config.nix",
".flk/pins.nix",
];
const LEGACY_INPUTS: &[&str] = &[
"flake.nix",
"flake.lock",
".flk/default.nix",
".flk/pins.nix",
".flk/overlays.nix",
];
fn is_slim_layout() -> bool {
Path::new(".flk/config.nix").exists()
}
fn base_inputs() -> &'static [&'static str] {
if is_slim_layout() {
SLIM_INPUTS
} else {
LEGACY_INPUTS
}
}
pub(crate) fn profile_cache_inputs(profile: &str) -> Vec<PathBuf> {
let mut paths = base_inputs().iter().map(PathBuf::from).collect::<Vec<_>>();
paths.push(Path::new(".flk/profiles").join(format!("{profile}.nix")));
paths
}
pub(crate) fn profile_cache_hook_inputs(profile_expr: &str) -> String {
base_inputs()
.iter()
.map(|path| format!("\"{path}\""))
.chain(std::iter::once(format!(
"\".flk/profiles/{profile_expr}.nix\""
)))
.collect::<Vec<_>>()
.join(" ")
}