refactor(nix): move isPathLike utility into //nix/utils
Change-Id: I040fbcbf1eefa69a2e37bf6e40fa6bc453ea1c90 Reviewed-on: https://cl.tvl.fyi/c/depot/+/13179 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: sterni <sternenseemann@systemli.org>
This commit is contained in:
parent
13723eb45f
commit
699826b831
2 changed files with 24 additions and 7 deletions
|
|
@ -148,6 +148,27 @@ let
|
|||
*/
|
||||
isSymlink = path: pathType' path ? symlink;
|
||||
|
||||
/* Checks whether the given value is (or contains) a reference to a
|
||||
path that will be retained in the store path resulting from a derivation.
|
||||
So if isReferencablePath returns true, the given value may be used in a
|
||||
way that allows accessing it at runtime of any Nix built program.
|
||||
|
||||
Returns true for:
|
||||
|
||||
- Strings with context (if the string is/contains a single path is not verified!)
|
||||
- Path values
|
||||
- Derivations
|
||||
|
||||
Note that the value still needs to used in a way that forces string context
|
||||
(and thus reference tracking) to be created, e.g. in string interpolation.
|
||||
|
||||
Type: any -> bool
|
||||
*/
|
||||
isReferencablePath = value:
|
||||
builtins.isPath value
|
||||
|| lib.isDerivation value
|
||||
|| (builtins.isString value && builtins.hasContext value);
|
||||
|
||||
in
|
||||
{
|
||||
inherit
|
||||
|
|
@ -156,5 +177,6 @@ in
|
|||
isDirectory
|
||||
isRegularFile
|
||||
isSymlink
|
||||
isReferencablePath
|
||||
;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
{ depot, lib, pkgs, ... }:
|
||||
let
|
||||
inherit (lib) fix pipe mapAttrsToList isAttrs concatLines isString isDerivation isPath;
|
||||
|
||||
# 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);
|
||||
inherit (depot.nix.utils) isReferencablePath;
|
||||
|
||||
esc = s: lib.escapeShellArg /* ensure paths import into store */ "${s}";
|
||||
|
||||
|
|
@ -16,7 +11,7 @@ let
|
|||
''
|
||||
+ pipe tree [
|
||||
(mapAttrsToList (k: v:
|
||||
if isPathLike v then
|
||||
if isReferencablePath v then
|
||||
"cp -R --reflink=auto ${esc "${v}"} \"$out/\"${esc path}/${esc k}"
|
||||
else if lib.isAttrs v then
|
||||
writeTreeAtPath (path + "/" + k) v
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue