From 7d4eb3f1b7c74b3812c1873b6136a18387310bb8 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Wed, 13 Sep 2023 22:26:16 +0200 Subject: [PATCH] lib.fileset.toSource: Evaluate fileset even for empty directories --- lib/fileset/default.nix | 4 +++- lib/fileset/internal.nix | 1 + lib/fileset/tests.sh | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/fileset/default.nix b/lib/fileset/default.nix index b30125265520..51002332a319 100644 --- a/lib/fileset/default.nix +++ b/lib/fileset/default.nix @@ -92,6 +92,7 @@ The only way to change which files get added to the store is by changing the `fi fileset = _coerce "lib.fileset.toSource: `fileset`" filesetPath; rootFilesystemRoot = (splitRoot root).root; filesetFilesystemRoot = (splitRoot fileset._internalBase).root; + filter = _toSourceFilter fileset; in if ! isPath root then if isStringLike root then @@ -123,9 +124,10 @@ The only way to change which files get added to the store is by changing the `fi - Set `root` to ${toString fileset._internalBase} or any directory higher up. This changes the layout of the resulting store path. - Set `fileset` to a file set that cannot contain files outside the `root` ${toString root}. This could change the files included in the result.'' else + builtins.seq filter cleanSourceWith { name = "source"; src = root; - filter = _toSourceFilter fileset; + inherit filter; }; } diff --git a/lib/fileset/internal.nix b/lib/fileset/internal.nix index ae8eb20e3ed2..946ea1014f30 100644 --- a/lib/fileset/internal.nix +++ b/lib/fileset/internal.nix @@ -294,6 +294,7 @@ rec { in # Special case because the code below assumes that the _internalBase is always included in the result # which shouldn't be done when we have no files at all in the base + # This also forces the tree before returning the filter, leads to earlier error messages if tree == null then empty else diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh index e27610573a86..5bd798ae7942 100755 --- a/lib/fileset/tests.sh +++ b/lib/fileset/tests.sh @@ -246,6 +246,9 @@ expectFailure 'toSource { root = ./a; fileset = ./a; }' 'lib.fileset.toSource: ` \s*- If you want to import the file into the store _with_ a containing directory, set `root` to the containing directory, such as '"$work"', and set `fileset` to the file path.' rm -rf * +# The fileset argument should be evaluated, even if the directory is empty +expectFailure 'toSource { root = ./.; fileset = abort "This should be evaluated"; }' 'evaluation aborted with the following error message: '\''This should be evaluated'\' + # Only paths under `root` should be able to influence the result mkdir a expectFailure 'toSource { root = ./a; fileset = ./.; }' 'lib.fileset.toSource: `fileset` could contain files in '"$work"', which is not under the `root` '"$work"'/a. Potential solutions: