1 { stdenv, writeScript, coreutils, gnugrep, gnused, common-updater-scripts, nix }:
10 , patchlevel-unstable ? false
14 # where to print git commands and debugging messages
15 fileForGitCommands = "update-git-commits.txt";
17 # shell script to update package
18 updateScript = writeScript "update-script.sh" ''
30 patchlevel_unstable="$8"
33 echo "# $pname-$version" >> ${fileForGitCommands}
35 function version_is_ignored() {
37 [ -n "$ignored_versions" ] && grep -E "$ignored_versions" <<< "$tag"
40 function version_is_unstable() {
43 if [ -n "$odd_unstable" -o -n "$enforce" ]; then
44 local minor=$(echo "$tag" | ${gnused}/bin/sed -rne 's,^[0-9]+\.([0-9]+).*,\1,p')
45 if [ $((minor % 2)) -eq 1 ]; then
49 if [ -n "$patchlevel_unstable" -o -n "$enforce" ]; then
50 local patchlevel=$(echo "$tag" | ${gnused}/bin/sed -rne 's,^[0-9]+\.[0-9]+\.([0-9]+).*$,\1,p')
51 if ((patchlevel >= 90)); then
58 tags=$($version_lister $pname ${fileForGitCommands}) || exit 1
60 # print available tags
62 echo "# found $pname version: $tag" >> ${fileForGitCommands}
65 # cut any revision prefix not used in the NixOS package version
66 if [ -n "$rev_prefix" ]; then
67 tags=$(echo "$tags" | ${gnugrep}/bin/grep "^$rev_prefix")
68 tags=$(echo "$tags" | ${gnused}/bin/sed -e "s,^$rev_prefix,,")
70 tags=$(echo "$tags" | ${gnugrep}/bin/grep "^[0-9]")
72 # sort the tags in decreasing order
73 tags=$(echo "$tags" | ${coreutils}/bin/sort --reverse --version-sort)
76 # do not consider development versions
77 for latest_tag in $tags; do
78 if version_is_ignored "$latest_tag"; then
79 echo "# skip ignored version: $pname-$latest_tag" >> ${fileForGitCommands}
81 elif version_is_unstable "$latest_tag"; then
82 echo "# skip development version: $pname-$latest_tag" >> ${fileForGitCommands}
85 if version_is_unstable "$latest_tag" "enforce"; then
86 echo "# use potential development version: $pname-$latest_tag" >> ${fileForGitCommands}
92 if [ -n "$latest_tag" ]; then
93 # print commands to commit the changes
94 if [ "$version" != "$latest_tag" ]; then
95 pfile=$(EDITOR=echo ${nix}/bin/nix edit -f. "$attr_path")
96 echo " git add $pfile " >> ${fileForGitCommands}
97 echo " git commit -m '$attr_path: $version -> $latest_tag'" >> ${fileForGitCommands}
100 # update the nix expression
101 ${common-updater-scripts}/bin/update-source-version "$attr_path" "$latest_tag"
104 echo "" >> ${fileForGitCommands}
108 [ updateScript pname version attrPath versionLister ignoredVersions rev-prefix odd-unstable patchlevel-unstable ]