diff --git a/builder.nix b/builder.nix index f21961b..d98ff37 100644 --- a/builder.nix +++ b/builder.nix @@ -20,7 +20,7 @@ let funcPkgs = { __functor = self: arg: resolve arg; src = getSrc root rcwd filter; - inherit pkgs cwd rcwd; + inherit pkgs cwd rcwd d1 d2; }; _builder = let diff --git a/lib.nix b/lib.nix index c32aef8..776e821 100644 --- a/lib.nix +++ b/lib.nix @@ -1,10 +1,10 @@ { lib ? import }: let inherit (builtins) baseNameOf dirOf length genList pathExists filterSource - isString match replaceStrings; + isString match replaceStrings stringLength; inherit (lib) take splitString concatStringsSep last foldl foldr head tail singleton removePrefix hasSuffix removeSuffix flatten crossLists reverseList - all any unique; + all any unique hasPrefix; butlast = list: take (length list - 1) list; doFileSuffix = "do"; @@ -77,7 +77,7 @@ let # Add all preceding paths to a src down to the root. Otherwise # builtins.filterSource will reject it. augmentedSrcs = root: srcs: let - aug = map (s: singleton s ++ (map (p: root + (removeSuffix "/" p)) (genPathlist (removePrefix root s)))) srcs; + aug = map (s: (map (p: root + (removeSuffix "/" p)) (genPathlist (removePrefix root s)))) srcs; in unique (flatten aug); # The source tree resolver combinator. @@ -90,15 +90,25 @@ let captureFunc (resolveSrc root rcwd) (srcs: let rejector = path: (all (x: path != x) rejected); + + # If a src in srcs is a prefix to a that (it must be a dir, then, or the + # file itself), allow all sub-paths. + srcFilter = path: + if srcs == [] + then true + else (any (x: (hasPrefix x path)) srcs); + + # Allow all directories lying on the way to specified srcs. _srcs = (augmentedSrcs root srcs); - srcFilter = path: if srcs == [] + srcDirFilter = path: if srcs == [] then true # No explicit srcs means: Take the whole source tree! - else (any (x: path == x) _srcs); + else (any (x: path == x) (_srcs)); filter = (path: type: (baseNameOf path != ".git") && (baseNameOf path != ".envrc") && (rejector path) && - (srcFilter path)); + ((srcFilter path) || + (srcDirFilter path))); in (builtins.filterSource filter root)); self = {