Skip to content
This repository has been archived by the owner on Oct 15, 2022. It is now read-only.

Commit

Permalink
builder: mirror nix’s default.nix mechanism
Browse files Browse the repository at this point in the history
For a directory import like `import ./foo`, nix imports
`./foo/default.nix` but only prints `./foo` to its log output.
This commit reproduces that behaviour.

We were watching way too many files, e.g. `import <nixpkgs> {}` meant
we’d watch all of nixpkgs recursively. This should be solved now.

Fixes #58
  • Loading branch information
Profpatsch committed Oct 4, 2019
1 parent 35f8c4f commit 89b6fdd
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,21 @@ fn instrumented_instantiation(
.into_iter()
.fold((vec![], vec![]), |(mut paths, mut log_lines), result| {
match result {
LogDatum::CopiedSource(src)
| LogDatum::NixSourceFile(src)
| LogDatum::ReadFileOrDir(src) => {
LogDatum::CopiedSource(src) | LogDatum::ReadFileOrDir(src) => {
paths.push(src);
}
LogDatum::NixSourceFile(mut src) => {
// We need to emulate nix’s `default.nix` mechanism here.
// That is, if the user uses something like
// `import ./foo`
// and `foo` is a directory, nix will actually import
// `./foo/default.nix`
// but still print `./foo`.
// Since this is the only time directories are printed,
// we can just manually re-implement that behavior.
if src.is_dir() {
src.push("default.nix");
}
paths.push(src);
}
LogDatum::Text(line) => log_lines.push(line),
Expand Down

0 comments on commit 89b6fdd

Please sign in to comment.