Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

devenv: caching fixes and improvements #1649

Merged
merged 3 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions devenv/src/cnix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ impl<'a> Nix<'a> {
cached_cmd.watch_path(self.devenv_root.join("devenv.yaml"));
cached_cmd.watch_path(self.devenv_root.join("devenv.lock"));

cached_cmd.unwatch_path(self.devenv_root.join(".devenv.flake.nix"));
// Ignore anything in .devenv.
cached_cmd.unwatch_path(&self.devenv_dotfile);

Expand Down Expand Up @@ -448,8 +447,8 @@ impl<'a> Nix<'a> {
options: &Options<'a>,
) -> Result<std::process::Command> {
let mut final_args = Vec::new();
let known_keys;
let pull_caches;
let known_keys_str;
let pull_caches_str;
let mut push_cache = None;

if !self.global_options.offline {
Expand All @@ -464,28 +463,31 @@ impl<'a> Nix<'a> {
push_cache = cachix_caches.caches.push.clone();
// handle cachix.pull
if !cachix_caches.caches.pull.is_empty() {
pull_caches = cachix_caches
let mut pull_caches = cachix_caches
.caches
.pull
.iter()
.map(|cache| format!("https://{}.cachix.org", cache))
.collect::<Vec<String>>()
.join(" ");
.collect::<Vec<String>>();
pull_caches.sort();
pull_caches_str = pull_caches.join(" ");
final_args.extend_from_slice(&[
"--option",
"extra-substituters",
&pull_caches,
&pull_caches_str,
]);
known_keys = cachix_caches

let mut known_keys = cachix_caches
.known_keys
.values()
.cloned()
.collect::<Vec<String>>()
.join(" ");
.collect::<Vec<String>>();
known_keys.sort();
known_keys_str = known_keys.join(" ");
final_args.extend_from_slice(&[
"--option",
"extra-trusted-public-keys",
&known_keys,
&known_keys_str,
]);
}
}
Expand Down
12 changes: 9 additions & 3 deletions devenv/src/devenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ impl Devenv {
$ devenv init
"});
}
std::fs::create_dir_all(&self.devenv_dot_gc)
fs::create_dir_all(&self.devenv_dot_gc)
.unwrap_or_else(|_| panic!("Failed to create {}", self.devenv_dot_gc.display()));

let mut flake_inputs = HashMap::new();
Expand Down Expand Up @@ -832,8 +832,14 @@ impl Devenv {
is_testing
);
let flake = FLAKE_TMPL.replace("__DEVENV_VARS__", &vars);
std::fs::write(self.devenv_root.join(DEVENV_FLAKE), flake)
.expect("Failed to write flake.nix");
let flake_path = self.devenv_root.join(DEVENV_FLAKE);

// Avoid writing the flake if it hasn't changed.
// direnv's watch_file triggers a reload based solely on mtime, which becomes annoying if we constantly touch this file.
let existing_flake = fs::read_to_string(&flake_path).unwrap_or_default();
if flake != existing_flake {
fs::write(flake_path, flake).expect("Failed to write flake.nix");
}

self.assembled = true;
Ok(())
Expand Down
Loading