packages/build-support/hydrate-asset-directory: init
This commit is contained in:
parent
4a44f29e2b
commit
3949cb255c
2 changed files with 38 additions and 1 deletions
|
@ -5,7 +5,11 @@
|
|||
./options.nix
|
||||
];
|
||||
|
||||
builders = {
|
||||
builders = rec {
|
||||
fetchAsset = pkgs.callPackage ./fetch-asset { };
|
||||
|
||||
hydrateAssetDirectory = pkgs.callPackage ./hydrate-asset-directory {
|
||||
inherit fetchAsset;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
33
packages/build-support/hydrate-asset-directory/default.nix
Normal file
33
packages/build-support/hydrate-asset-directory/default.nix
Normal 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)}
|
||||
''
|
Loading…
Reference in a new issue