diff options
Diffstat (limited to 'nix/sparseTree/default.nix')
-rw-r--r-- | nix/sparseTree/default.nix | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/nix/sparseTree/default.nix b/nix/sparseTree/default.nix index 5184f33d5c..35fa459e1c 100644 --- a/nix/sparseTree/default.nix +++ b/nix/sparseTree/default.nix @@ -2,22 +2,33 @@ # and directories if they are listed in a supplied list: # # # A very minimal depot -# sparseTree ./depot [ -# ./default.nix -# ./depot/nix/readTree/default.nix -# ./third_party/nixpkgs -# ./third_party/overlays -# ] +# sparseTree { +# root = ./depot; +# paths = [ +# ./default.nix +# ./depot/nix/readTree/default.nix +# ./third_party/nixpkgs +# ./third_party/overlays +# ]; +# } { pkgs, lib, ... }: -# root path to use as a reference point -root: -# list of paths below `root` that should be -# included in the resulting directory -# -# If path, need to refer to the actual file / directory to be included. -# If a string, it is treated as a string relative to the root. -paths: +{ + # root path to use as a reference point + root +, # list of paths below `root` that should be + # included in the resulting directory + # + # If path, need to refer to the actual file / directory to be included. + # If a string, it is treated as a string relative to the root. + paths +, # (optional) name to use for the derivation + # + # This should always be set when using roots that do not have + # controlled names, such as when passing the top-level of a git + # repository (e.g. `depot.path.origSrc`). + name ? builtins.baseNameOf root +}: let rootLength = builtins.stringLength (toString root); @@ -45,14 +56,15 @@ let let withLeading = p: if builtins.substring 0 1 p == "/" then p else "/" + p; fullPath = - /**/ if builtins.isPath path then path + if builtins.isPath path then path else if builtins.isString path then (root + withLeading path) else builtins.throw "Unsupported path type ${builtins.typeOf path}"; strPath = toString fullPath; contextPath = "${fullPath}"; belowRoot = builtins.substring rootLength (-1) strPath; prefix = builtins.substring 0 rootLength strPath; - in assert toString root == prefix; { + in + assert toString root == prefix; { src = contextPath; dst = belowRoot; }; @@ -61,10 +73,12 @@ let in # TODO(sterni): teach readTree to also read symlinked directories, -# so we ln -sT instead of cp -aT. -pkgs.runCommandNoCC "sparse-${builtins.baseNameOf root}" {} ( - lib.concatMapStrings ({ src, dst }: '' - mkdir -p "$(dirname "$out${dst}")" - cp -aT --reflink=auto "${src}" "$out${dst}" - '') symlinks + # so we ln -sT instead of cp -aT. +pkgs.runCommand "sparse-${name}" { } ( + lib.concatMapStrings + ({ src, dst }: '' + mkdir -p "$(dirname "$out${dst}")" + cp -aT --reflink=auto "${src}" "$out${dst}" + '') + symlinks ) |