summary refs log tree commit diff
path: root/pkgs/build-support/substitute-files/substitute-all-files.nix
blob: aa600a76650c2b82e2ca50fa50d8793ba9c43fc9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{ stdenv }:

args:

stdenv.mkDerivation ({
  name = if args ? name then args.name else baseNameOf (toString args.src);
  builder = with stdenv.lib; builtins.toFile "builder.sh" ''
    source $stdenv/setup
    set -o pipefail

    eval "$preInstall"

    args=

    pushd "$src"
    echo -ne "${concatStringsSep "\\0" args.files}" | xargs -0 -n1 -I {} -- find {} -type f -print0 | while read -d "" line; do
      mkdir -p "$out/$(dirname "$line")"
      substituteAll "$line" "$out/$line"
    done
    popd

    eval "$postInstall"
  '';
  preferLocalBuild = true;
} // args)