2 local FILE_TO_PATCH
="$1"
3 local SOURCETIME_PATH
="$2"
4 local FILE_TO_WORK_ON
="$(mktemp "$
(basename "$FILE_TO_PATCH").XXXXXX.tmp
")"
5 cat <<EOF >> "$FILE_TO_WORK_ON"
6 # Lines to add to PATH the source-time utilities for Nixpkgs packaging
7 if set -q NIXPKGS_SOURCETIME_PATH && test (count \$NIXPKGS_SOURCETIME_PATH) -gt 0
8 set --unpath NIXPKGS_SOURCETIME_PATH_OLD "\$NIXPKGS_SOURCETIME_PATH" \$NIXPKGS_SOURCETIME_PATH_OLD
10 set --path NIXPKGS_SOURCETIME_PATH $SOURCETIME_PATH
11 set -g --path PATH \$NIXPKGS_SOURCETIME_PATH \$PATH
12 # End of lines to add to PATH source-time utilities for Nixpkgs packaging
14 cat "$FILE_TO_PATCH" >> "$FILE_TO_WORK_ON"
15 cat <<EOF >> "$FILE_TO_WORK_ON"
16 # Lines to clean up inside PATH the source-time utilities for Nixpkgs packaging
17 if set -q PATH && test "\$PATH" != "" && test (count \$PATH) -ge (count \$NIXPKGS_SOURCETIME_PATH)
18 # Remove the inserted section
19 for i in (seq 0 (math (count \$PATH) - (count \$NIXPKGS_SOURCETIME_PATH)))
20 for j in (seq 1 (count \$NIXPKGS_SOURCETIME_PATH))
21 if test \$PATH[(math \$i + \$j)] != \$NIXPKGS_SOURCETIME_PATH[\$j]
30 set -g --path PATH \$PATH[(math (count \$NIXPKGS_SOURCETIME_PATH) + 1)..]
32 set -g --path PATH \$PATH[..\$i] \$PATH[(math (count \$NIXPKGS_SOURCETIME_PATH) + 1 + \$i)..]
37 if set -q NIXPKGS_SOURCETIME_PATH_OLD && test (count \$NIXPKGS_SOURCETIME_PATH_OLD) -gt 0
38 set --path NIXPKGS_SOURCETIME_PATH \$NIXPKGS_SOURCETIME_PATH_OLD[1]
39 set --unpath NIXPKGS_SOURCETIME_PATH_OLD \$NIXPKGS_SOURCETIME_PATH_OLD[2..]
41 set -e NIXPKGS_SOURCETIME_PATH
43 if set -q NIXPKGS_SOURCETIME_PATH_OLD && test (count \$NIXPKGS_SOURCETIME_PATH_OLD) -eq 0
44 set -e NIXPKGS_SOURCETIME_PATH_OLD
46 # End of lines to clean up inside PATH the source-time utilities for Nixpkgs packaging
48 cat "$FILE_TO_WORK_ON" > "$FILE_TO_PATCH"