Skip to content

Commit

Permalink
Provision DeterminateNixd very early in configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
grahamc committed Aug 8, 2024
1 parent 7e9a385 commit 34578c4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ use crate::action::{common::ConfigureInitService, Action, ActionDescription};
use crate::settings::InitSystem;

// Linux
const SERVICE_DEST: &str = "/etc/systemd/system/nix-daemon.service";
pub const DETERMINATE_NIXD_SERVICE_SRC: &str = "/nix/determinate/nix-daemon.service";
const LINUX_NIXD_DAEMON_DEST: &str = "/etc/systemd/system/nix-daemon.service";

// Darwin
const DARWIN_NIXD_DAEMON_DEST: &str = "/Library/LaunchDaemons/systems.determinate.nix-daemon.plist";
Expand All @@ -32,17 +31,9 @@ impl ConfigureDeterminateNixdInitService {
init: InitSystem,
start_daemon: bool,
) -> Result<StatefulAction<Self>, ActionError> {
let service_src: Option<PathBuf> = match init {
InitSystem::Launchd => {
// We'll write it out down in the execute step
None
},
InitSystem::Systemd => Some(DETERMINATE_NIXD_SERVICE_SRC.into()),
InitSystem::None => None,
};
let service_dest: Option<PathBuf> = match init {
InitSystem::Launchd => Some(DARWIN_NIXD_DAEMON_DEST.into()),
InitSystem::Systemd => Some(SERVICE_DEST.into()),
InitSystem::Systemd => Some(LINUX_NIXD_DAEMON_DEST.into()),
InitSystem::None => None,
};
let service_name: Option<String> = match init {
Expand All @@ -51,7 +42,7 @@ impl ConfigureDeterminateNixdInitService {
};

let configure_init_service =
ConfigureInitService::plan(init, start_daemon, service_src, service_dest, service_name)
ConfigureInitService::plan(init, start_daemon, None, service_dest, service_name)
.await
.map_err(Self::error)?;

Expand Down Expand Up @@ -94,9 +85,9 @@ impl Action for ConfigureDeterminateNixdInitService {
configure_init_service,
} = self;

let daemon_file = DARWIN_NIXD_DAEMON_DEST;

if *init == InitSystem::Launchd {
let daemon_file = DARWIN_NIXD_DAEMON_DEST;

// This is the only part that is actually different from configure_init_service, beyond variable parameters.

let generated_plist = generate_plist();
Expand All @@ -114,6 +105,16 @@ impl Action for ConfigureDeterminateNixdInitService {
file.write_all(&buf)
.await
.map_err(|e| Self::error(ActionErrorKind::Write(PathBuf::from(daemon_file), e)))?;
} else if *init == InitSystem::Systemd {
let daemon_file = PathBuf::from(LINUX_NIXD_DAEMON_DEST);

tokio::fs::write(
&daemon_file,
include_str!("./nix-daemon.determinate-nixd.service"),
)
.await
.map_err(|e| ActionErrorKind::Write(daemon_file.clone(), e))
.map_err(Self::error)?;
}

configure_init_service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::path::PathBuf;
use tokio::fs::{create_dir_all, remove_file};
use tracing::{span, Span};

use crate::action::common::configure_determinate_nixd_init_service::DETERMINATE_NIXD_SERVICE_SRC;
use crate::action::{
Action, ActionDescription, ActionError, ActionErrorKind, ActionTag, StatefulAction,
};
Expand All @@ -19,7 +18,6 @@ Provision the determinate-nixd binary
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct ProvisionDeterminateNixd {
binary_location: PathBuf,
service_location: PathBuf,
}

impl ProvisionDeterminateNixd {
Expand All @@ -30,7 +28,6 @@ impl ProvisionDeterminateNixd {

let this = Self {
binary_location: DETERMINATE_NIXD_BINARY_PATH.into(),
service_location: DETERMINATE_NIXD_SERVICE_SRC.into(),
};

Ok(StatefulAction::uncompleted(this))
Expand Down Expand Up @@ -91,14 +88,6 @@ impl Action for ProvisionDeterminateNixd {
.map_err(|e| ActionErrorKind::Write(self.binary_location.clone(), e))
.map_err(Self::error)?;

tokio::fs::write(
&self.service_location,
include_str!("./nix-daemon.determinate-nixd.service"),
)
.await
.map_err(|e| ActionErrorKind::Write(self.service_location.clone(), e))
.map_err(Self::error)?;

Ok(())
}

Expand Down
19 changes: 10 additions & 9 deletions src/planner/macos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,22 @@ impl Planner for Macos {

let mut plan = vec![];

if self.settings.determinate_nix {
plan.push(
ProvisionDeterminateNixd::plan()
.await
.map_err(PlannerError::Action)?
.boxed(),
);
}

if self.settings.determinate_nix {
plan.push(
CreateDeterminateNixVolume::plan(
root_disk.unwrap(), /* We just ensured it was populated */
self.volume_label.clone(),
self.case_sensitive,
self.settings.force,
)
.await
.map_err(PlannerError::Action)?
Expand All @@ -169,15 +179,6 @@ impl Planner for Macos {
);
}

if self.settings.determinate_nix {
plan.push(
ProvisionDeterminateNixd::plan()
.await
.map_err(PlannerError::Action)?
.boxed(),
);
}

plan.push(
ProvisionNix::plan(&self.settings)
.await
Expand Down

0 comments on commit 34578c4

Please sign in to comment.