@@ -10,38 +10,103 @@
1010# commit.
1111{ url ? null # The git url, if empty it will be set to src.url
1212, branch ? null
13+, stableVersion ? false # Use version format according to RFC 107 (i.e. LAST_TAG+date=YYYY-MM-DD)
14+, tagPrefix ? "" # strip this prefix from a tag name when using stable version
1315}:
1416
1517let
1618 updateScript = writeShellScript "unstable-update-script.sh" ''
1719 set -ex
1820
19− url="$1"
21+ url=""
22+ branch=""
23+ use_stable_version=""
24+ tag_prefix=""
25+
26+ while (( $# > 0 )); do
27+ flag="$1"
28+ shift 1
29+ case "$flag" in
30+ --url=*)
31+ url="''${flag#*=}"
32+ ;;
33+ --branch=*)
34+ branch="''${flag#*=}"
35+ ;;
36+ --use-stable-version)
37+ use_stable_version=1
38+ ;;
39+ --tag-prefix=*)
40+ tag_prefix="''${flag#*=}"
41+ ;;
42+ *)
43+ echo "$0: unknown option ‘''${flag}’"
44+ exit 1
45+ ;;
46+ esac
47+ done
2048
2149 # By default we set url to src.url
2250 if [[ -z "$url" ]]; then
2351 url="$(${nix}/bin/nix-instantiate $systemArg --eval -E \
24− "with import ./. {}; $UPDATE_NIX_ATTR_PATH.src.url" \
52+ "with import ./. {}; $UPDATE_NIX_ATTR_PATH.src.url or $UPDATE_NIX_ATTR_PATH.src.meta.homepage" \
2553 | tr -d '"')"
2654 fi
2755
2856 # Get info about HEAD from a shallow git clone
2957 tmpdir="$(${coreutils}/bin/mktemp -d)"
30− ${git}/bin/git clone --bare --depth=1 \
31− ${lib.optionalString (branch != null) "--branch ${branch}"} \
32− "$url" "$tmpdir"
58+
59+ cloneArgs=(
60+ --bare
61+ --depth=1
62+ )
63+
64+ if [[ -n "$branch" ]]; then
65+ cloneArgs+=(--branch="$branch")
66+ fi
67+
68+ ${git}/bin/git clone "''${cloneArgs[@]}" "$url" "$tmpdir"
69+
3370 pushd "$tmpdir"
3471 commit_date="$(${git}/bin/git show -s --pretty='format:%cs')"
3572 commit_sha="$(${git}/bin/git show -s --pretty='format:%H')"
73+ if [[ -z "$use_stable_version" ]]; then
74+ new_version="unstable-$commit_date"
75+ else
76+ depth=100
77+ while (( $depth < 10000 )); do
78+ last_tag="$(${git}/bin/git describe --tags --abbrev=0 2> /dev/null || true)"
79+ if [[ -n "$last_tag" ]]; then
80+ break
81+ fi
82+ ${git}/bin/git fetch --depth="$depth" --tags
83+ depth=$(( $depth * 2 ))
84+ done
85+ if [[ -z "$last_tag" ]]; then
86+ echo "Cound not found a tag within last 10000 commits" > /dev/stderr
87+ exit 1
88+ fi
89+ if [[ -n "$tag_prefix" ]]; then
90+ last_tag="''${last_tag#$tag_prefix}"
91+ fi
92+ new_version="$last_tag+date=$commit_date"
93+ fi
3694 popd
37− ${coreutils}/bin/rm -rf "$tmpdir"
95+ # ${coreutils}/bin/rm -rf "$tmpdir"
3896
3997 # update the nix expression
4098 ${common-updater-scripts}/bin/update-source-version \
4199 "$UPDATE_NIX_ATTR_PATH" \
42− "unstable-$commit_date" \
100+ "$new_version" \
43101 --rev="$commit_sha"
44102 '';
45103
46−in [ updateScript url ]
47−
104+in [
105+ updateScript
106+ "--url=${builtins.toString url}"
107+] ++ lib.optionals (branch != null) [
108+ "--branch=${branch}"
109+] ++ lib.optionals stableVersion [
110+ "--use-stable-version"
111+ "--tag-prefix=${tagPrefix}"
112+]