Skip to content

Commit 22b4ebf

Browse files
committed
search: cache nix search and hide all eval warnings
1 parent eef34a1 commit 22b4ebf

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

devenv/src/cnix.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,20 @@ impl Nix {
186186
Ok(())
187187
}
188188

189-
pub async fn build(&self, attributes: &[&str]) -> Result<Vec<PathBuf>> {
189+
pub async fn build(
190+
&self,
191+
attributes: &[&str],
192+
options: Option<Options>,
193+
) -> Result<Vec<PathBuf>> {
190194
if attributes.is_empty() {
191195
return Ok(Vec::new());
192196
}
193197

194-
let options = Options {
198+
let options = options.unwrap_or(Options {
195199
cache_output: true,
196200
..self.options
197-
};
201+
});
202+
198203
// TODO: use eval underneath
199204
let mut args: Vec<String> = vec![
200205
"build".to_string(),
@@ -272,7 +277,18 @@ impl Nix {
272277
pub async fn search(&self, name: &str) -> Result<devenv_eval_cache::Output> {
273278
self.run_nix_with_substituters(
274279
"nix",
275-
&["search", "--inputs-from", ".", "--json", "nixpkgs", name],
280+
&[
281+
"search",
282+
"--inputs-from",
283+
".",
284+
"--quiet",
285+
"--option",
286+
"eval-cache",
287+
"true",
288+
"--json",
289+
"nixpkgs",
290+
name,
291+
],
276292
&self.options,
277293
)
278294
.await

devenv/src/devenv.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ impl Devenv {
314314

315315
let container_store_path = self
316316
.nix
317-
.build(&[&format!("devenv.containers.{name}.derivation")])
317+
.build(&[&format!("devenv.containers.{name}.derivation")], None)
318318
.await?;
319319
let container_store_path = container_store_path[0]
320320
.to_str()
@@ -343,7 +343,7 @@ impl Devenv {
343343
async move {
344344
let copy_script = self
345345
.nix
346-
.build(&[&format!("devenv.containers.{name}.copyScript")])
346+
.build(&[&format!("devenv.containers.{name}.copyScript")], None)
347347
.await?;
348348
let copy_script = &copy_script[0];
349349
let copy_script_string = &copy_script.to_string_lossy();
@@ -393,7 +393,7 @@ impl Devenv {
393393
async move {
394394
let run_script = self
395395
.nix
396-
.build(&[&format!("devenv.containers.{name}.dockerRun")])
396+
.build(&[&format!("devenv.containers.{name}.dockerRun")], None)
397397
.await?;
398398

399399
let status = std::process::Command::new(&run_script[0])
@@ -462,7 +462,15 @@ impl Devenv {
462462
pub async fn search(&mut self, name: &str) -> Result<()> {
463463
self.assemble(false)?;
464464

465-
let options = self.nix.build(&["optionsJSON"]).await?;
465+
let build_options = cnix::Options {
466+
logging: false,
467+
cache_output: true,
468+
..Default::default()
469+
};
470+
let options = self
471+
.nix
472+
.build(&["optionsJSON"], Some(build_options))
473+
.await?;
466474
let options_path = options[0]
467475
.join("share")
468476
.join("doc")
@@ -531,7 +539,7 @@ impl Devenv {
531539
// TODO: No newline
532540
let span = info_span!("tasks_run", devenv.user_message = "Evaluating tasks");
533541
self.nix
534-
.build(&["devenv.task.config"])
542+
.build(&["devenv.task.config"], None)
535543
.instrument(span)
536544
.await?
537545
};
@@ -566,7 +574,10 @@ impl Devenv {
566574
// collect tests
567575
let test_script = {
568576
let span = info_span!("test", devenv.user_message = "Building tests");
569-
self.nix.build(&["devenv.test"]).instrument(span).await?
577+
self.nix
578+
.build(&["devenv.test"], None)
579+
.instrument(span)
580+
.await?
570581
};
571582
let test_script = test_script[0].to_string_lossy().to_string();
572583

@@ -643,7 +654,10 @@ impl Devenv {
643654
};
644655
let paths = self
645656
.nix
646-
.build(&attributes.iter().map(AsRef::as_ref).collect::<Vec<&str>>())
657+
.build(
658+
&attributes.iter().map(AsRef::as_ref).collect::<Vec<&str>>(),
659+
None,
660+
)
647661
.await?;
648662
for path in paths {
649663
println!("{}", path.display());
@@ -668,7 +682,7 @@ impl Devenv {
668682
devenv.user_message = "Building processes"
669683
);
670684
let proc_script_string = async {
671-
let proc_script = self.nix.build(&["procfileScript"]).await?;
685+
let proc_script = self.nix.build(&["procfileScript"], None).await?;
672686
let proc_script_string = proc_script[0]
673687
.to_str()
674688
.expect("Failed to get proc script path")

0 commit comments

Comments
 (0)