Run nix build.

This commit is contained in:
Tom Alexander
2026-02-14 19:20:52 -05:00
parent 7ec243e3e4
commit 47e6a32ba3
7 changed files with 130 additions and 17 deletions

View File

@@ -15,7 +15,7 @@ use super::TargetConfig;
pub(crate) struct Config {
#[serde(skip)]
config_path: Option<PathBuf>,
work_directory: Option<PathBuf>,
output_directory: Option<PathBuf>,
targets: Vec<TargetConfig>,
}
@@ -63,9 +63,9 @@ impl Config {
Ok(target_config)
}
pub(crate) fn get_work_directory(&self) -> Result<Cow<'_, Path>, CustomError> {
let maybe_work_directory = self.work_directory.as_deref().map(Cow::Borrowed);
if let Some(work_dir) = maybe_work_directory {
pub(crate) fn get_output_directory(&self) -> Result<Cow<'_, Path>, CustomError> {
let maybe_repo_directory = self.output_directory.as_deref().map(Cow::Borrowed);
if let Some(work_dir) = maybe_repo_directory {
return Ok(work_dir);
}
let current_dir: PathBuf = std::env::current_dir()?;

View File

@@ -24,7 +24,7 @@ pub(crate) struct TargetConfig {
pub(super) path: Option<String>,
#[serde(default)]
pub(super) attr: Option<String>,
pub(super) attr: String,
#[serde(default)]
pub(super) update: Option<bool>,
@@ -34,26 +34,44 @@ pub(crate) struct TargetConfig {
}
impl TargetConfig {
/// The root directory for this specific build target.
pub(crate) fn get_target_directory<'target, 'root>(
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let work_directory = config_root.get_work_directory()?;
Ok(Cow::Owned(work_directory.join(&self.name)))
let repo_directory = config_root.get_output_directory()?;
Ok(Cow::Owned(repo_directory.join(&self.name)))
}
pub(crate) fn get_flake_directory<'target, 'root>(
/// The root of the checkout of the git repository.
pub(crate) fn get_repo_directory<'target, 'root>(
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let target_directory = self.get_target_directory(config_root)?;
Ok(Cow::Owned(target_directory.join("flake")))
Ok(Cow::Owned(target_directory.join("repo")))
}
/// The directory that contains flake.nix.
pub(crate) fn get_flake_directory<'target, 'root>(
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let repo_directory = self.get_repo_directory(config_root)?;
let subpath = self.path.as_deref();
if let Some(subpath) = subpath {
Ok(Cow::Owned(repo_directory.join(subpath)))
} else {
Ok(repo_directory)
}
}
/// The URL to the upstream git repository.
pub(crate) fn get_repo(&'_ self) -> Result<&String, CustomError> {
Ok(&self.repo)
}
/// The git branch name to track.
pub(crate) fn get_branch(&'_ self) -> Result<Cow<'_, str>, CustomError> {
if let Some(b) = &self.branch {
Ok(Cow::Borrowed(b))
@@ -62,7 +80,22 @@ impl TargetConfig {
}
}
/// If we want to pin to a specific revision, this is the reference to that commit.
pub(crate) fn get_revision(&self) -> Result<&Option<String>, CustomError> {
Ok(&self.revision)
}
/// The folder where nixos-rebuild is invoked and the outputs are linked.
pub(crate) fn get_build_directory<'target, 'root>(
&'target self,
config_root: &'root Config,
) -> Result<Cow<'target, Path>, CustomError> {
let target_directory = self.get_target_directory(config_root)?;
Ok(Cow::Owned(target_directory.join("build")))
}
/// The flake output attribute to build (the part after '#' in the build command).
pub(crate) fn get_attr(&'_ self) -> Result<&String, CustomError> {
Ok(&self.attr)
}
}