feat(nix/writeTree): don't require IfD for drvs in tree
As far as I can tell we can handle files and directories using the same cp(1) invocation, so we no longer need to potentially IfD derivations in the tree to figure out whether they are files or directories. Change-Id: Iabe648c30a747fa42768558715e388552024764a Reviewed-on: https://cl.tvl.fyi/c/depot/+/10996 Reviewed-by: aspen <root@gws.fyi> Autosubmit: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
944483ef5e
commit
77a6eb4f51
1 changed files with 11 additions and 19 deletions
|
@ -1,8 +1,12 @@
|
|||
{ depot, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib) fix pipe mapAttrsToList isAttrs concatLines isString;
|
||||
inherit (lib) fix pipe mapAttrsToList isAttrs concatLines isString isDerivation isPath;
|
||||
|
||||
inherit (depot.nix.utils) isDirectory isRegularFile;
|
||||
# TODO(sterni): move to //nix/utils with clearer naming and alternative similar to lib.types.path
|
||||
isPathLike = value:
|
||||
isPath value
|
||||
|| isDerivation value
|
||||
|| (isString value && builtins.hasContext value);
|
||||
|
||||
esc = s: lib.escapeShellArg /* ensure paths import into store */ "${s}";
|
||||
|
||||
|
@ -12,24 +16,12 @@ let
|
|||
''
|
||||
+ pipe tree [
|
||||
(mapAttrsToList (k: v:
|
||||
# TODO(sterni): a more discoverable isPathLike would fit into //nix/utils
|
||||
# ATTN: This check has the flaw that it accepts paths without context
|
||||
# that would not be available in the sandbox!
|
||||
if lib.types.path.check v then
|
||||
if isRegularFile v then
|
||||
"cp --reflink=auto ${esc v} \"$out/\"${esc path}/${esc k}"
|
||||
else if isDirectory v then ''
|
||||
mkdir -p "$out/"${esc path}
|
||||
cp -r --reflink=auto ${esc v} "$out/"${esc path}/${esc k}
|
||||
''
|
||||
if isPathLike v then
|
||||
"cp -R --reflink=auto ${v} \"$out/\"${esc path}/${esc k}"
|
||||
else if lib.isAttrs v then
|
||||
writeTreeAtPath (path + "/" + k) v
|
||||
else
|
||||
throw "invalid path type (expected file or directory)"
|
||||
else if isAttrs v then
|
||||
writeTreeAtPath "${path}/${k}" v
|
||||
else if isString v then
|
||||
"cp --reflink=auto ${esc v} \"$out/\"${esc path}/${esc k}"
|
||||
else
|
||||
throw "invalid type (expected file, directory, or attrs)"))
|
||||
throw "invalid type (expected path, derivation, string with context, or attrs)"))
|
||||
concatLines
|
||||
];
|
||||
|
||||
|
|
Loading…
Reference in a new issue