Fix nix profile upgrade command & add profile path detection (#56)

* Fixes antigen update (#39)

* Adds manifest.json check to nix

* #34 Fix `nix profile upgrade` command & add profile path detection (#4)

Authored-by: Manu [tennox] <2084639+tennox@users.noreply.github.com>
This commit is contained in:
Thomas Schönauer
2022-10-22 09:26:49 +00:00
committed by GitHub
parent 7b512f1e00
commit 3797fc7bae
2 changed files with 18 additions and 2 deletions

View File

@@ -277,6 +277,12 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
let nix = require("nix")?;
let nix_channel = require("nix-channel")?;
let nix_env = require("nix-env")?;
let profile_path = match env::home_dir() {
Some(home) => Path::new(&home).join(".nix-profile"),
None => Path::new("/nix/var/nix/profiles/per-user/default").into(),
};
debug!("nix profile: {:?}", profile_path);
let manifest_json_path = profile_path.join("manifest.json");
let output = Command::new(&nix_env).args(&["--query", "nix"]).check_output();
debug!("nix-env output: {:?}", output);
@@ -317,7 +323,17 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
}
run_type.execute(&nix_channel).arg("--update").check_run()?;
run_type.execute(&nix_env).arg("--upgrade").check_run()
if std::path::Path::new(&manifest_json_path).exists() {
run_type
.execute(&nix)
.arg("profile")
.arg("upgrade")
.arg(".*")
.check_run()
} else {
run_type.execute(&nix_env).arg("--upgrade").check_run()
}
}
pub fn run_yadm(ctx: &ExecutionContext) -> Result<()> {

View File

@@ -47,7 +47,7 @@ pub fn run_antigen(base_dirs: &BaseDirs, run_type: RunType) -> Result<()> {
print_separator("antigen");
let cmd = format!("source {} && antigen selfupdate && antigen update", zshrc.display());
let cmd = format!("source {} && (antigen selfupdate ; antigen update)", zshrc.display());
run_type.execute(zsh).args(&["-l", "-c", cmd.as_str()]).check_run()
}