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
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";
const DETERMINATE_NIXD_BINARY_PATH: &str = "/var/usrlocal/bin/determinate-nixd";
/**
Provision the determinate-nixd binary
*/
Expand Down
4 changes: 2 additions & 2 deletions src/action/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pub(crate) mod ensure_steamos_nix_directory;
pub(crate) mod provision_selinux;
pub(crate) mod revert_clean_steamos_nix_offload;
pub(crate) mod start_systemd_unit;
pub(crate) mod start_or_enable_systemd_unit;
pub(crate) mod systemctl_daemon_reload;

pub use ensure_steamos_nix_directory::EnsureSteamosNixDirectory;
pub use provision_selinux::ProvisionSelinux;
pub use revert_clean_steamos_nix_offload::RevertCleanSteamosNixOffload;
pub use start_systemd_unit::{StartSystemdUnit, StartSystemdUnitError};
pub use start_or_enable_systemd_unit::{StartOrEnableSystemdUnit, StartSystemdUnitError};
pub use systemctl_daemon_reload::SystemctlDaemonReload;
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ use crate::action::{Action, ActionDescription};
Start a given systemd unit
*/
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
#[serde(tag = "action_name", rename = "start_systemd_unit")]
pub struct StartSystemdUnit {
#[serde(tag = "action_name", rename = "start_or_enable_systemd_unit")]
pub struct StartOrEnableSystemdUnit {
unit: String,
enable: bool,
start: bool,
}

impl StartSystemdUnit {
impl StartOrEnableSystemdUnit {
#[tracing::instrument(level = "debug", skip_all)]
pub async fn plan(
unit: impl AsRef<str>,
enable: bool,
start: bool,
) -> Result<StatefulAction<Self>, ActionError> {
let unit = unit.as_ref();
let mut command = Command::new("systemctl");
Expand All @@ -42,26 +44,27 @@ impl StartSystemdUnit {
action: Self {
unit: unit.to_string(),
enable,
start,
},
state,
})
}
}

#[async_trait::async_trait]
#[typetag::serde(name = "start_systemd_unit")]
impl Action for StartSystemdUnit {
#[typetag::serde(name = "start_or_enable_systemd_unit")]
impl Action for StartOrEnableSystemdUnit {
fn action_tag() -> ActionTag {
ActionTag("start_systemd_unit")
ActionTag("start_or_enable_systemd_unit")
}
fn tracing_synopsis(&self) -> String {
format!("Enable (and start) the systemd unit `{}`", self.unit)
format!("Enable (and/or start) the systemd unit `{}`", self.unit)
}

fn tracing_span(&self) -> Span {
span!(
tracing::Level::DEBUG,
"start_systemd_unit",
"start_or_enable_systemd_unit",
unit = %self.unit,
)
}
Expand All @@ -72,10 +75,14 @@ impl Action for StartSystemdUnit {

#[tracing::instrument(level = "debug", skip_all)]
async fn execute(&mut self) -> Result<(), ActionError> {
let Self { unit, enable } = self;

match enable {
true => {
let Self {
unit,
enable,
start,
} = self;

match (enable, start) {
(true, true) => {
// TODO(@Hoverbear): Handle proxy vars
execute_command(
Command::new("systemctl")
Expand All @@ -88,7 +95,7 @@ impl Action for StartSystemdUnit {
.await
.map_err(Self::error)?;
},
false => {
(false, true) => {
// TODO(@Hoverbear): Handle proxy vars
execute_command(
Command::new("systemctl")
Expand All @@ -100,6 +107,21 @@ impl Action for StartSystemdUnit {
.await
.map_err(Self::error)?;
},
(true, false) => {
// TODO(@Hoverbear): Handle proxy vars
execute_command(
Command::new("systemctl")
.process_group(0)
.arg("enable")
.arg(unit)
.stdin(std::process::Stdio::null()),
)
.await
.map_err(Self::error)?;
},
(false, false) => {
tracing::warn!("Told to neither enable nor start unit {}. Noop!", unit);
},
}

Ok(())
Expand Down
65 changes: 42 additions & 23 deletions src/planner/ostree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::{
},
linux::{
provision_selinux::{DETERMINATE_SELINUX_POLICY_PP_CONTENT, SELINUX_POLICY_PP_CONTENT},
ProvisionSelinux, StartSystemdUnit, SystemctlDaemonReload,
ProvisionSelinux, StartOrEnableSystemdUnit, SystemctlDaemonReload,
},
StatefulAction,
},
distribution::Distribution,
error::HasExpectedErrors,
planner::{Planner, PlannerError},
settings::{CommonSettings, InitSystem, InstallSettingsError},
settings::{CommonSettings, InitSettings, InitSystem, InstallSettingsError},
Action, BuiltinPlanner,
};
use std::{collections::HashMap, path::PathBuf};
Expand All @@ -36,6 +36,8 @@ pub struct Ostree {
persistence: PathBuf,
#[cfg_attr(feature = "cli", clap(flatten))]
pub settings: CommonSettings,
#[cfg_attr(feature = "cli", clap(flatten))]
pub init: InitSettings,
}

#[async_trait::async_trait]
Expand All @@ -45,19 +47,23 @@ impl Planner for Ostree {
Ok(Self {
persistence: PathBuf::from("/var/home/nix"),
settings: CommonSettings::default().await?,
init: InitSettings::default().await?,
})
}

async fn plan(&self) -> Result<Vec<StatefulAction<Box<dyn Action>>>, PlannerError> {
let has_selinux = detect_selinux().await?;
let mut plan = vec![
// Primarily for uninstall
SystemctlDaemonReload::plan()
.await
.map_err(PlannerError::Action)?
.boxed(),
];
let mut plan = vec![];

if self.init.start_daemon {
// Primarily for uninstall
plan.push(
SystemctlDaemonReload::plan()
.await
.map_err(PlannerError::Action)?
.boxed(),
)
}
plan.push(
CreateDirectory::plan(&self.persistence, None, None, 0o0755, true)
.await
Expand Down Expand Up @@ -171,7 +177,7 @@ impl Planner for Ostree {
}

plan.push(
StartSystemdUnit::plan("nix.mount".to_string(), false)
StartOrEnableSystemdUnit::plan("nix.mount".to_string(), false, self.init.start_daemon)
.await
.map_err(PlannerError::Action)?
.boxed(),
Expand Down Expand Up @@ -229,29 +235,36 @@ impl Planner for Ostree {
);

plan.push(
ConfigureUpstreamInitService::plan(InitSystem::Systemd, true)
ConfigureUpstreamInitService::plan(InitSystem::Systemd, self.init.start_daemon)
.await
.map_err(PlannerError::Action)?
.boxed(),
);
plan.push(
StartSystemdUnit::plan("ensure-symlinked-units-resolve.service".to_string(), true)
.await
.map_err(PlannerError::Action)?
.boxed(),
StartOrEnableSystemdUnit::plan(
"ensure-symlinked-units-resolve.service".to_string(),
true,
self.init.start_daemon,
)
.await
.map_err(PlannerError::Action)?
.boxed(),
);
plan.push(
RemoveDirectory::plan(crate::settings::SCRATCH_DIR)
.await
.map_err(PlannerError::Action)?
.boxed(),
);
plan.push(
SystemctlDaemonReload::plan()
.await
.map_err(PlannerError::Action)?
.boxed(),
);

if self.init.start_daemon {
plan.push(
SystemctlDaemonReload::plan()
.await
.map_err(PlannerError::Action)?
.boxed(),
);
}

Ok(plan)
}
Expand All @@ -260,10 +273,12 @@ impl Planner for Ostree {
let Self {
persistence,
settings,
init,
} = self;
let mut map = HashMap::default();

map.extend(settings.settings()?);
map.extend(init.settings()?);
map.insert(
"persistence".to_string(),
serde_json::to_value(persistence)?,
Expand Down Expand Up @@ -302,7 +317,9 @@ impl Planner for Ostree {
async fn pre_uninstall_check(&self) -> Result<(), PlannerError> {
check_not_wsl1()?;

check_systemd_active()?;
if self.init.init == InitSystem::Systemd && self.init.start_daemon {
check_systemd_active()?;
}

Ok(())
}
Expand All @@ -314,7 +331,9 @@ impl Planner for Ostree {

check_not_wsl1()?;

check_systemd_active()?;
if self.init.init == InitSystem::Systemd && self.init.start_daemon {
check_systemd_active()?;
}

Ok(())
}
Expand Down
23 changes: 14 additions & 9 deletions src/planner/steam_deck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use crate::{
ProvisionDeterminateNixd, ProvisionNix,
},
linux::{
EnsureSteamosNixDirectory, RevertCleanSteamosNixOffload, StartSystemdUnit,
EnsureSteamosNixDirectory, RevertCleanSteamosNixOffload, StartOrEnableSystemdUnit,
SystemctlDaemonReload,
},
Action, StatefulAction,
Expand Down Expand Up @@ -265,9 +265,10 @@ impl Planner for SteamDeck {
.map_err(PlannerError::Action)?;
actions.push(ensure_steamos_nix_directory.boxed());

let start_nix_mount = StartSystemdUnit::plan("nix.mount".to_string(), true)
.await
.map_err(PlannerError::Action)?;
let start_nix_mount =
StartOrEnableSystemdUnit::plan("nix.mount".to_string(), true, true)
.await
.map_err(PlannerError::Action)?;
actions.push(start_nix_mount.boxed());
}

Expand Down Expand Up @@ -337,7 +338,7 @@ impl Planner for SteamDeck {

if requires_nix_bind_mount {
actions.push(
StartSystemdUnit::plan("nix.mount".to_string(), false)
StartOrEnableSystemdUnit::plan("nix.mount".to_string(), false, true)
.await
.map_err(PlannerError::Action)?
.boxed(),
Expand Down Expand Up @@ -371,10 +372,14 @@ impl Planner for SteamDeck {
.await
.map_err(PlannerError::Action)?
.boxed(),
StartSystemdUnit::plan("ensure-symlinked-units-resolve.service".to_string(), true)
.await
.map_err(PlannerError::Action)?
.boxed(),
StartOrEnableSystemdUnit::plan(
"ensure-symlinked-units-resolve.service".to_string(),
true,
true,
)
.await
.map_err(PlannerError::Action)?
.boxed(),
RemoveDirectory::plan(crate::settings::SCRATCH_DIR)
.await
.map_err(PlannerError::Action)?
Expand Down
10 changes: 6 additions & 4 deletions tests/fixtures/linux/steam-deck.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
},
{
"action": {
"action_name": "start_systemd_unit",
"action_name": "start_or_enable_systemd_unit",
"unit": "nix.mount",
"enable": true
"enable": true,
"start": true
},
"state": "Skipped"
},
Expand Down Expand Up @@ -1148,9 +1149,10 @@
},
{
"action": {
"action_name": "start_systemd_unit",
"action_name": "start_or_enable_systemd_unit",
"unit": "ensure-symlinked-units-resolve.service",
"enable": true
"enable": true,
"start": true
},
"state": "Completed"
},
Expand Down