refactor: rename NixOptions to NixFlags

This helps differentiate in the code Nix's `--option` and other CLI
flags (previously referred to as options).
This commit is contained in:
ThinkChaos 2022-11-10 13:03:00 -05:00 committed by Zhaofeng Li
parent d73fa5d74f
commit 90c88ddd17
7 changed files with 50 additions and 50 deletions

View file

@ -105,7 +105,7 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
let target = { let target = {
if let Some(info) = hive.deployment_info_single(&hostname).await.unwrap() { if let Some(info) = hive.deployment_info_single(&hostname).await.unwrap() {
let nix_options = hive.nix_options_with_builders().await.unwrap(); let nix_options = hive.nix_flags_with_builders().await.unwrap();
if !info.allows_local_deployment() { if !info.allows_local_deployment() {
log::error!( log::error!(
"Local deployment is not enabled for host {}.", "Local deployment is not enabled for host {}.",

View file

@ -18,7 +18,7 @@ use futures::future::join_all;
use itertools::Itertools; use itertools::Itertools;
use tokio_stream::StreamExt; use tokio_stream::StreamExt;
use super::NixOptions; use super::NixFlags;
use crate::job::{JobHandle, JobMonitor, JobState, JobType}; use crate::job::{JobHandle, JobMonitor, JobState, JobType};
use crate::progress::Sender as ProgressSender; use crate::progress::Sender as ProgressSender;
use crate::util; use crate::util;
@ -50,7 +50,7 @@ pub struct Deployment {
options: Options, options: Options,
/// Options passed to Nix invocations. /// Options passed to Nix invocations.
nix_options: NixOptions, nix_options: NixFlags,
/// Handle to send messages to the ProgressOutput. /// Handle to send messages to the ProgressOutput.
progress: Option<ProgressSender>, progress: Option<ProgressSender>,
@ -103,7 +103,7 @@ impl Deployment {
hive, hive,
goal, goal,
options: Options::default(), options: Options::default(),
nix_options: NixOptions::default(), nix_options: NixFlags::default(),
progress, progress,
targets, targets,
parallelism_limit: ParallelismLimit::default(), parallelism_limit: ParallelismLimit::default(),
@ -129,7 +129,7 @@ impl Deployment {
monitor.set_label_width(width); monitor.set_label_width(width);
} }
let nix_options = self.hive.nix_options_with_builders().await?; let nix_options = self.hive.nix_flags_with_builders().await?;
self.nix_options = nix_options; self.nix_options = nix_options;
if self.goal == Goal::UploadKeys { if self.goal == Goal::UploadKeys {
@ -250,7 +250,7 @@ impl Deployment {
evaluator.set_job(job.clone()); evaluator.set_job(job.clone());
// FIXME: nix-eval-jobs currently does not support IFD with builders // FIXME: nix-eval-jobs currently does not support IFD with builders
let options = self.hive.nix_options(); let options = self.hive.nix_flags();
let mut stream = evaluator.evaluate(&expr, options).await?; let mut stream = evaluator.evaluate(&expr, options).await?;
let mut futures: Vec<tokio::task::JoinHandle<ColmenaResult<()>>> = Vec::new(); let mut futures: Vec<tokio::task::JoinHandle<ColmenaResult<()>>> = Vec::new();

View file

@ -17,7 +17,7 @@ use std::result::Result as StdResult;
use async_trait::async_trait; use async_trait::async_trait;
use futures::Stream; use futures::Stream;
use super::{BuildResult, NixExpression, NixOptions, StoreDerivation, StorePath}; use super::{BuildResult, NixExpression, NixFlags, StoreDerivation, StorePath};
use crate::error::{ColmenaError, ColmenaResult}; use crate::error::{ColmenaError, ColmenaResult};
use crate::job::JobHandle; use crate::job::JobHandle;
@ -61,7 +61,7 @@ pub trait DrvSetEvaluator {
async fn evaluate( async fn evaluate(
&self, &self,
expression: &dyn NixExpression, expression: &dyn NixExpression,
options: NixOptions, flags: NixFlags,
) -> ColmenaResult<Pin<Box<dyn Stream<Item = EvalResult>>>>; ) -> ColmenaResult<Pin<Box<dyn Stream<Item = EvalResult>>>>;
/// Sets the maximum number of attributes to evaluate at the same time. /// Sets the maximum number of attributes to evaluate at the same time.

View file

@ -19,7 +19,7 @@ use tokio::process::Command;
use super::{AttributeError, AttributeOutput, DrvSetEvaluator, EvalError, EvalResult}; use super::{AttributeError, AttributeOutput, DrvSetEvaluator, EvalError, EvalResult};
use crate::error::{ColmenaError, ColmenaResult}; use crate::error::{ColmenaError, ColmenaResult};
use crate::job::{null_job_handle, JobHandle}; use crate::job::{null_job_handle, JobHandle};
use crate::nix::{NixExpression, NixOptions, StorePath}; use crate::nix::{NixExpression, NixFlags, StorePath};
use crate::util::capture_stream; use crate::util::capture_stream;
/// The pinned nix-eval-jobs binary. /// The pinned nix-eval-jobs binary.
@ -74,7 +74,7 @@ impl DrvSetEvaluator for NixEvalJobs {
async fn evaluate( async fn evaluate(
&self, &self,
expression: &dyn NixExpression, expression: &dyn NixExpression,
options: NixOptions, flags: NixFlags,
) -> ColmenaResult<Pin<Box<dyn Stream<Item = EvalResult>>>> { ) -> ColmenaResult<Pin<Box<dyn Stream<Item = EvalResult>>>> {
let mut command = Command::new(&self.executable); let mut command = Command::new(&self.executable);
command command
@ -82,7 +82,7 @@ impl DrvSetEvaluator for NixEvalJobs {
.arg(self.workers.to_string()) .arg(self.workers.to_string())
.args(&["--expr", &expression.expression()]); .args(&["--expr", &expression.expression()]);
command.args(options.to_args()); command.args(flags.to_args());
if expression.requires_flakes() { if expression.requires_flakes() {
command.args(&["--extra-experimental-features", "flakes"]); command.args(&["--extra-experimental-features", "flakes"]);
@ -235,7 +235,7 @@ mod tests {
block_on(async move { block_on(async move {
let mut stream = evaluator let mut stream = evaluator
.evaluate(&expr, NixOptions::default()) .evaluate(&expr, NixFlags::default())
.await .await
.unwrap(); .unwrap();
let mut count = 0; let mut count = 0;
@ -259,7 +259,7 @@ mod tests {
block_on(async move { block_on(async move {
let mut stream = evaluator let mut stream = evaluator
.evaluate(&expr, NixOptions::default()) .evaluate(&expr, NixFlags::default())
.await .await
.unwrap(); .unwrap();
let mut count = 0; let mut count = 0;
@ -283,7 +283,7 @@ mod tests {
block_on(async move { block_on(async move {
let mut stream = evaluator let mut stream = evaluator
.evaluate(&expr, NixOptions::default()) .evaluate(&expr, NixFlags::default())
.await .await
.unwrap(); .unwrap();
let mut count = 0; let mut count = 0;
@ -323,7 +323,7 @@ mod tests {
block_on(async move { block_on(async move {
let mut stream = evaluator let mut stream = evaluator
.evaluate(&expr, NixOptions::default()) .evaluate(&expr, NixFlags::default())
.await .await
.unwrap(); .unwrap();
let mut count = 0; let mut count = 0;

View file

@ -13,7 +13,7 @@ use validator::Validate;
use super::deployment::TargetNode; use super::deployment::TargetNode;
use super::{ use super::{
Flake, MetaConfig, NixExpression, NixOptions, NodeConfig, NodeFilter, NodeName, Flake, MetaConfig, NixExpression, NixFlags, NodeConfig, NodeFilter, NodeName,
ProfileDerivation, SerializedNixExpression, StorePath, ProfileDerivation, SerializedNixExpression, StorePath,
}; };
use crate::error::ColmenaResult; use crate::error::ColmenaResult;
@ -140,25 +140,25 @@ impl Hive {
} }
/// Returns Nix options to set for this Hive. /// Returns Nix options to set for this Hive.
pub fn nix_options(&self) -> NixOptions { pub fn nix_flags(&self) -> NixFlags {
let mut options = NixOptions::default(); let mut flags = NixFlags::default();
options.set_show_trace(self.show_trace); flags.set_show_trace(self.show_trace);
options.set_pure_eval(self.path.is_flake()); flags.set_pure_eval(self.path.is_flake());
options.set_impure(self.impure); flags.set_impure(self.impure);
options.set_options(self.nix_options.clone()); flags.set_options(self.nix_options.clone());
options flags
} }
/// Returns Nix options to set for this Hive, with configured remote builders. /// Returns Nix flags to set for this Hive, with configured remote builders.
pub async fn nix_options_with_builders(&self) -> ColmenaResult<NixOptions> { pub async fn nix_flags_with_builders(&self) -> ColmenaResult<NixFlags> {
let mut options = NixOptions::default(); let mut flags = NixFlags::default();
options.set_show_trace(self.show_trace); flags.set_show_trace(self.show_trace);
if let Some(machines_file) = &self.get_meta_config().await?.machines_file { if let Some(machines_file) = &self.get_meta_config().await?.machines_file {
options.set_builders(Some(format!("@{}", machines_file))); flags.set_builders(Some(format!("@{}", machines_file)));
} }
Ok(options) Ok(flags)
} }
/// Convenience wrapper to filter nodes for CLI actions. /// Convenience wrapper to filter nodes for CLI actions.
@ -432,7 +432,7 @@ impl<'hive> NixInstantiate<'hive> {
fn eval(self) -> Command { fn eval(self) -> Command {
let mut command = self.instantiate(); let mut command = self.instantiate();
let options = self.hive.nix_options(); let flags = self.hive.nix_flags();
command command
.arg("--eval") .arg("--eval")
.arg("--json") .arg("--json")
@ -440,24 +440,24 @@ impl<'hive> NixInstantiate<'hive> {
// Ensures the derivations are instantiated // Ensures the derivations are instantiated
// Required for system profile evaluation and IFD // Required for system profile evaluation and IFD
.arg("--read-write-mode") .arg("--read-write-mode")
.args(options.to_args()); .args(flags.to_args());
command command
} }
async fn instantiate_with_builders(self) -> ColmenaResult<Command> { async fn instantiate_with_builders(self) -> ColmenaResult<Command> {
let options = self.hive.nix_options_with_builders().await?; let flags = self.hive.nix_flags_with_builders().await?;
let mut command = self.instantiate(); let mut command = self.instantiate();
command.args(options.to_args()); command.args(flags.to_args());
Ok(command) Ok(command)
} }
async fn eval_with_builders(self) -> ColmenaResult<Command> { async fn eval_with_builders(self) -> ColmenaResult<Command> {
let options = self.hive.nix_options_with_builders().await?; let flags = self.hive.nix_flags_with_builders().await?;
let mut command = self.eval(); let mut command = self.eval();
command.args(options.to_args()); command.args(flags.to_args());
Ok(command) Ok(command)
} }

View file

@ -8,7 +8,7 @@ use tokio::process::Command;
use super::{key_uploader, CopyDirection, CopyOptions, Host}; use super::{key_uploader, CopyDirection, CopyOptions, Host};
use crate::error::{ColmenaError, ColmenaResult}; use crate::error::{ColmenaError, ColmenaResult};
use crate::job::JobHandle; use crate::job::JobHandle;
use crate::nix::{Goal, Key, NixOptions, Profile, StorePath, CURRENT_PROFILE, SYSTEM_PROFILE}; use crate::nix::{Goal, Key, NixFlags, Profile, StorePath, CURRENT_PROFILE, SYSTEM_PROFILE};
use crate::util::{CommandExecution, CommandExt}; use crate::util::{CommandExecution, CommandExt};
/// The local machine running Colmena. /// The local machine running Colmena.
@ -18,12 +18,12 @@ use crate::util::{CommandExecution, CommandExt};
#[derive(Debug)] #[derive(Debug)]
pub struct Local { pub struct Local {
job: Option<JobHandle>, job: Option<JobHandle>,
nix_options: NixOptions, nix_options: NixFlags,
privilege_escalation_command: Option<Vec<String>>, privilege_escalation_command: Option<Vec<String>>,
} }
impl Local { impl Local {
pub fn new(nix_options: NixOptions) -> Self { pub fn new(nix_options: NixFlags) -> Self {
Self { Self {
job: None, job: None,
nix_options, nix_options,

View file

@ -91,9 +91,9 @@ pub struct MetaConfig {
pub machines_file: Option<String>, pub machines_file: Option<String>,
} }
/// Nix options. /// Nix CLI flags.
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
pub struct NixOptions { pub struct NixFlags {
/// Whether to pass --show-trace. /// Whether to pass --show-trace.
show_trace: bool, show_trace: bool,
@ -191,7 +191,7 @@ impl NodeConfig {
} }
} }
impl NixOptions { impl NixFlags {
pub fn set_show_trace(&mut self, show_trace: bool) { pub fn set_show_trace(&mut self, show_trace: bool) {
self.show_trace = show_trace; self.show_trace = show_trace;
} }
@ -213,10 +213,10 @@ impl NixOptions {
} }
pub fn to_args(&self) -> Vec<String> { pub fn to_args(&self) -> Vec<String> {
let mut options = Vec::new(); let mut args = Vec::new();
if let Some(builders) = &self.builders { if let Some(builders) = &self.builders {
options.append(&mut vec![ args.append(&mut vec![
"--option".to_string(), "--option".to_string(),
"builders".to_string(), "builders".to_string(),
builders.clone(), builders.clone(),
@ -224,24 +224,24 @@ impl NixOptions {
} }
if self.show_trace { if self.show_trace {
options.push("--show-trace".to_string()); args.push("--show-trace".to_string());
} }
if self.pure_eval { if self.pure_eval {
options.push("--pure-eval".to_string()); args.push("--pure-eval".to_string());
} }
if self.impure { if self.impure {
options.push("--impure".to_string()); args.push("--impure".to_string());
} }
for (name, value) in self.options.iter() { for (name, value) in self.options.iter() {
options.push("--option".to_string()); args.push("--option".to_string());
options.push(name.to_string()); args.push(name.to_string());
options.push(value.to_string()); args.push(value.to_string());
} }
options args
} }
} }