diff options
author | sterni <sternenseemann@systemli.org> | 2024-02-20T16·49+0100 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-02-21T20·52+0000 |
commit | 77a6eb4f512b6d8ae94b82677d8efe3eacf8cfa8 (patch) | |
tree | 5788cd461d854c3a67940aeebdeb60b2068635ae /nix | |
parent | 944483ef5e3536c96bf9120ef2054aa520cf6e60 (diff) |
feat(nix/writeTree): don't require IfD for drvs in tree r/7590
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
Diffstat (limited to 'nix')
-rw-r--r-- | nix/writeTree/default.nix | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/nix/writeTree/default.nix b/nix/writeTree/default.nix index 43ece9b19f97..0c7c2a130feb 100644 --- a/nix/writeTree/default.nix +++ b/nix/writeTree/default.nix @@ -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} - '' - 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}" + 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 type (expected file, directory, or attrs)")) + throw "invalid type (expected path, derivation, string with context, or attrs)")) concatLines ]; |