packages/build-support/hydrate-asset-directory: init

This commit is contained in:
Max Headroom 2022-08-05 22:42:18 +02:00
parent 4a44f29e2b
commit 3949cb255c
2 changed files with 38 additions and 1 deletions

View file

@ -5,7 +5,11 @@
./options.nix
];
builders = {
builders = rec {
fetchAsset = pkgs.callPackage ./fetch-asset { };
hydrateAssetDirectory = pkgs.callPackage ./hydrate-asset-directory {
inherit fetchAsset;
};
};
}

View file

@ -0,0 +1,33 @@
{ lib, fetchAsset, runCommandNoCC }:
rootDir: let
prefix = ((toString rootDir) + "/");
files = lib.filesystem.listFilesRecursive rootDir;
hydrate = index: fetchAsset { inherit index; };
isDvc = lib.strings.hasSuffix ".dvc";
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)}
''