From a499951a164b7fb767895d47f32885d97de51bb0 Mon Sep 17 00:00:00 2001 From: Ana Hobden Date: Mon, 12 Sep 2022 10:28:33 -0700 Subject: [PATCH] Tidy out subcmd --- src/cli/mod.rs | 12 ----------- src/cli/subcommand/mod.rs | 9 -------- src/cli/subcommand/nixos.rs | 43 ------------------------------------- src/lib.rs | 17 ++++++--------- src/nixos.rs | 21 ------------------ 5 files changed, 6 insertions(+), 96 deletions(-) delete mode 100644 src/cli/subcommand/mod.rs delete mode 100644 src/cli/subcommand/nixos.rs delete mode 100644 src/nixos.rs diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 54aa8da..9ba41c2 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -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, } #[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); diff --git a/src/cli/subcommand/mod.rs b/src/cli/subcommand/mod.rs deleted file mode 100644 index c76f64e..0000000 --- a/src/cli/subcommand/mod.rs +++ /dev/null @@ -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), -} diff --git a/src/cli/subcommand/nixos.rs b/src/cli/subcommand/nixos.rs deleted file mode 100644 index 9c28ef4..0000000 --- a/src/cli/subcommand/nixos.rs +++ /dev/null @@ -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 { - 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) - } -} diff --git a/src/lib.rs b/src/lib.rs index 99e481a..8bfdbdd 100644 --- a/src/lib.rs +++ b/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", diff --git a/src/nixos.rs b/src/nixos.rs deleted file mode 100644 index 85abdeb..0000000 --- a/src/nixos.rs +++ /dev/null @@ -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(()) - } -}