diff options
author | sterni <sternenseemann@systemli.org> | 2021-10-09T14·48+0200 |
---|---|---|
committer | sterni <sternenseemann@systemli.org> | 2021-10-10T10·03+0000 |
commit | 2397fd8d569c5006b52a6afe677e0a597599c909 (patch) | |
tree | 5929bc49781cef048c6dd44e2748d26a8526e4ec /nix | |
parent | 04f7cc3880912abb738d3d3bc20e7622a211f25e (diff) |
feat(nix/sparseTree): allow specifying subtrees as relative paths r/2957
Passed strings will be treated as a relative path below the given root, which is quite convenient when using depot.path by eliminating a lot of repetition. Change-Id: I3da6058094484f4a6ffbb84f89ad4472b502a00c Reviewed-on: https://cl.tvl.fyi/c/depot/+/3704 Tested-by: BuildkiteCI Reviewed-by: tazjin <mail@tazj.in>
Diffstat (limited to 'nix')
-rw-r--r-- | nix/sparseTree/default.nix | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/nix/sparseTree/default.nix b/nix/sparseTree/default.nix index 569b9834b305..5184f33d5c46 100644 --- a/nix/sparseTree/default.nix +++ b/nix/sparseTree/default.nix @@ -14,6 +14,9 @@ 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: let @@ -40,8 +43,13 @@ let # a leading slash. Additionally some sanity checking is done. makeSymlink = path: let - strPath = toString path; - contextPath = "${path}"; + withLeading = p: if builtins.substring 0 1 p == "/" then p else "/" + p; + fullPath = + /**/ 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; { |