Skip to content
Draft
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
10 changes: 5 additions & 5 deletions src/action/common/configure_init_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl Action for ConfigureInitService {
let service_dest = service_dest
.as_ref()
.expect("service_dest should be set for Launchd");
let service = service_name
let service_name = service_name
.as_ref()
.expect("service_name should be set for Launchd");
let domain = DARWIN_LAUNCHD_DOMAIN;
Expand All @@ -259,27 +259,27 @@ impl Action for ConfigureInitService {
})?;
}

crate::action::macos::retry_bootstrap(domain, service, service_dest)
crate::action::macos::retry_bootstrap(domain, service_name, service_dest)
.await
.map_err(Self::error)?;

let is_disabled = crate::action::macos::service_is_disabled(domain, service)
let is_disabled = crate::action::macos::service_is_disabled(domain, service_name)
.await
.map_err(Self::error)?;
if is_disabled {
execute_command(
Command::new("launchctl")
.process_group(0)
.arg("enable")
.arg(format!("{domain}/{service}"))
.arg(format!("{domain}/{service_name}"))
.stdin(std::process::Stdio::null()),
)
.await
.map_err(Self::error)?;
}

if *start_daemon {
crate::action::macos::retry_kickstart(domain, service)
crate::action::macos::retry_kickstart(domain, service_name)
.await
.map_err(Self::error)?;
}
Expand Down
26 changes: 13 additions & 13 deletions src/action/macos/bootstrap_launchctl_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ Bootstrap and kickstart an APFS volume
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(tag = "action_name", rename = "bootstrap_launchctl_service")]
pub struct BootstrapLaunchctlService {
service: String,
service_name: String,
path: PathBuf,
is_present: bool,
is_disabled: bool,
}

impl BootstrapLaunchctlService {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn plan(service: &str, path: &str) -> Result<StatefulAction<Self>, ActionError> {
let service = service.to_owned();
pub async fn plan(service_name: &str, path: &str) -> Result<StatefulAction<Self>, ActionError> {
let service_name = service_name.to_owned();
let path = PathBuf::from(path);

let is_present = {
let mut command = Command::new("launchctl");
command.process_group(0);
command.arg("print");
command.arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service}"));
command.arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service_name}"));
command.stdin(std::process::Stdio::null());
command.stdout(std::process::Stdio::piped());
command.stderr(std::process::Stdio::piped());
Expand All @@ -41,15 +41,15 @@ impl BootstrapLaunchctlService {
.await
.map_err(|e| Self::error(ActionErrorKind::command(&command, e)))?;
// We presume that success means it's found
command_output.status.success() || command_output.status.code() == Some(37)
command_output.status.success()
};

let is_disabled = service_is_disabled(DARWIN_LAUNCHD_DOMAIN, &service)
let is_disabled = service_is_disabled(DARWIN_LAUNCHD_DOMAIN, &service_name)
.await
.map_err(Self::error)?;

Ok(StatefulAction::uncompleted(Self {
service,
service_name,
path,
is_present,
is_disabled,
Expand All @@ -66,7 +66,7 @@ impl Action for BootstrapLaunchctlService {
fn tracing_synopsis(&self) -> String {
format!(
"Bootstrap the `{}` service via `launchctl bootstrap {} {}`",
self.service,
self.service_name,
DARWIN_LAUNCHD_DOMAIN,
self.path.display()
)
Expand All @@ -89,7 +89,7 @@ impl Action for BootstrapLaunchctlService {
#[tracing::instrument(level = "debug", skip_all)]
async fn execute(&mut self) -> Result<(), ActionError> {
let Self {
service,
service_name,
path,
is_present,
is_disabled,
Expand All @@ -100,20 +100,20 @@ impl Action for BootstrapLaunchctlService {
Command::new("launchctl")
.process_group(0)
.arg("enable")
.arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service}"))
.arg(format!("{DARWIN_LAUNCHD_DOMAIN}/{service_name}"))
.stdin(std::process::Stdio::null()),
)
.await
.map_err(Self::error)?;
}

if *is_present {
crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, service)
crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, service_name)
.await
.map_err(Self::error)?;
}

crate::action::macos::retry_bootstrap(DARWIN_LAUNCHD_DOMAIN, service, path)
crate::action::macos::retry_bootstrap(DARWIN_LAUNCHD_DOMAIN, service_name, path)
.await
.map_err(Self::error)?;

Expand All @@ -133,7 +133,7 @@ impl Action for BootstrapLaunchctlService {

#[tracing::instrument(level = "debug", skip_all)]
async fn revert(&mut self) -> Result<(), ActionError> {
crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, &self.service)
crate::action::macos::retry_bootout(DARWIN_LAUNCHD_DOMAIN, &self.service_name)
.await
.map_err(Self::error)?;

Expand Down
35 changes: 18 additions & 17 deletions src/action/macos/create_nix_volume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ use super::{
};

pub const NIX_VOLUME_MOUNTD_DEST: &str = "/Library/LaunchDaemons/org.nixos.darwin-store.plist";
pub const NIX_VOLUME_MOUNTD_NAME: &str = "org.nixos.darwin-store";

/// Create an APFS volume
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(tag = "action_name", rename = "create_nix_volume")]
pub struct CreateNixVolume {
disk: PathBuf,
name: String,
volume_label: String,
case_sensitive: bool,
encrypt: bool,
create_or_append_synthetic_conf: StatefulAction<CreateOrInsertIntoFile>,
Expand All @@ -44,7 +45,7 @@ impl CreateNixVolume {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn plan(
disk: impl AsRef<Path>,
name: String,
volume_label: String,
case_sensitive: bool,
encrypt: bool,
) -> Result<StatefulAction<Self>, ActionError> {
Expand All @@ -62,53 +63,53 @@ impl CreateNixVolume {

let create_synthetic_objects = CreateSyntheticObjects::plan().await.map_err(Self::error)?;

let create_volume = CreateApfsVolume::plan(disk, name.clone(), case_sensitive)
let create_volume = CreateApfsVolume::plan(disk, volume_label.clone(), case_sensitive)
.await
.map_err(Self::error)?;

let unmount_volume = if create_volume.state == crate::action::ActionState::Completed {
UnmountApfsVolume::plan_skip_if_already_mounted_to_nix(disk, name.clone())
UnmountApfsVolume::plan_skip_if_already_mounted_to_nix(disk, volume_label.clone())
.await
.map_err(Self::error)?
} else {
UnmountApfsVolume::plan(disk, name.clone())
UnmountApfsVolume::plan(disk, volume_label.clone())
.await
.map_err(Self::error)?
};

let create_fstab_entry = CreateFstabEntry::plan(name.clone())
let create_fstab_entry = CreateFstabEntry::plan(volume_label.clone())
.await
.map_err(Self::error)?;

let encrypt_volume = if encrypt {
Some(EncryptApfsVolume::plan(false, disk, &name, &create_volume).await?)
Some(EncryptApfsVolume::plan(false, disk, &volume_label, &create_volume).await?)
} else {
None
};

let setup_volume_daemon = CreateVolumeService::plan(
NIX_VOLUME_MOUNTD_DEST,
"org.nixos.darwin-store",
name.clone(),
NIX_VOLUME_MOUNTD_NAME,
volume_label.clone(),
"/nix",
encrypt,
)
.await
.map_err(Self::error)?;

let bootstrap_volume =
BootstrapLaunchctlService::plan("org.nixos.darwin-store", NIX_VOLUME_MOUNTD_DEST)
BootstrapLaunchctlService::plan(NIX_VOLUME_MOUNTD_NAME, NIX_VOLUME_MOUNTD_DEST)
.await
.map_err(Self::error)?;
let kickstart_launchctl_service =
KickstartLaunchctlService::plan(DARWIN_LAUNCHD_DOMAIN, "org.nixos.darwin-store")
KickstartLaunchctlService::plan(DARWIN_LAUNCHD_DOMAIN, NIX_VOLUME_MOUNTD_NAME)
.await
.map_err(Self::error)?;
let enable_ownership = EnableOwnership::plan("/nix").await.map_err(Self::error)?;

Ok(Self {
disk: disk.to_path_buf(),
name,
volume_label,
case_sensitive,
encrypt,
create_or_append_synthetic_conf,
Expand All @@ -134,9 +135,9 @@ impl Action for CreateNixVolume {
}
fn tracing_synopsis(&self) -> String {
format!(
"Create an{maybe_encrypted} APFS volume `{name}` for Nix on `{disk}` and add it to `/etc/fstab` mounting on `/nix`",
"Create an{maybe_encrypted} APFS volume `{volume_label}` for Nix on `{disk}` and add it to `/etc/fstab` mounting on `/nix`",
maybe_encrypted = if self.encrypt { " encrypted" } else { "" },
name = self.name,
volume_label = self.volume_label,
disk = self.disk.display(),
)
}
Expand All @@ -146,7 +147,7 @@ impl Action for CreateNixVolume {
tracing::Level::DEBUG,
"create_nix_volume",
disk = tracing::field::display(self.disk.display()),
name = self.name
volume_label = self.volume_label
)
}

Expand Down Expand Up @@ -188,7 +189,7 @@ impl Action for CreateNixVolume {
loop {
let mut command = Command::new("/usr/sbin/diskutil");
command.args(["info", "-plist"]);
command.arg(&self.name);
command.arg(&self.volume_label);
command.stderr(std::process::Stdio::null());
command.stdout(std::process::Stdio::null());
tracing::debug!(%retry_tokens, command = ?command.as_std(), "Checking for Nix Store volume existence");
Expand Down Expand Up @@ -261,7 +262,7 @@ impl Action for CreateNixVolume {
vec![ActionDescription::new(
format!(
"Remove the APFS volume `{}` on `{}`",
self.name,
self.volume_label,
self.disk.display()
),
explanation,
Expand Down
Loading