Improve documentation structure

This commit is contained in:
Ana Hobden 2022-10-28 14:15:33 -07:00
parent eb1d8215f3
commit 67a67111e6
12 changed files with 34 additions and 33 deletions

View file

@ -8,7 +8,7 @@ use crate::{
},
Action, ActionDescription, ActionState,
},
cli::arg::ChannelValue,
channel_value::ChannelValue,
BoxableError, CommonSettings,
};

View file

@ -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 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 DARWIN_NIX_DAEMON_DEST: &str = "/Library/LaunchDaemons/org.nixos.nix-daemon.plist";
#[derive(Debug, serde::Deserialize, serde::Serialize, Clone)]
pub struct ConfigureNixDaemonService {
@ -79,9 +80,6 @@ impl Action for ConfigureNixDaemonService {
patch: _,
}
| 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");
tokio::fs::copy(src.clone(), DARWIN_NIX_DAEMON_DEST)
.await
@ -177,7 +175,7 @@ impl Action for ConfigureNixDaemonService {
execute_command(
Command::new("launchctl")
.arg("unload")
.arg("system/org.nixos.nix-daemon"),
.arg(DARWIN_NIX_DAEMON_DEST),
)
.await
.map_err(|e| ConfigureNixDaemonServiceError::Command(e).boxed())?;

View file

@ -82,7 +82,10 @@ impl Action for KickstartLaunchctlService {
unit = %self.unit,
))]
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 {
tracing::trace!("Already reverted: Unkickstart launchctl unit (noop)");
return Ok(());

View file

@ -100,10 +100,10 @@ impl Action for UnmountVolume {
action_state,
} = self;
if *action_state == ActionState::Uncompleted {
tracing::trace!("Already reverted: Stopping systemd unit");
tracing::trace!("Already reverted: Unmounting Nix Store volume");
return Ok(());
}
tracing::debug!("Stopping systemd unit");
tracing::debug!("Unmounting Nix Store volume");
execute_command(
Command::new(" /usr/sbin/diskutil")
@ -113,7 +113,7 @@ impl Action for UnmountVolume {
.await
.map_err(|e| UnmountVolumeError::Command(e).boxed())?;
tracing::trace!("Stopped systemd unit");
tracing::trace!("Unmounted Nix Store volume");
*action_state = ActionState::Completed;
Ok(())
}

View file

@ -10,7 +10,7 @@ pub trait Action: Send + Sync + std::fmt::Debug + dyn_clone::DynClone {
fn describe_execute(&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 revert(&mut self) -> Result<(), Box<dyn std::error::Error + Send + Sync>>;
}

View file

@ -1,4 +1,2 @@
mod instrumentation;
pub(crate) use instrumentation::Instrumentation;
mod channel_value;
pub(crate) use channel_value::ChannelValue;

View file

@ -1,4 +1,5 @@
pub mod action;
pub mod channel_value;
pub mod cli;
mod error;
mod interaction;
@ -9,6 +10,9 @@ mod settings;
use std::{ffi::OsStr, process::Output};
pub use action::Action;
pub use planner::Planner;
pub use error::HarmonicError;
pub use plan::InstallPlan;
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());
}
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>
where
Self: Sized + 'static,

View file

@ -17,18 +17,18 @@ use crate::{
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
pub struct DarwinMulti {
#[clap(flatten)]
settings: CommonSettings,
pub settings: CommonSettings,
#[clap(
long,
action(ArgAction::SetTrue),
default_value = "false",
env = "HARMONIC_VOLUME_ENCRYPT"
)]
volume_encrypt: bool,
pub volume_encrypt: bool,
#[clap(long, default_value = "Nix Store", env = "HARMONIC_VOLUME_LABEL")]
volume_label: String,
pub volume_label: String,
#[clap(long, env = "HARMONIC_ROOT_DISK")]
root_disk: Option<String>,
pub root_disk: Option<String>,
}
async fn default_root_disk() -> Result<String, BuiltinPlannerError> {

View file

@ -12,7 +12,7 @@ use crate::{
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
pub struct LinuxMulti {
#[clap(flatten)]
settings: CommonSettings,
pub settings: CommonSettings,
}
#[async_trait::async_trait]

View file

@ -1,7 +1,5 @@
use std::collections::HashMap;
use serde_json::json;
use crate::{
action::{
common::{CreateDirectory, ProvisionNix},
@ -14,7 +12,7 @@ use crate::{
#[derive(Debug, Clone, clap::Parser, serde::Serialize, serde::Deserialize)]
pub struct SteamDeck {
#[clap(flatten)]
settings: CommonSettings,
pub settings: CommonSettings,
}
#[async_trait::async_trait]
@ -30,7 +28,7 @@ impl Planner for SteamDeck {
Ok(InstallPlan {
planner: Box::new(self.clone()),
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(ProvisionNix::plan(self.settings.clone()).await?),
Box::new(StartSystemdUnit::plan("nix-daemon.socket".into()).await?),

View file

@ -3,7 +3,7 @@ use std::collections::HashMap;
use clap::ArgAction;
use url::Url;
use crate::cli::arg::ChannelValue;
use crate::channel_value::ChannelValue;
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";
@ -26,7 +26,7 @@ pub struct CommonSettings {
env = "HARMONIC_CHANNEL",
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
#[clap(
@ -37,27 +37,27 @@ pub struct CommonSettings {
env = "HARMONIC_NO_MODIFY_PROFILE",
name = "no-modify-profile"
)]
pub(crate) modify_profile: bool,
pub modify_profile: bool,
/// Number of build users to create
#[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")]
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")]
pub(crate) nix_build_group_id: usize,
pub nix_build_group_id: usize,
#[clap(long, env = "HARMONIC_NIX_BUILD_USER_PREFIX")]
#[cfg_attr(target_os = "macos", 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")]
#[cfg_attr(target_os = "macos", clap(default_value_t = 300))]
#[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")]
#[cfg_attr(
@ -84,10 +84,10 @@ pub struct CommonSettings {
default_value = NIX_AARCH64_LINUX_URL,
)
)]
pub(crate) nix_package_url: Url,
pub nix_package_url: Url,
#[clap(long, env = "HARMONIC_EXTRA_CONF")]
pub(crate) extra_conf: Option<String>,
pub extra_conf: Option<String>,
#[clap(
long,
@ -96,7 +96,7 @@ pub struct CommonSettings {
global = true,
env = "HARMONIC_FORCE"
)]
pub(crate) force: bool,
pub force: bool,
}
impl CommonSettings {