2 , writeShellApplication
6 , common-updater-scripts
9 # This is an updater for unstable packages that should always use the latest
11 # To use this updater, add the following to your package set:
12 # passthru.updateScript = unstableGitUpdater { };
13 # relevant attributes can be passed as below:
15 { url ? null # The git url, if empty it will be set to src.gitRepoUrl
17 , hardcodeZeroVersion ? false # Use a made-up version "0" instead of latest tag. Use when the project's tagging system is incompatible with what we expect from versions
18 , tagFormat ? "*" # A `git describe --tags --match '<format>'` pattern that tags must match to be considered
19 , tagPrefix ? null # strip this prefix from a tag name
20 , tagConverter ? null # A command to convert more complex tag formats. It receives the git tag via stdin and should convert it into x.y.z format to stdout
24 assert lib.asserts.assertMsg (tagPrefix == null || tagConverter == null) "Can only use either tagPrefix or tagConverter!";
27 updateScript = writeShellApplication {
28 name = "unstable-update-script";
30 common-updater-scripts
40 hardcode_zero_version=""
47 while (( $# > 0 )); do
57 --hardcode-zero-version)
58 hardcode_zero_version=1
61 tag_format="''${flag#*=}"
64 tag_prefix="''${flag#*=}"
67 tag_converter="''${flag#*=}"
73 echo "$0: unknown option ‘''${flag}’"
79 # By default we set url to src.gitRepoUrl
80 if [[ -z "$url" ]]; then
81 # system argument cannot be passed as 1 argument
82 # shellcheck disable=SC2086
83 url="$(nix-instantiate $systemArg --eval -E \
84 "with import ./. {}; $UPDATE_NIX_ATTR_PATH.src.gitRepoUrl" \
88 # Get info about HEAD from a shallow git clone
93 if [[ "$shallow_clone" == "1" ]]; then
94 cloneArgs+=(--depth=1)
97 if [[ -n "$branch" ]]; then
98 cloneArgs+=(--branch="$branch")
101 git clone "''${cloneArgs[@]}" "$url" "$tmpdir"
103 git describe --tags --abbrev=0 --match "''${tag_format}" 2> /dev/null || true
107 commit_date="$(git show -s --pretty='format:%cs')"
108 commit_sha="$(git show -s --pretty='format:%H')"
110 if [[ -z "$hardcode_zero_version" ]]; then
111 if [[ "$shallow_clone" == "1" ]]; then
113 while (( depth < 10000 )); do
114 last_tag="$(getLatestVersion)"
115 if [[ -n "$last_tag" ]]; then
118 git fetch --depth="$depth" --tags
119 depth=$(( depth * 2 ))
122 if [[ -z "$last_tag" ]]; then
123 # To be extra sure, check if full history helps with finding a tag
125 last_tag="$(getLatestVersion)"
128 last_tag="$(getLatestVersion)"
130 if [[ -z "$last_tag" ]]; then
133 if [[ -n "$tag_prefix" ]]; then
134 echo "Stripping prefix '$tag_prefix' from tag '$last_tag'"
135 last_tag="''${last_tag#"''${tag_prefix}"}"
137 if [[ -n "$tag_converter" ]]; then
138 echo "Running '$last_tag' through: $tag_converter"
139 last_tag="$(echo "''${last_tag}" | ''${tag_converter})"
144 if [[ ! "$last_tag" =~ ^[[:digit:]] ]]; then
145 echo "Last tag '$last_tag' does not start with a digit" > /dev/stderr
148 new_version="$last_tag-unstable-$commit_date"
152 # update the nix expression
153 update-source-version \
154 "$UPDATE_NIX_ATTR_PATH" \
162 (lib.getExe updateScript)
163 "--url=${builtins.toString url}"
164 "--tag-format=${tagFormat}"
165 ] ++ lib.optionals (branch != null) [
167 ] ++ lib.optionals (tagPrefix != null) [
168 "--tag-prefix=${tagPrefix}"
169 ] ++ lib.optionals (tagConverter != null) [
170 "--tag-converter=${tagConverter}"
171 ] ++ lib.optionals hardcodeZeroVersion [
172 "--hardcode-zero-version"
173 ] ++ lib.optionals shallowClone [