Skip to content

Commit

Permalink
Remove compile-time target restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucperkins committed Jul 29, 2024
1 parent 11b2e13 commit 8386e0e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 26 deletions.
7 changes: 3 additions & 4 deletions src/cli/cmd/apply/home_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ impl HomeManager {
// If you need to apply a configuration at a path that doesn't conform to this pattern, you
// can still provide an explicit path.
fn parse_output_ref(output_ref: &str) -> Result<String, FhError> {
let username = whoami::username();

Ok(match output_ref.split('#').collect::<Vec<_>>()[..] {
[_release, _output_path] => parse_release_ref(output_ref)?,
[release] => format!(
"{}#homeConfigurations.{username}",
parse_release_ref(release)?
"{}#homeConfigurations.{}",
parse_release_ref(release)?,
whoami::username(),
),
_ => return Err(FhError::MalformedOutputRef(output_ref.to_string())),
})
Expand Down
20 changes: 5 additions & 15 deletions src/cli/cmd/apply/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mod home_manager;
#[cfg(target_os = "macos")]
mod nix_darwin;
#[cfg(target_os = "linux")]
mod nixos;

use std::{
Expand All @@ -21,13 +19,11 @@ use crate::{
path,
};

use self::home_manager::{HomeManager, HOME_MANAGER_SCRIPT};

#[cfg(target_os = "linux")]
use self::nixos::{NixOs, NIXOS_PROFILE, NIXOS_SCRIPT};

#[cfg(target_os = "macos")]
use self::nix_darwin::{NixDarwin, DARWIN_REBUILD_ACTION, NIX_DARWIN_PROFILE, NIX_DARWIN_SCRIPT};
use self::{
home_manager::{HomeManager, HOME_MANAGER_SCRIPT},
nix_darwin::{NixDarwin, DARWIN_REBUILD_ACTION, NIX_DARWIN_PROFILE, NIX_DARWIN_SCRIPT},
nixos::{NixOs, NIXOS_PROFILE, NIXOS_SCRIPT},
};

use super::{CommandExecute, FlakeHubClient};

Expand All @@ -46,11 +42,9 @@ enum System {
/// Resolve the store path for a Home Manager configuration and run its activation script
HomeManager(HomeManager),

#[cfg(target_os = "macos")]
/// Resolve the store path for a nix-darwin configuration and run its activation script
NixDarwin(NixDarwin),

#[cfg(target_os = "linux")]
/// Apply the resolved store path on a NixOS system
#[clap(name = "nixos")]
NixOs(NixOs),
Expand All @@ -61,9 +55,7 @@ impl CommandExecute for ApplySubcommand {
async fn execute(self) -> color_eyre::Result<ExitCode> {
let output_ref = match &self.system {
System::HomeManager(home_manager) => home_manager.output_ref()?,
#[cfg(target_os = "linux")]
System::NixOs(nixos) => nixos.output_ref()?,
#[cfg(target_os = "macos")]
System::NixDarwin(nix_darwin) => nix_darwin.output_ref()?,
};

Expand All @@ -86,7 +78,6 @@ impl CommandExecute for ApplySubcommand {

run_script(script_path, None, HOME_MANAGER_SCRIPT).await?;
}
#[cfg(target_os = "macos")]
System::NixDarwin(_) => {
let profile_path =
apply_path_to_profile(NIX_DARWIN_PROFILE, &resolved_path.store_path).await?;
Expand All @@ -101,7 +92,6 @@ impl CommandExecute for ApplySubcommand {
)
.await?;
}
#[cfg(target_os = "linux")]
System::NixOs(NixOs { action, .. }) => {
let profile_path =
apply_path_to_profile(NIXOS_PROFILE, &resolved_path.store_path).await?;
Expand Down
7 changes: 3 additions & 4 deletions src/cli/cmd/apply/nix_darwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ impl NixDarwin {
// If you need to apply a configuration at a path that doesn't conform to this pattern, you
// can still provide an explicit path.
fn parse_output_ref(output_ref: &str) -> Result<String, FhError> {
let devicename = whoami::devicename();

Ok(match output_ref.split('#').collect::<Vec<_>>()[..] {
[_release, _output_path] => parse_release_ref(output_ref)?,
[release] => format!(
"{}#darwinConfigurations.{devicename}.system",
parse_release_ref(release)?
"{}#darwinConfigurations.{}.system",
parse_release_ref(release)?,
whoami::devicename(),
),
_ => return Err(FhError::MalformedOutputRef(output_ref.to_string())),
})
Expand Down
5 changes: 2 additions & 3 deletions src/cli/cmd/apply/nixos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ impl Display for NixOsAction {
// If you need to apply a configuration at a path that doesn't conform to this pattern, you
// can still provide an explicit path.
fn parse_output_ref(output_ref: &str) -> Result<String, FhError> {
let hostname = gethostname::gethostname().to_string_lossy().to_string();

Ok(match output_ref.split('#').collect::<Vec<_>>()[..] {
[_release, _output_path] => parse_release_ref(output_ref)?,
[release] => format!(
"{}#nixosConfigurations.{hostname}",
"{}#nixosConfigurations.{}",
gethostname::gethostname().to_string_lossy(),
parse_release_ref(release)?
),
_ => return Err(FhError::MalformedOutputRef(output_ref.to_string())),
Expand Down
3 changes: 3 additions & 0 deletions src/cli/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ pub(crate) enum FhError {
#[error("a presumably unreachable point was reached: {0}")]
Unreachable(String),

#[error("this functionality only supported on {0}")]
UnsupportedOs(String),

#[error("url parse error: {0}")]
Url(#[from] url::ParseError),

Expand Down

0 comments on commit 8386e0e

Please sign in to comment.