Skip to content

Commit

Permalink
search: cache nix search and hide all eval warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed Feb 26, 2025
1 parent eef34a1 commit 22b4ebf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
24 changes: 20 additions & 4 deletions devenv/src/cnix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,20 @@ impl Nix {
Ok(())
}

pub async fn build(&self, attributes: &[&str]) -> Result<Vec<PathBuf>> {
pub async fn build(
&self,
attributes: &[&str],
options: Option<Options>,
) -> Result<Vec<PathBuf>> {
if attributes.is_empty() {
return Ok(Vec::new());
}

let options = Options {
let options = options.unwrap_or(Options {
cache_output: true,
..self.options
};
});

// TODO: use eval underneath
let mut args: Vec<String> = vec![
"build".to_string(),
Expand Down Expand Up @@ -272,7 +277,18 @@ impl Nix {
pub async fn search(&self, name: &str) -> Result<devenv_eval_cache::Output> {
self.run_nix_with_substituters(
"nix",
&["search", "--inputs-from", ".", "--json", "nixpkgs", name],
&[
"search",
"--inputs-from",
".",
"--quiet",
"--option",
"eval-cache",
"true",
"--json",
"nixpkgs",
name,
],
&self.options,
)
.await
Expand Down
30 changes: 22 additions & 8 deletions devenv/src/devenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl Devenv {

let container_store_path = self
.nix
.build(&[&format!("devenv.containers.{name}.derivation")])
.build(&[&format!("devenv.containers.{name}.derivation")], None)
.await?;
let container_store_path = container_store_path[0]
.to_str()
Expand Down Expand Up @@ -343,7 +343,7 @@ impl Devenv {
async move {
let copy_script = self
.nix
.build(&[&format!("devenv.containers.{name}.copyScript")])
.build(&[&format!("devenv.containers.{name}.copyScript")], None)
.await?;
let copy_script = &copy_script[0];
let copy_script_string = &copy_script.to_string_lossy();
Expand Down Expand Up @@ -393,7 +393,7 @@ impl Devenv {
async move {
let run_script = self
.nix
.build(&[&format!("devenv.containers.{name}.dockerRun")])
.build(&[&format!("devenv.containers.{name}.dockerRun")], None)
.await?;

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

let options = self.nix.build(&["optionsJSON"]).await?;
let build_options = cnix::Options {
logging: false,
cache_output: true,
..Default::default()
};
let options = self
.nix
.build(&["optionsJSON"], Some(build_options))
.await?;
let options_path = options[0]
.join("share")
.join("doc")
Expand Down Expand Up @@ -531,7 +539,7 @@ impl Devenv {
// TODO: No newline
let span = info_span!("tasks_run", devenv.user_message = "Evaluating tasks");
self.nix
.build(&["devenv.task.config"])
.build(&["devenv.task.config"], None)
.instrument(span)
.await?
};
Expand Down Expand Up @@ -566,7 +574,10 @@ impl Devenv {
// collect tests
let test_script = {
let span = info_span!("test", devenv.user_message = "Building tests");
self.nix.build(&["devenv.test"]).instrument(span).await?
self.nix
.build(&["devenv.test"], None)
.instrument(span)
.await?
};
let test_script = test_script[0].to_string_lossy().to_string();

Expand Down Expand Up @@ -643,7 +654,10 @@ impl Devenv {
};
let paths = self
.nix
.build(&attributes.iter().map(AsRef::as_ref).collect::<Vec<&str>>())
.build(
&attributes.iter().map(AsRef::as_ref).collect::<Vec<&str>>(),
None,
)
.await?;
for path in paths {
println!("{}", path.display());
Expand All @@ -668,7 +682,7 @@ impl Devenv {
devenv.user_message = "Building processes"
);
let proc_script_string = async {
let proc_script = self.nix.build(&["procfileScript"]).await?;
let proc_script = self.nix.build(&["procfileScript"], None).await?;
let proc_script_string = proc_script[0]
.to_str()
.expect("Failed to get proc script path")
Expand Down

0 comments on commit 22b4ebf

Please sign in to comment.