3 , common-updater-scripts
16 , allowedVersions ? ""
17 , ignoredVersions ? ""
19 , odd-unstable ? false
20 , patchlevel-unstable ? false
24 # where to print git commands and debugging messages
25 fileForGitCommands = "update-git-commits.txt";
27 grep = lib.getExe gnugrep;
28 sed = lib.getExe gnused;
30 # shell script to update package
31 updateScript = writeScript "generic-update-script.sh" ''
45 patchlevel_unstable="$${10}"
47 [[ -n "$name" ]] || name="$UPDATE_NIX_NAME"
48 [[ -n "$pname" ]] || pname="$UPDATE_NIX_PNAME"
49 [[ -n "$version" ]] || version="$UPDATE_NIX_OLD_VERSION"
50 [[ -n "$attr_path" ]] || attr_path="$UPDATE_NIX_ATTR_PATH"
53 echo "# $name" >> ${fileForGitCommands}
55 function version_is_ignored() {
57 [ -n "$ignored_versions" ] && ${grep} -E -e "$ignored_versions" <<< "$tag"
60 function version_is_unstable() {
63 if [ -n "$odd_unstable" -o -n "$enforce" ]; then
64 local minor=$(echo "$tag" | ${sed} -rne 's,^[0-9]+\.([0-9]+).*,\1,p')
65 if [ $((minor % 2)) -eq 1 ]; then
69 if [ -n "$patchlevel_unstable" -o -n "$enforce" ]; then
70 local patchlevel=$(echo "$tag" | ${sed} -rne 's,^[0-9]+\.[0-9]+\.([0-9]+).*$,\1,p')
71 if ((patchlevel >= 90)); then
78 tags=$(sh -c "$version_lister --pname=$pname --attr-path=$attr_path --file=\"${fileForGitCommands}\"") || exit 1
80 # print available tags
82 echo "# found $pname version: $tag" >> ${fileForGitCommands}
85 # cut any revision prefix not used in the NixOS package version
86 if [ -n "$rev_prefix" ]; then
87 tags=$(echo "$tags" | ${grep} "^$rev_prefix")
88 tags=$(echo "$tags" | ${sed} -e "s,^$rev_prefix,,")
90 tags=$(echo "$tags" | ${grep} "^[0-9]")
91 if [ -n "$allowed_versions" ]; then
92 tags=$(echo "$tags" | ${grep} -E -e "$allowed_versions")
95 # sort the tags in decreasing order
96 tags=$(echo "$tags" | ${coreutils}/bin/sort --reverse --version-sort)
99 # do not consider development versions
100 for latest_tag in $tags; do
101 if version_is_ignored "$latest_tag"; then
102 echo "# skip ignored version: $pname-$latest_tag" >> ${fileForGitCommands}
104 elif version_is_unstable "$latest_tag"; then
105 echo "# skip development version: $pname-$latest_tag" >> ${fileForGitCommands}
108 if version_is_unstable "$latest_tag" "enforce"; then
109 echo "# use potential development version: $pname-$latest_tag" >> ${fileForGitCommands}
115 if [ -n "$latest_tag" ]; then
116 # print commands to commit the changes
117 if [ "$version" != "$latest_tag" ]; then
118 pfile=$(EDITOR=echo ${nix}/bin/nix edit --extra-experimental-features nix-command -f. "$attr_path")
119 echo " git add $pfile " >> ${fileForGitCommands}
120 echo " git commit -m '$attr_path: $version -> $latest_tag'" >> ${fileForGitCommands}
123 # update the nix expression
124 ${common-updater-scripts}/bin/update-source-version --print-changes "$attr_path" "$latest_tag"
126 # No changes for commit protocol.
130 echo "" >> ${fileForGitCommands}
134 name = "generic-update-script";
135 command = [ updateScript name pname version attrPath versionLister allowedVersions ignoredVersions rev-prefix odd-unstable patchlevel-unstable ];
136 supportedFeatures = [
137 # Stdout must contain output according to the updateScript commit protocol when the update script finishes with a non-zero exit code.