Skip to content

Commit 90c88dd

Browse files
ThinkChaoszhaofengli
authored andcommitted
refactor: rename NixOptions to NixFlags
This helps differentiate in the code Nix's `--option` and other CLI flags (previously referred to as options).
1 parent d73fa5d commit 90c88dd

File tree

7 files changed

+50
-50
lines changed

7 files changed

+50
-50
lines changed

src/command/apply_local.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub async fn run(_global_args: &ArgMatches, local_args: &ArgMatches) -> Result<(
105105

106106
let target = {
107107
if let Some(info) = hive.deployment_info_single(&hostname).await.unwrap() {
108-
let nix_options = hive.nix_options_with_builders().await.unwrap();
108+
let nix_options = hive.nix_flags_with_builders().await.unwrap();
109109
if !info.allows_local_deployment() {
110110
log::error!(
111111
"Local deployment is not enabled for host {}.",

src/nix/deployment/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use futures::future::join_all;
1818
use itertools::Itertools;
1919
use tokio_stream::StreamExt;
2020

21-
use super::NixOptions;
21+
use super::NixFlags;
2222
use crate::job::{JobHandle, JobMonitor, JobState, JobType};
2323
use crate::progress::Sender as ProgressSender;
2424
use crate::util;
@@ -50,7 +50,7 @@ pub struct Deployment {
5050
options: Options,
5151

5252
/// Options passed to Nix invocations.
53-
nix_options: NixOptions,
53+
nix_options: NixFlags,
5454

5555
/// Handle to send messages to the ProgressOutput.
5656
progress: Option<ProgressSender>,
@@ -103,7 +103,7 @@ impl Deployment {
103103
hive,
104104
goal,
105105
options: Options::default(),
106-
nix_options: NixOptions::default(),
106+
nix_options: NixFlags::default(),
107107
progress,
108108
targets,
109109
parallelism_limit: ParallelismLimit::default(),
@@ -129,7 +129,7 @@ impl Deployment {
129129
monitor.set_label_width(width);
130130
}
131131

132-
let nix_options = self.hive.nix_options_with_builders().await?;
132+
let nix_options = self.hive.nix_flags_with_builders().await?;
133133
self.nix_options = nix_options;
134134

135135
if self.goal == Goal::UploadKeys {
@@ -250,7 +250,7 @@ impl Deployment {
250250
evaluator.set_job(job.clone());
251251

252252
// FIXME: nix-eval-jobs currently does not support IFD with builders
253-
let options = self.hive.nix_options();
253+
let options = self.hive.nix_flags();
254254
let mut stream = evaluator.evaluate(&expr, options).await?;
255255

256256
let mut futures: Vec<tokio::task::JoinHandle<ColmenaResult<()>>> = Vec::new();

src/nix/evaluator/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::result::Result as StdResult;
1717
use async_trait::async_trait;
1818
use futures::Stream;
1919

20-
use super::{BuildResult, NixExpression, NixOptions, StoreDerivation, StorePath};
20+
use super::{BuildResult, NixExpression, NixFlags, StoreDerivation, StorePath};
2121
use crate::error::{ColmenaError, ColmenaResult};
2222
use crate::job::JobHandle;
2323

@@ -61,7 +61,7 @@ pub trait DrvSetEvaluator {
6161
async fn evaluate(
6262
&self,
6363
expression: &dyn NixExpression,
64-
options: NixOptions,
64+
flags: NixFlags,
6565
) -> ColmenaResult<Pin<Box<dyn Stream<Item = EvalResult>>>>;
6666

6767
/// Sets the maximum number of attributes to evaluate at the same time.

src/nix/evaluator/nix_eval_jobs.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use tokio::process::Command;
1919
use super::{AttributeError, AttributeOutput, DrvSetEvaluator, EvalError, EvalResult};
2020
use crate::error::{ColmenaError, ColmenaResult};
2121
use crate::job::{null_job_handle, JobHandle};
22-
use crate::nix::{NixExpression, NixOptions, StorePath};
22+
use crate::nix::{NixExpression, NixFlags, StorePath};
2323
use crate::util::capture_stream;
2424

2525
/// The pinned nix-eval-jobs binary.
@@ -74,15 +74,15 @@ impl DrvSetEvaluator for NixEvalJobs {
7474
async fn evaluate(
7575
&self,
7676
expression: &dyn NixExpression,
77-
options: NixOptions,
77+
flags: NixFlags,
7878
) -> ColmenaResult<Pin<Box<dyn Stream<Item = EvalResult>>>> {
7979
let mut command = Command::new(&self.executable);
8080
command
8181
.arg("--workers")
8282
.arg(self.workers.to_string())
8383
.args(&["--expr", &expression.expression()]);
8484

85-
command.args(options.to_args());
85+
command.args(flags.to_args());
8686

8787
if expression.requires_flakes() {
8888
command.args(&["--extra-experimental-features", "flakes"]);
@@ -235,7 +235,7 @@ mod tests {
235235

236236
block_on(async move {
237237
let mut stream = evaluator
238-
.evaluate(&expr, NixOptions::default())
238+
.evaluate(&expr, NixFlags::default())
239239
.await
240240
.unwrap();
241241
let mut count = 0;
@@ -259,7 +259,7 @@ mod tests {
259259

260260
block_on(async move {
261261
let mut stream = evaluator
262-
.evaluate(&expr, NixOptions::default())
262+
.evaluate(&expr, NixFlags::default())
263263
.await
264264
.unwrap();
265265
let mut count = 0;
@@ -283,7 +283,7 @@ mod tests {
283283

284284
block_on(async move {
285285
let mut stream = evaluator
286-
.evaluate(&expr, NixOptions::default())
286+
.evaluate(&expr, NixFlags::default())
287287
.await
288288
.unwrap();
289289
let mut count = 0;
@@ -323,7 +323,7 @@ mod tests {
323323

324324
block_on(async move {
325325
let mut stream = evaluator
326-
.evaluate(&expr, NixOptions::default())
326+
.evaluate(&expr, NixFlags::default())
327327
.await
328328
.unwrap();
329329
let mut count = 0;

src/nix/hive/mod.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use validator::Validate;
1313

1414
use super::deployment::TargetNode;
1515
use super::{
16-
Flake, MetaConfig, NixExpression, NixOptions, NodeConfig, NodeFilter, NodeName,
16+
Flake, MetaConfig, NixExpression, NixFlags, NodeConfig, NodeFilter, NodeName,
1717
ProfileDerivation, SerializedNixExpression, StorePath,
1818
};
1919
use crate::error::ColmenaResult;
@@ -140,25 +140,25 @@ impl Hive {
140140
}
141141

142142
/// Returns Nix options to set for this Hive.
143-
pub fn nix_options(&self) -> NixOptions {
144-
let mut options = NixOptions::default();
145-
options.set_show_trace(self.show_trace);
146-
options.set_pure_eval(self.path.is_flake());
147-
options.set_impure(self.impure);
148-
options.set_options(self.nix_options.clone());
149-
options
143+
pub fn nix_flags(&self) -> NixFlags {
144+
let mut flags = NixFlags::default();
145+
flags.set_show_trace(self.show_trace);
146+
flags.set_pure_eval(self.path.is_flake());
147+
flags.set_impure(self.impure);
148+
flags.set_options(self.nix_options.clone());
149+
flags
150150
}
151151

152-
/// Returns Nix options to set for this Hive, with configured remote builders.
153-
pub async fn nix_options_with_builders(&self) -> ColmenaResult<NixOptions> {
154-
let mut options = NixOptions::default();
155-
options.set_show_trace(self.show_trace);
152+
/// Returns Nix flags to set for this Hive, with configured remote builders.
153+
pub async fn nix_flags_with_builders(&self) -> ColmenaResult<NixFlags> {
154+
let mut flags = NixFlags::default();
155+
flags.set_show_trace(self.show_trace);
156156

157157
if let Some(machines_file) = &self.get_meta_config().await?.machines_file {
158-
options.set_builders(Some(format!("@{}", machines_file)));
158+
flags.set_builders(Some(format!("@{}", machines_file)));
159159
}
160160

161-
Ok(options)
161+
Ok(flags)
162162
}
163163

164164
/// Convenience wrapper to filter nodes for CLI actions.
@@ -432,32 +432,32 @@ impl<'hive> NixInstantiate<'hive> {
432432

433433
fn eval(self) -> Command {
434434
let mut command = self.instantiate();
435-
let options = self.hive.nix_options();
435+
let flags = self.hive.nix_flags();
436436
command
437437
.arg("--eval")
438438
.arg("--json")
439439
.arg("--strict")
440440
// Ensures the derivations are instantiated
441441
// Required for system profile evaluation and IFD
442442
.arg("--read-write-mode")
443-
.args(options.to_args());
443+
.args(flags.to_args());
444444
command
445445
}
446446

447447
async fn instantiate_with_builders(self) -> ColmenaResult<Command> {
448-
let options = self.hive.nix_options_with_builders().await?;
448+
let flags = self.hive.nix_flags_with_builders().await?;
449449
let mut command = self.instantiate();
450450

451-
command.args(options.to_args());
451+
command.args(flags.to_args());
452452

453453
Ok(command)
454454
}
455455

456456
async fn eval_with_builders(self) -> ColmenaResult<Command> {
457-
let options = self.hive.nix_options_with_builders().await?;
457+
let flags = self.hive.nix_flags_with_builders().await?;
458458
let mut command = self.eval();
459459

460-
command.args(options.to_args());
460+
command.args(flags.to_args());
461461

462462
Ok(command)
463463
}

src/nix/host/local.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tokio::process::Command;
88
use super::{key_uploader, CopyDirection, CopyOptions, Host};
99
use crate::error::{ColmenaError, ColmenaResult};
1010
use crate::job::JobHandle;
11-
use crate::nix::{Goal, Key, NixOptions, Profile, StorePath, CURRENT_PROFILE, SYSTEM_PROFILE};
11+
use crate::nix::{Goal, Key, NixFlags, Profile, StorePath, CURRENT_PROFILE, SYSTEM_PROFILE};
1212
use crate::util::{CommandExecution, CommandExt};
1313

1414
/// The local machine running Colmena.
@@ -18,12 +18,12 @@ use crate::util::{CommandExecution, CommandExt};
1818
#[derive(Debug)]
1919
pub struct Local {
2020
job: Option<JobHandle>,
21-
nix_options: NixOptions,
21+
nix_options: NixFlags,
2222
privilege_escalation_command: Option<Vec<String>>,
2323
}
2424

2525
impl Local {
26-
pub fn new(nix_options: NixOptions) -> Self {
26+
pub fn new(nix_options: NixFlags) -> Self {
2727
Self {
2828
job: None,
2929
nix_options,

src/nix/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ pub struct MetaConfig {
9191
pub machines_file: Option<String>,
9292
}
9393

94-
/// Nix options.
94+
/// Nix CLI flags.
9595
#[derive(Debug, Clone, Default)]
96-
pub struct NixOptions {
96+
pub struct NixFlags {
9797
/// Whether to pass --show-trace.
9898
show_trace: bool,
9999

@@ -191,7 +191,7 @@ impl NodeConfig {
191191
}
192192
}
193193

194-
impl NixOptions {
194+
impl NixFlags {
195195
pub fn set_show_trace(&mut self, show_trace: bool) {
196196
self.show_trace = show_trace;
197197
}
@@ -213,35 +213,35 @@ impl NixOptions {
213213
}
214214

215215
pub fn to_args(&self) -> Vec<String> {
216-
let mut options = Vec::new();
216+
let mut args = Vec::new();
217217

218218
if let Some(builders) = &self.builders {
219-
options.append(&mut vec![
219+
args.append(&mut vec![
220220
"--option".to_string(),
221221
"builders".to_string(),
222222
builders.clone(),
223223
]);
224224
}
225225

226226
if self.show_trace {
227-
options.push("--show-trace".to_string());
227+
args.push("--show-trace".to_string());
228228
}
229229

230230
if self.pure_eval {
231-
options.push("--pure-eval".to_string());
231+
args.push("--pure-eval".to_string());
232232
}
233233

234234
if self.impure {
235-
options.push("--impure".to_string());
235+
args.push("--impure".to_string());
236236
}
237237

238238
for (name, value) in self.options.iter() {
239-
options.push("--option".to_string());
240-
options.push(name.to_string());
241-
options.push(value.to_string());
239+
args.push("--option".to_string());
240+
args.push(name.to_string());
241+
args.push(value.to_string());
242242
}
243243

244-
options
244+
args
245245
}
246246
}
247247

0 commit comments

Comments
 (0)