depot/packages/build-support/hydrate-asset-directory/default.nix

34 lines
892 B
Nix
Raw Normal View History

{ lib, fetchAsset, runCommandNoCC }:
rootDir: let
2022-10-17 15:38:55 +03:00
prefix = (toString rootDir) + "/";
files = lib.filesystem.listFilesRecursive rootDir;
hydrate = index: fetchAsset { inherit index; };
isDvc = file: lib.strings.hasSuffix ".dvc" (toString file);
relative = file: lib.strings.removePrefix prefix (toString file);
files' = builtins.partition isDvc files;
filesRaw = map relative files'.wrong;
filesDvc = map (file: rec {
dvc = hydrate file;
installPath = (builtins.dirOf (relative file)) + "/${dvc.name}";
}) files'.right;
installFile = file: "install -Dm644 ${file} $out/${file}";
installDvc = dvc: "install -Dm644 ${dvc.dvc} $out/${dvc.installPath}";
in runCommandNoCC (builtins.baseNameOf rootDir) {} ''
cd ${rootDir}
mkdir $out
${lib.concatStringsSep "\n" (map installFile filesRaw)}
${lib.concatStringsSep "\n" (map installDvc filesDvc)}
''