diff --git a/README.md b/README.md index ec2c139e..cdb49002 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Just run `topgrade`. It will run the following steps: * *Debian/Ubuntu*: Run `apt update && apt dist-upgrade` * *Linux*: Run [etc-update](https://dev.gentoo.org/~zmedico/portage/doc/man/etc-update.1.html): * *Unix*: Run `brew update && brew upgrade`. This should handle both Homebrew and Linuxbrew +* *Unix*: Run `nix upgrade-nix && nix --upgrade`. * *Windows*: Upgrade Powershell modules * *Windows*: Upgrade all [Chocolatey](https://chocolatey.org/) packages * *Windows*: Upgrade all [Scoop](https://scoop.sh) packages diff --git a/src/main.rs b/src/main.rs index 6a47c33c..6760b94b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -186,6 +186,11 @@ fn run() -> Result<(), Error> { |terminal| unix::run_homebrew(terminal, opt.dry_run), &mut execution_context, )?); + #[cfg(unix)] + report.push_result(execute( + |terminal| unix::run_nix(terminal, opt.dry_run), + &mut execution_context, + )?); if !opt.no_emacs { git_repos.insert(base_dirs.home_dir().join(".emacs.d")); diff --git a/src/unix.rs b/src/unix.rs index c86f5158..fa25e969 100644 --- a/src/unix.rs +++ b/src/unix.rs @@ -67,3 +67,30 @@ pub fn run_homebrew(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static None } + +#[must_use] +pub fn run_nix(terminal: &mut Terminal, dry_run: bool) -> Option<(&'static str, bool)> { + if let Some(nix) = which("nix") { + if let Some(nix_env) = which("nix-env") { + terminal.print_separator("Nix"); + + let inner = || -> Result<(), Error> { + Executor::new(&nix, dry_run) + .arg("upgrade-nix") + .spawn()? + .wait()? + .check()?; + Executor::new(&nix_env, dry_run) + .arg("--upgrade") + .spawn()? + .wait()? + .check()?; + Ok(()) + }; + + return Some(("Nix", inner().is_ok())); + } + } + + None +}