forked from lix-project/lix-installer
Tidy out subcmd
This commit is contained in:
parent
4336d806a8
commit
a499951a16
|
@ -1,5 +1,4 @@
|
|||
pub(crate) mod arg;
|
||||
pub(crate) mod subcommand;
|
||||
|
||||
use crate::{cli::arg::ChannelValue, interaction};
|
||||
use clap::{ArgAction, Parser};
|
||||
|
@ -40,9 +39,6 @@ pub(crate) struct HarmonicCli {
|
|||
/// Number of build users to create
|
||||
#[clap(long, default_value = "32", env = "HARMONIC_NIX_DAEMON_USER_COUNT")]
|
||||
pub(crate) daemon_user_count: usize,
|
||||
#[cfg(target_os = "linux")]
|
||||
#[clap(subcommand)]
|
||||
subcommand: Option<subcommand::Subcommand>,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
|
@ -60,16 +56,8 @@ impl CommandExecute for HarmonicCli {
|
|||
daemon_user_count,
|
||||
channel,
|
||||
no_modify_profile,
|
||||
#[cfg(target_os = "linux")]
|
||||
subcommand,
|
||||
} = self;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
match subcommand {
|
||||
Some(subcommand::Subcommand::NixOs(nixos)) => return nixos.execute().await,
|
||||
None => (),
|
||||
}
|
||||
|
||||
let mut harmonic = Harmonic::default();
|
||||
|
||||
harmonic.dry_run(dry_run);
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
#[cfg(target_os = "linux")]
|
||||
mod nixos;
|
||||
|
||||
#[derive(Debug, clap::Subcommand)]
|
||||
pub(crate) enum Subcommand {
|
||||
#[cfg(target_os = "linux")]
|
||||
#[clap(name = "nixos")]
|
||||
NixOs(nixos::NixOsCommand),
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
use std::{path::PathBuf, process::ExitCode};
|
||||
|
||||
use crate::{cli::CommandExecute, interaction};
|
||||
use harmonic::NixOs;
|
||||
use owo_colors::OwoColorize;
|
||||
|
||||
/// Install an opinionated NixOS on a device
|
||||
#[derive(Debug, clap::Parser)]
|
||||
pub(crate) struct NixOsCommand {
|
||||
/// The disk to install on (eg. `/dev/nvme1n1`, `/dev/sda`)
|
||||
#[clap(long)]
|
||||
target_device: PathBuf,
|
||||
}
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl CommandExecute for NixOsCommand {
|
||||
#[tracing::instrument(skip_all, fields(
|
||||
target_device = %self.target_device.display(),
|
||||
))]
|
||||
async fn execute(self) -> eyre::Result<ExitCode> {
|
||||
let Self { target_device } = self;
|
||||
|
||||
if interaction::confirm(format!(
|
||||
"\
|
||||
This will:
|
||||
1. Irrecoverably wipe `{target_device}`
|
||||
2. Write a GPT partition table to `{target_device}`
|
||||
3. Write a partition 1 to `{target_device}` as a 1G FAT32 EFI ESP
|
||||
4. Write partition 2 to `{target_device}` as a BTRFS disk consuming
|
||||
the remaining disk\n\
|
||||
5. Create several BTRFS subvolumes supporting an ephemeral
|
||||
(aka \'Erase your darlings\') installation\n\
|
||||
",
|
||||
target_device = target_device.display().cyan()
|
||||
))
|
||||
.await?
|
||||
{
|
||||
NixOs::new(target_device).install().await?;
|
||||
}
|
||||
|
||||
Ok(ExitCode::SUCCESS)
|
||||
}
|
||||
}
|
17
src/lib.rs
17
src/lib.rs
|
@ -10,11 +10,6 @@ use std::{
|
|||
|
||||
pub use error::HarmonicError;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod nixos;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub use nixos::NixOs;
|
||||
|
||||
use bytes::Buf;
|
||||
use glob::glob;
|
||||
use reqwest::Url;
|
||||
|
@ -62,7 +57,7 @@ impl Harmonic {
|
|||
impl Harmonic {
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn fetch_nix(&self) -> Result<(), HarmonicError> {
|
||||
tracing::debug!("Fetching nix");
|
||||
tracing::info!("Fetching nix");
|
||||
// TODO(@hoverbear): architecture specific download
|
||||
// TODO(@hoverbear): hash check
|
||||
// TODO(@hoverbear): custom url
|
||||
|
@ -94,7 +89,7 @@ impl Harmonic {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn create_group(&self) -> Result<(), HarmonicError> {
|
||||
tracing::debug!("Creating group");
|
||||
tracing::info!("Creating group");
|
||||
execute_command(
|
||||
Command::new("groupadd")
|
||||
.arg("-g")
|
||||
|
@ -109,7 +104,7 @@ impl Harmonic {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn create_users(&self) -> Result<(), HarmonicError> {
|
||||
tracing::debug!("Creating users");
|
||||
tracing::info!("Creating users");
|
||||
for index in 1..=self.daemon_user_count {
|
||||
let user_name = format!("{}{index}", self.nix_build_user_prefix);
|
||||
let user_id = self.nix_build_user_id_base + index;
|
||||
|
@ -142,7 +137,7 @@ impl Harmonic {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn create_directories(&self) -> Result<(), HarmonicError> {
|
||||
tracing::debug!("Creating directories");
|
||||
tracing::info!("Creating directories");
|
||||
create_directory("/nix", self.dry_run).await?;
|
||||
set_permissions(
|
||||
"/nix",
|
||||
|
@ -198,7 +193,7 @@ impl Harmonic {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn place_channel_configuration(&self) -> Result<(), HarmonicError> {
|
||||
tracing::debug!("Placing channel configuration");
|
||||
tracing::info!("Placing channel configuration");
|
||||
let buf = self
|
||||
.channels
|
||||
.iter()
|
||||
|
@ -219,7 +214,7 @@ impl Harmonic {
|
|||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub async fn configure_shell_profile(&self) -> Result<(), HarmonicError> {
|
||||
tracing::debug!("Configuring shell profile");
|
||||
tracing::info!("Configuring shell profile");
|
||||
const PROFILE_TARGETS: &[&str] = &[
|
||||
"/etc/bashrc",
|
||||
"/etc/profile.d/nix.sh",
|
||||
|
|
21
src/nixos.rs
21
src/nixos.rs
|
@ -1,21 +0,0 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::HarmonicError;
|
||||
|
||||
pub struct NixOs {
|
||||
/// The disk to install on (eg. `/dev/nvme1n1`, `/dev/sda`)
|
||||
target_device: PathBuf,
|
||||
}
|
||||
|
||||
impl NixOs {
|
||||
pub fn new(target_device: PathBuf) -> Self {
|
||||
Self { target_device }
|
||||
}
|
||||
#[tracing::instrument(skip_all, fields(
|
||||
target_device = %self.target_device.display(),
|
||||
))]
|
||||
pub async fn install(&self) -> Result<(), HarmonicError> {
|
||||
tracing::warn!("Kicking your socks in");
|
||||
Ok(())
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue