Improve documentation structure
This commit is contained in:
parent
eb1d8215f3
commit
67a67111e6
|
@ -8,7 +8,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
Action, ActionDescription, ActionState,
|
Action, ActionDescription, ActionState,
|
||||||
},
|
},
|
||||||
cli::arg::ChannelValue,
|
channel_value::ChannelValue,
|
||||||
BoxableError, CommonSettings,
|
BoxableError, CommonSettings,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ const SERVICE_SRC: &str = "/nix/var/nix/profiles/default/lib/systemd/system/nix-
|
||||||
const SOCKET_SRC: &str = "/nix/var/nix/profiles/default/lib/systemd/system/nix-daemon.socket";
|
const SOCKET_SRC: &str = "/nix/var/nix/profiles/default/lib/systemd/system/nix-daemon.socket";
|
||||||
const TMPFILES_SRC: &str = "/nix/var/nix/profiles/default//lib/tmpfiles.d/nix-daemon.conf";
|
const TMPFILES_SRC: &str = "/nix/var/nix/profiles/default//lib/tmpfiles.d/nix-daemon.conf";
|
||||||
const TMPFILES_DEST: &str = "/etc/tmpfiles.d/nix-daemon.conf";
|
const TMPFILES_DEST: &str = "/etc/tmpfiles.d/nix-daemon.conf";
|
||||||
|
const DARWIN_NIX_DAEMON_DEST: &str = "/Library/LaunchDaemons/org.nixos.nix-daemon.plist";
|
||||||
|
|
||||||
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
|
||||||
pub struct ConfigureNixDaemonService {
|
pub struct ConfigureNixDaemonService {
|
||||||
|
@ -79,9 +80,6 @@ impl Action for ConfigureNixDaemonService {
|
||||||
patch: _,
|
patch: _,
|
||||||
}
|
}
|
||||||
| OperatingSystem::Darwin => {
|
| OperatingSystem::Darwin => {
|
||||||
const DARWIN_NIX_DAEMON_DEST: &str =
|
|
||||||
"/Library/LaunchDaemons/org.nixos.nix-daemon.plist";
|
|
||||||
|
|
||||||
let src = Path::new("/nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist");
|
let src = Path::new("/nix/var/nix/profiles/default/Library/LaunchDaemons/org.nixos.nix-daemon.plist");
|
||||||
tokio::fs::copy(src.clone(), DARWIN_NIX_DAEMON_DEST)
|
tokio::fs::copy(src.clone(), DARWIN_NIX_DAEMON_DEST)
|
||||||
.await
|
.await
|
||||||
|
@ -177,7 +175,7 @@ impl Action for ConfigureNixDaemonService {
|
||||||
execute_command(
|
execute_command(
|
||||||
Command::new("launchctl")
|
Command::new("launchctl")
|
||||||
.arg("unload")
|
.arg("unload")
|
||||||
.arg("system/org.nixos.nix-daemon"),
|
.arg(DARWIN_NIX_DAEMON_DEST),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;
|
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;
|
||||||
|
|
|
@ -82,7 +82,10 @@ impl Action for KickstartLaunchctlService {
|
||||||
unit = %self.unit,
|
unit = %self.unit,
|
||||||
))]
|
))]
|
||||||
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
let Self { unit, action_state } = self;
|
let Self {
|
||||||
|
unit: _,
|
||||||
|
action_state,
|
||||||
|
} = self;
|
||||||
if *action_state == ActionState::Uncompleted {
|
if *action_state == ActionState::Uncompleted {
|
||||||
tracing::trace!("Already reverted: Unkickstart launchctl unit (noop)");
|
tracing::trace!("Already reverted: Unkickstart launchctl unit (noop)");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
|
|
@ -100,10 +100,10 @@ impl Action for UnmountVolume {
|
||||||
action_state,
|
action_state,
|
||||||
} = self;
|
} = self;
|
||||||
if *action_state == ActionState::Uncompleted {
|
if *action_state == ActionState::Uncompleted {
|
||||||
tracing::trace!("Already reverted: Stopping systemd unit");
|
tracing::trace!("Already reverted: Unmounting Nix Store volume");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
tracing::debug!("Stopping systemd unit");
|
tracing::debug!("Unmounting Nix Store volume");
|
||||||
|
|
||||||
execute_command(
|
execute_command(
|
||||||
Command::new(" /usr/sbin/diskutil")
|
Command::new(" /usr/sbin/diskutil")
|
||||||
|
@ -113,7 +113,7 @@ impl Action for UnmountVolume {
|
||||||
.await
|
.await
|
||||||
.map_err(|e| UnmountVolumeError::Command(e).boxed())?;
|
.map_err(|e| UnmountVolumeError::Command(e).boxed())?;
|
||||||
|
|
||||||
tracing::trace!("Stopped systemd unit");
|
tracing::trace!("Unmounted Nix Store volume");
|
||||||
*action_state = ActionState::Completed;
|
*action_state = ActionState::Completed;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ pub trait Action: Send + Sync + std::fmt::Debug + dyn_clone::DynClone {
|
||||||
fn describe_execute(&self) -> Vec<ActionDescription>;
|
fn describe_execute(&self) -> Vec<ActionDescription>;
|
||||||
fn describe_revert(&self) -> Vec<ActionDescription>;
|
fn describe_revert(&self) -> Vec<ActionDescription>;
|
||||||
|
|
||||||
// They should also have an `async fn plan(args...) -> Result<ActionState<Self>, Self::Error>;`
|
// They should also have an `async fn plan(args...) -> Result<ActionState<Self>, Box<dyn std::error::Error + Send + Sync>>;`
|
||||||
async fn execute(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
async fn execute(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||||
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
async fn revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,2 @@
|
||||||
mod instrumentation;
|
mod instrumentation;
|
||||||
pub(crate) use instrumentation::Instrumentation;
|
pub(crate) use instrumentation::Instrumentation;
|
||||||
mod channel_value;
|
|
||||||
pub(crate) use channel_value::ChannelValue;
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod action;
|
pub mod action;
|
||||||
|
pub mod channel_value;
|
||||||
pub mod cli;
|
pub mod cli;
|
||||||
mod error;
|
mod error;
|
||||||
mod interaction;
|
mod interaction;
|
||||||
|
@ -9,6 +10,9 @@ mod settings;
|
||||||
|
|
||||||
use std::{ffi::OsStr, process::Output};
|
use std::{ffi::OsStr, process::Output};
|
||||||
|
|
||||||
|
pub use action::Action;
|
||||||
|
pub use planner::Planner;
|
||||||
|
|
||||||
pub use error::HarmonicError;
|
pub use error::HarmonicError;
|
||||||
pub use plan::InstallPlan;
|
pub use plan::InstallPlan;
|
||||||
use planner::BuiltinPlanner;
|
use planner::BuiltinPlanner;
|
||||||
|
@ -43,7 +47,7 @@ fn set_env(k: impl AsRef<OsStr>, v: impl AsRef<OsStr>) {
|
||||||
std::env::set_var(k.as_ref(), v.as_ref());
|
std::env::set_var(k.as_ref(), v.as_ref());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait BoxableError: std::error::Error + Send + Sync {
|
trait BoxableError: std::error::Error + Send + Sync {
|
||||||
fn boxed(self) -> Box<dyn std::error::Error + Send + Sync>
|
fn boxed(self) -> Box<dyn std::error::Error + Send + Sync>
|
||||||
where
|
where
|
||||||
Self: Sized + 'static,
|
Self: Sized + 'static,
|
||||||
|
|
|
@ -17,18 +17,18 @@ use crate::{
|
||||||
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct DarwinMulti {
|
pub struct DarwinMulti {
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
settings: CommonSettings,
|
pub settings: CommonSettings,
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
action(ArgAction::SetTrue),
|
action(ArgAction::SetTrue),
|
||||||
default_value = "false",
|
default_value = "false",
|
||||||
env = "HARMONIC_VOLUME_ENCRYPT"
|
env = "HARMONIC_VOLUME_ENCRYPT"
|
||||||
)]
|
)]
|
||||||
volume_encrypt: bool,
|
pub volume_encrypt: bool,
|
||||||
#[clap(long, default_value = "Nix Store", env = "HARMONIC_VOLUME_LABEL")]
|
#[clap(long, default_value = "Nix Store", env = "HARMONIC_VOLUME_LABEL")]
|
||||||
volume_label: String,
|
pub volume_label: String,
|
||||||
#[clap(long, env = "HARMONIC_ROOT_DISK")]
|
#[clap(long, env = "HARMONIC_ROOT_DISK")]
|
||||||
root_disk: Option<String>,
|
pub root_disk: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn default_root_disk() -> Result<String, BuiltinPlannerError> {
|
async fn default_root_disk() -> Result<String, BuiltinPlannerError> {
|
||||||
|
|
|
@ -12,7 +12,7 @@ use crate::{
|
||||||
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct LinuxMulti {
|
pub struct LinuxMulti {
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
settings: CommonSettings,
|
pub settings: CommonSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use serde_json::json;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
action::{
|
action::{
|
||||||
common::{CreateDirectory, ProvisionNix},
|
common::{CreateDirectory, ProvisionNix},
|
||||||
|
@ -14,7 +12,7 @@ use crate::{
|
||||||
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
|
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
|
||||||
pub struct SteamDeck {
|
pub struct SteamDeck {
|
||||||
#[clap(flatten)]
|
#[clap(flatten)]
|
||||||
settings: CommonSettings,
|
pub settings: CommonSettings,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
|
@ -30,7 +28,7 @@ impl Planner for SteamDeck {
|
||||||
Ok(InstallPlan {
|
Ok(InstallPlan {
|
||||||
planner: Box::new(self.clone()),
|
planner: Box::new(self.clone()),
|
||||||
actions: vec![
|
actions: vec![
|
||||||
Box::new(CreateSystemdSysext::plan("/var/lib/extensions").await?),
|
Box::new(CreateSystemdSysext::plan("/var/lib/extensions/nix").await?),
|
||||||
Box::new(CreateDirectory::plan("/nix", None, None, 0o0755, true).await?),
|
Box::new(CreateDirectory::plan("/nix", None, None, 0o0755, true).await?),
|
||||||
Box::new(ProvisionNix::plan(self.settings.clone()).await?),
|
Box::new(ProvisionNix::plan(self.settings.clone()).await?),
|
||||||
Box::new(StartSystemdUnit::plan("nix-daemon.socket".into()).await?),
|
Box::new(StartSystemdUnit::plan("nix-daemon.socket".into()).await?),
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||||
use clap::ArgAction;
|
use clap::ArgAction;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
use crate::cli::arg::ChannelValue;
|
use crate::channel_value::ChannelValue;
|
||||||
|
|
||||||
pub const NIX_X64_64_LINUX_URL: &str =
|
pub const NIX_X64_64_LINUX_URL: &str =
|
||||||
"https://releases.nixos.org/nix/nix-2.11.0/nix-2.11.0-x86_64-linux.tar.xz";
|
"https://releases.nixos.org/nix/nix-2.11.0/nix-2.11.0-x86_64-linux.tar.xz";
|
||||||
|
@ -26,7 +26,7 @@ pub struct CommonSettings {
|
||||||
env = "HARMONIC_CHANNEL",
|
env = "HARMONIC_CHANNEL",
|
||||||
default_value = "nixpkgs=https://nixos.org/channels/nixpkgs-unstable",
|
default_value = "nixpkgs=https://nixos.org/channels/nixpkgs-unstable",
|
||||||
)]
|
)]
|
||||||
pub(crate) channels: Vec<crate::cli::arg::ChannelValue>,
|
pub channels: Vec<ChannelValue>,
|
||||||
|
|
||||||
/// Modify the user profile to automatically load nix
|
/// Modify the user profile to automatically load nix
|
||||||
#[clap(
|
#[clap(
|
||||||
|
@ -37,27 +37,27 @@ pub struct CommonSettings {
|
||||||
env = "HARMONIC_NO_MODIFY_PROFILE",
|
env = "HARMONIC_NO_MODIFY_PROFILE",
|
||||||
name = "no-modify-profile"
|
name = "no-modify-profile"
|
||||||
)]
|
)]
|
||||||
pub(crate) modify_profile: bool,
|
pub modify_profile: bool,
|
||||||
|
|
||||||
/// Number of build users to create
|
/// Number of build users to create
|
||||||
#[clap(long, default_value = "32", env = "HARMONIC_DAEMON_USER_COUNT")]
|
#[clap(long, default_value = "32", env = "HARMONIC_DAEMON_USER_COUNT")]
|
||||||
pub(crate) daemon_user_count: usize,
|
pub daemon_user_count: usize,
|
||||||
|
|
||||||
#[clap(long, default_value = "nixbld", env = "HARMONIC_NIX_BUILD_GROUP_NAME")]
|
#[clap(long, default_value = "nixbld", env = "HARMONIC_NIX_BUILD_GROUP_NAME")]
|
||||||
pub(crate) nix_build_group_name: String,
|
pub nix_build_group_name: String,
|
||||||
|
|
||||||
#[clap(long, default_value_t = 3000, env = "HARMONIC_NIX_BUILD_GROUP_ID")]
|
#[clap(long, default_value_t = 3000, env = "HARMONIC_NIX_BUILD_GROUP_ID")]
|
||||||
pub(crate) nix_build_group_id: usize,
|
pub nix_build_group_id: usize,
|
||||||
|
|
||||||
#[clap(long, env = "HARMONIC_NIX_BUILD_USER_PREFIX")]
|
#[clap(long, env = "HARMONIC_NIX_BUILD_USER_PREFIX")]
|
||||||
#[cfg_attr(target_os = "macos", clap(default_value = "_nixbld"))]
|
#[cfg_attr(target_os = "macos", clap(default_value = "_nixbld"))]
|
||||||
#[cfg_attr(target_os = "linux", clap(default_value = "nixbld"))]
|
#[cfg_attr(target_os = "linux", clap(default_value = "nixbld"))]
|
||||||
pub(crate) nix_build_user_prefix: String,
|
pub nix_build_user_prefix: String,
|
||||||
|
|
||||||
#[clap(long, env = "HARMONIC_NIX_BUILD_USER_ID_BASE")]
|
#[clap(long, env = "HARMONIC_NIX_BUILD_USER_ID_BASE")]
|
||||||
#[cfg_attr(target_os = "macos", clap(default_value_t = 300))]
|
#[cfg_attr(target_os = "macos", clap(default_value_t = 300))]
|
||||||
#[cfg_attr(target_os = "linux", clap(default_value_t = 3000))]
|
#[cfg_attr(target_os = "linux", clap(default_value_t = 3000))]
|
||||||
pub(crate) nix_build_user_id_base: usize,
|
pub nix_build_user_id_base: usize,
|
||||||
|
|
||||||
#[clap(long, env = "HARMONIC_NIX_PACKAGE_URL")]
|
#[clap(long, env = "HARMONIC_NIX_PACKAGE_URL")]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
|
@ -84,10 +84,10 @@ pub struct CommonSettings {
|
||||||
default_value = NIX_AARCH64_LINUX_URL,
|
default_value = NIX_AARCH64_LINUX_URL,
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
pub(crate) nix_package_url: Url,
|
pub nix_package_url: Url,
|
||||||
|
|
||||||
#[clap(long, env = "HARMONIC_EXTRA_CONF")]
|
#[clap(long, env = "HARMONIC_EXTRA_CONF")]
|
||||||
pub(crate) extra_conf: Option<String>,
|
pub extra_conf: Option<String>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
long,
|
long,
|
||||||
|
@ -96,7 +96,7 @@ pub struct CommonSettings {
|
||||||
global = true,
|
global = true,
|
||||||
env = "HARMONIC_FORCE"
|
env = "HARMONIC_FORCE"
|
||||||
)]
|
)]
|
||||||
pub(crate) force: bool,
|
pub force: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CommonSettings {
|
impl CommonSettings {
|
||||||
|
|
Loading…
Reference in a new issue