From 3797fc7bae3fbeda3b12565c16eb1ec505622b05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sch=C3=B6nauer?= <37108907+DottoDev@users.noreply.github.com> Date: Sat, 22 Oct 2022 09:26:49 +0000 Subject: [PATCH] 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> --- src/steps/os/unix.rs | 18 +++++++++++++++++- src/steps/zsh.rs | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/steps/os/unix.rs b/src/steps/os/unix.rs index cdbc9ad3..b392749c 100644 --- a/src/steps/os/unix.rs +++ b/src/steps/os/unix.rs @@ -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<()> { diff --git a/src/steps/zsh.rs b/src/steps/zsh.rs index 01c2de99..25a5e25d 100644 --- a/src/steps/zsh.rs +++ b/src/steps/zsh.rs @@ -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() }