diff --git a/Cargo.toml b/Cargo.toml index 4cc615d..65fcebe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,11 @@ name = "nh" version = "3.5.27" edition = "2021" license = "EUPL-1.2" + +[lib] +name = "nh_lib" +path = "src/lib/main.rs" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/src/home.rs b/src/home.rs index d87e610..b465b75 100644 --- a/src/home.rs +++ b/src/home.rs @@ -11,9 +11,10 @@ use crate::*; use crate::{ interface::NHRunnable, interface::{FlakeRef, HomeArgs, HomeRebuildArgs, HomeSubcommand}, - util::{compare_semver, get_nix_version}, }; +use nh_lib::version::{compare_semver, get_nix_version}; + #[derive(Error, Debug)] enum HomeRebuildError { #[error("Configuration \"{0}\" doesn't exist")] @@ -34,7 +35,7 @@ impl NHRunnable for HomeArgs { impl HomeRebuildArgs { fn rebuild(&self, action: &HomeSubcommand) -> Result<()> { - let out_path: Box = match self.common.out_link { + let out_path: Box = match self.common.out_link { Some(ref p) => Box::new(p.clone()), None => Box::new({ let dir = tempfile::Builder::new().prefix("nh-home").tempdir()?; diff --git a/src/lib/main.rs b/src/lib/main.rs new file mode 100644 index 0000000..2b5df3b --- /dev/null +++ b/src/lib/main.rs @@ -0,0 +1,22 @@ +pub mod version; + +extern crate semver; + +use std::path::{Path, PathBuf}; +use tempfile::TempDir; + +pub trait MaybeTempPath: std::fmt::Debug { + fn get_path(&self) -> &Path; +} + +impl MaybeTempPath for PathBuf { + fn get_path(&self) -> &Path { + self.as_ref() + } +} + +impl MaybeTempPath for (PathBuf, TempDir) { + fn get_path(&self) -> &Path { + self.0.as_ref() + } +} diff --git a/src/util.rs b/src/lib/version.rs similarity index 84% rename from src/util.rs rename to src/lib/version.rs index 1cbee66..f0a1288 100644 --- a/src/util.rs +++ b/src/lib/version.rs @@ -1,10 +1,5 @@ -extern crate semver; - use color_eyre::{eyre, Result}; use semver::Version; -use tempfile::TempDir; - -use std::path::{Path, PathBuf}; use std::process::Command; use std::str; @@ -58,19 +53,3 @@ pub fn get_nix_version() -> Result { Err(eyre::eyre!("Failed to extract version")) } - -pub trait MaybeTempPath: std::fmt::Debug { - fn get_path(&self) -> &Path; -} - -impl MaybeTempPath for PathBuf { - fn get_path(&self) -> &Path { - self.as_ref() - } -} - -impl MaybeTempPath for (PathBuf, TempDir) { - fn get_path(&self) -> &Path { - self.0.as_ref() - } -} diff --git a/src/main.rs b/src/main.rs index 76cdfaa..ac5ccd6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,6 @@ mod json; mod logging; mod nixos; mod search; -mod util; use crate::interface::NHParser; use crate::interface::NHRunnable; diff --git a/src/nixos.rs b/src/nixos.rs index 32075d4..4d2bab2 100644 --- a/src/nixos.rs +++ b/src/nixos.rs @@ -9,8 +9,8 @@ use tracing::{debug, info, warn}; use crate::interface::NHRunnable; use crate::interface::OsRebuildType::{self, Boot, Build, Switch, Test}; use crate::interface::{self, OsRebuildArgs}; -use crate::util::{compare_semver, get_nix_version}; use crate::*; +use nh_lib::version::{compare_semver, get_nix_version}; const SYSTEM_PROFILE: &str = "/nix/var/nix/profiles/system"; const CURRENT_PROFILE: &str = "/run/current-system"; @@ -47,7 +47,7 @@ impl OsRebuildArgs { None => hostname::get().context("Failed to get hostname")?, }; - let out_path: Box = match self.common.out_link { + let out_path: Box = match self.common.out_link { Some(ref p) => Box::new(p.clone()), None => Box::new({ let dir = tempfile::Builder::new().prefix("nh-os").tempdir()?;