Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/action/common/provision_determinate_nixd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{

use super::place_nix_configuration::{NIX_CONF, NIX_CONF_FOLDER};

const DETERMINATE_NIXD_BINARY_PATH: &str = "/usr/local/bin/determinate-nixd";
pub const DETERMINATE_NIXD_BINARY_PATH: &str = "/usr/local/bin/determinate-nixd";
/**
Provision the determinate-nixd binary
*/
Expand Down
33 changes: 33 additions & 0 deletions src/cli/subcommand/install/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
mod determinate;

use std::{
io::Write,
os::unix::prelude::PermissionsExt,
path::{Path, PathBuf},
process::ExitCode,
};

use crate::{
action::common::provision_determinate_nixd::DETERMINATE_NIXD_BINARY_PATH,
cli::{
ensure_root,
interaction::{self, PromptChoice},
Expand All @@ -26,6 +28,7 @@ use color_eyre::{
Section,
};
use owo_colors::OwoColorize;
use url::Url;

const EXISTING_INCOMPATIBLE_PLAN_GUIDANCE: &str = "\
If you are trying to upgrade Nix, try running `sudo -i nix upgrade-nix` instead.\n\
Expand Down Expand Up @@ -66,6 +69,9 @@ pub struct Install {
)]
pub explain: bool,

#[clap(long, env = "NIX_INSTALLER_DETERMINATE_NIXD_INSTALL_URL")]
determinate_nixd_install_url: Option<Url>,

/// A path to a non-default installer plan
#[clap(env = "NIX_INSTALLER_PLAN")]
pub plan: Option<PathBuf>,
Expand All @@ -87,6 +93,7 @@ impl CommandExecute for Install {
planner: maybe_planner,
settings,
explain,
determinate_nixd_install_url,
} = self;

ensure_root()?;
Expand Down Expand Up @@ -218,6 +225,12 @@ impl CommandExecute for Install {
// Attempt to copy self to the store if possible, but since the install failed, this might not work, that's ok.
copy_self_to_nix_dir().await.ok();

// If an explicit Determinate Nixd installation URL is provided, download that to the expected
// path on disk.
if let Some(determinate_nixd_install_url) = determinate_nixd_install_url {
download_determinate_nixd(&determinate_nixd_install_url.to_string()).await?;
}

if !no_confirm {
let mut was_expected = false;
if let Some(expected) = err.expected() {
Expand Down Expand Up @@ -352,3 +365,23 @@ async fn copy_self_to_nix_dir() -> Result<(), std::io::Error> {
tokio::fs::set_permissions("/nix/nix-installer", PermissionsExt::from_mode(0o0755)).await?;
Ok(())
}

// By default, Determinate Nixd is loaded from on disk. This download logic is used only if a
// Determinate Nixd download URL is specified.
#[tracing::instrument(level = "debug")]
async fn download_determinate_nixd(determinate_nixd_install_url: &str) -> color_eyre::Result<()> {
let response = reqwest::get(determinate_nixd_install_url)
.await?
.error_for_status()?
.bytes()
.await?;

let mut tempfile = tempfile::NamedTempFile::new_in("/usr/local/bin/")?;
let file = tempfile.as_file_mut();

file.write_all(&response)?;
file.set_permissions(std::fs::Permissions::from_mode(0o555))?;
tempfile.persist(DETERMINATE_NIXD_BINARY_PATH)?;

Ok(())
}
4 changes: 2 additions & 2 deletions src/planner/macos/profile_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl TargetProfileHardDiskInternalOpts<'_> {
}
}

fn flatten(policies: &Policies) -> impl Iterator<Item = TargetProfileItem> {
fn flatten(policies: &Policies) -> impl Iterator<Item = TargetProfileItem<'_>> {
policies
.iter()
.flat_map(|(target, profiles): (&Target, &Vec<Profile>)| {
Expand All @@ -62,7 +62,7 @@ fn flatten(policies: &Policies) -> impl Iterator<Item = TargetProfileItem> {
})
}

pub fn blocks_internal_mounting(policies: &Policies) -> Vec<TargetProfileHardDiskInternalOpts> {
pub fn blocks_internal_mounting(policies: &Policies) -> Vec<TargetProfileHardDiskInternalOpts<'_>> {
flatten(policies)
.filter_map(move |target_profile_item| {
let ProfileItem::SystemUIServer(system_ui_server) = target_profile_item.item else {
Expand Down
6 changes: 0 additions & 6 deletions src/profile/nixprofile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,6 @@ impl NixProfile<'_> {
}
}

#[derive(Debug, serde::Deserialize)]
struct PackageInfo {
#[serde(default)]
outputs: HashMap<String, PathBuf>,
}

fn collect_children<P: AsRef<std::path::Path>>(
base_path: P,
) -> Result<HashSet<PathBuf>, std::io::Error> {
Expand Down
Loading