From 3949cb255c5e4c43379130f4b081673b2a60c17a Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 5 Aug 2022 22:42:18 +0200 Subject: [PATCH] packages/build-support/hydrate-asset-directory: init --- packages/build-support/default.nix | 6 +++- .../hydrate-asset-directory/default.nix | 33 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 packages/build-support/hydrate-asset-directory/default.nix diff --git a/packages/build-support/default.nix b/packages/build-support/default.nix index b70cdaa..8adcf25 100644 --- a/packages/build-support/default.nix +++ b/packages/build-support/default.nix @@ -5,7 +5,11 @@ ./options.nix ]; - builders = { + builders = rec { fetchAsset = pkgs.callPackage ./fetch-asset { }; + + hydrateAssetDirectory = pkgs.callPackage ./hydrate-asset-directory { + inherit fetchAsset; + }; }; } diff --git a/packages/build-support/hydrate-asset-directory/default.nix b/packages/build-support/hydrate-asset-directory/default.nix new file mode 100644 index 0000000..d6ece4d --- /dev/null +++ b/packages/build-support/hydrate-asset-directory/default.nix @@ -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)} +''