From 19f2b1945063ddbe732bc219cc1fe4ef925c0660 Mon Sep 17 00:00:00 2001 From: Philip Patsch Date: Thu, 5 Sep 2019 16:32:11 +0200 Subject: [PATCH] =?UTF-8?q?builder:=20mirror=20nix=E2=80=99s=20`default.ni?= =?UTF-8?q?x`=20mechanism?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 {}` meant we’d watch all of nixpkgs recursively. This should be solved now. Fixes https://github.com/target/lorri/issues/58 --- src/builder.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 0305e542..29e8f859 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -99,9 +99,21 @@ fn instrumented_build( .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),