use std::fs;
use crate::config::Config;
use crate::error::{Error, Result};
use crate::nix::Nix;
use crate::profile::get_flake_dir;
use super::{info, success};
pub fn run(config: &Config) -> Result<()> {
let flake_dir = get_flake_dir(config)?;
let flake_path = flake_dir.join("flake.nix");
if !flake_path.exists() {
return Err(Error::NoFlakeFound(flake_path.display().to_string()));
}
info(&format!(
"Syncing packages with {}...",
flake_path.display()
));
info("Building nixy environment...");
if let Some(parent) = config.env_link.parent() {
fs::create_dir_all(parent)?;
}
Nix::build(&flake_dir, "default", &config.env_link)?;
success("Sync complete");
Ok(())
}