fix: fix "Nix" step to use nix upgrade-nix in more situations (#550)
`nix upgrade-nix` can be used on any platform except NixOS where `nix` is available. Also use `nix profile upgrade --verbose` because the non-verbose mode doesn't print anything on stdout.
This commit is contained in:
@@ -417,7 +417,7 @@ pub fn run_pip3_update(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
Command::new(&python3)
|
Command::new(&python3)
|
||||||
.args(["-m", "pip"])
|
.args(["-m", "pip"])
|
||||||
.output_checked_utf8()
|
.output_checked_utf8()
|
||||||
.map_err(|_| SkipStep("pip does not exists".to_string()))?;
|
.map_err(|_| SkipStep("pip does not exist".to_string()))?;
|
||||||
|
|
||||||
let check_externally_managed = "import sysconfig; from os import path; print('Y') if path.isfile(path.join(sysconfig.get_path('stdlib'), 'EXTERNALLY-MANAGED')) else print('N')";
|
let check_externally_managed = "import sysconfig; from os import path; print('Y') if path.isfile(path.join(sysconfig.get_path('stdlib'), 'EXTERNALLY-MANAGED')) else print('N')";
|
||||||
Command::new(&python3)
|
Command::new(&python3)
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ impl Git {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => match e.kind() {
|
Err(e) => match e.kind() {
|
||||||
io::ErrorKind::NotFound => debug!("{} does not exists", path.as_ref().display()),
|
io::ErrorKind::NotFound => debug!("{} does not exist", path.as_ref().display()),
|
||||||
_ => error!("Error looking for {}: {}", path.as_ref().display(), e),
|
_ => error!("Error looking for {}: {}", path.as_ref().display(), e),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ use home;
|
|||||||
use ini::Ini;
|
use ini::Ini;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
use super::linux::Distribution;
|
||||||
use crate::error::SkipStep;
|
use crate::error::SkipStep;
|
||||||
use crate::execution_context::ExecutionContext;
|
use crate::execution_context::ExecutionContext;
|
||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
@@ -363,24 +365,23 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
debug!("nix profile: {:?}", profile_path);
|
debug!("nix profile: {:?}", profile_path);
|
||||||
let manifest_json_path = profile_path.join("manifest.json");
|
let manifest_json_path = profile_path.join("manifest.json");
|
||||||
|
|
||||||
let output = Command::new(&nix_env).args(["--query", "nix"]).output_checked_utf8();
|
// Should we attempt to upgrade Nix with `nix upgrade-nix`?
|
||||||
debug!("nix-env output: {:?}", output);
|
#[allow(unused_mut)]
|
||||||
let should_self_upgrade = output.is_ok();
|
let mut should_self_upgrade = cfg!(target_os = "macos");
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
{
|
||||||
|
// We can't use `nix upgrade-nix` on NixOS.
|
||||||
|
if let Ok(Distribution::NixOS) = Distribution::detect() {
|
||||||
|
should_self_upgrade = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print_separator("Nix");
|
print_separator("Nix");
|
||||||
|
|
||||||
let multi_user = fs::metadata(&nix)?.uid() == 0;
|
let multi_user = fs::metadata(&nix)?.uid() == 0;
|
||||||
debug!("Multi user nix: {}", multi_user);
|
debug!("Multi user nix: {}", multi_user);
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
{
|
|
||||||
use super::linux::Distribution;
|
|
||||||
|
|
||||||
if let Ok(Distribution::NixOS) = Distribution::detect() {
|
|
||||||
return Err(SkipStep(String::from("Nix on NixOS must be upgraded via nixos-rebuild switch")).into());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
if require("darwin-rebuild").is_ok() {
|
if require("darwin-rebuild").is_ok() {
|
||||||
@@ -393,11 +394,20 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
|
|
||||||
let run_type = ctx.run_type();
|
let run_type = ctx.run_type();
|
||||||
|
|
||||||
|
let nix_args = ["--extra-experimental-features", "nix-command"];
|
||||||
|
|
||||||
if should_self_upgrade {
|
if should_self_upgrade {
|
||||||
if multi_user {
|
if multi_user {
|
||||||
ctx.execute_elevated(&nix, true)?.arg("upgrade-nix").status_checked()?;
|
ctx.execute_elevated(&nix, true)?
|
||||||
|
.args(nix_args)
|
||||||
|
.arg("upgrade-nix")
|
||||||
|
.status_checked()?;
|
||||||
} else {
|
} else {
|
||||||
run_type.execute(&nix).arg("upgrade-nix").status_checked()?;
|
run_type
|
||||||
|
.execute(&nix)
|
||||||
|
.args(nix_args)
|
||||||
|
.arg("upgrade-nix")
|
||||||
|
.status_checked()?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -406,12 +416,14 @@ pub fn run_nix(ctx: &ExecutionContext) -> Result<()> {
|
|||||||
if Path::new(&manifest_json_path).exists() {
|
if Path::new(&manifest_json_path).exists() {
|
||||||
run_type
|
run_type
|
||||||
.execute(&nix)
|
.execute(&nix)
|
||||||
|
.args(nix_args)
|
||||||
.arg("profile")
|
.arg("profile")
|
||||||
.arg("upgrade")
|
.arg("upgrade")
|
||||||
.arg(".*")
|
.arg(".*")
|
||||||
|
.arg("--verbose")
|
||||||
.status_checked()
|
.status_checked()
|
||||||
} else {
|
} else {
|
||||||
run_type.execute(&nix_env).arg("--upgrade").status_checked()
|
run_type.execute(nix_env).arg("--upgrade").status_checked()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user