2022-11-29 06:52:21 +00:00
|
|
|
#!/usr/bin/env bash
|
2015-02-18 01:02:25 +00:00
|
|
|
set -e
|
2014-12-17 00:44:58 +00:00
|
|
|
|
|
|
|
: ${NIXOS_CHANNELS:=https://nixos.org/channels/}
|
2014-12-18 21:25:21 +00:00
|
|
|
: ${CHANNELS_NAMESPACE:=refs/heads/channels/}
|
|
|
|
|
|
|
|
# List all channels which are currently in the repository which we would
|
|
|
|
# have to remove if they are not found again.
|
2015-02-18 01:02:25 +00:00
|
|
|
deadChannels=$(git for-each-ref --format="%(refname)" "$CHANNELS_NAMESPACE")
|
2014-12-18 21:25:21 +00:00
|
|
|
|
2015-02-18 01:02:25 +00:00
|
|
|
updateRef() {
|
2014-12-18 21:25:21 +00:00
|
|
|
local channelName=$1
|
|
|
|
local newRev=$2
|
|
|
|
|
|
|
|
# if the inputs are not valid, then we do not update any branch.
|
|
|
|
test -z "$newRev" -o -z "$channelName" && return;
|
|
|
|
|
|
|
|
# Update the local refs/heads/channels/* branches to be in-sync with the
|
|
|
|
# channel references.
|
|
|
|
local branch=$CHANNELS_NAMESPACE$channelName
|
2015-02-18 01:02:25 +00:00
|
|
|
oldRev=$(git rev-parse --short "$branch" 2>/dev/null || true)
|
2014-12-18 21:25:21 +00:00
|
|
|
if test "$oldRev" != "$newRev"; then
|
2015-02-18 01:02:25 +00:00
|
|
|
if git update-ref "$branch" "$newRev" 2>/dev/null; then
|
2014-12-18 21:25:21 +00:00
|
|
|
if test -z "$oldRev"; then
|
|
|
|
echo " * [new branch] $newRev -> ${branch#refs/heads/}"
|
|
|
|
else
|
|
|
|
echo " $oldRev..$newRev -> ${branch#refs/heads/}"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if test -z "$oldRev"; then
|
|
|
|
echo " * [missing rev] $newRev -> ${branch#refs/heads/}"
|
|
|
|
else
|
|
|
|
echo " [missing rev] $oldRev..$newRev -> ${branch#refs/heads/}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Filter out the current channel from the list of dead channels.
|
2015-02-18 01:02:25 +00:00
|
|
|
deadChannels=$(grep -v "$CHANNELS_NAMESPACE$channelName" <<EOF
|
2014-12-18 21:25:21 +00:00
|
|
|
$deadChannels
|
|
|
|
EOF
|
2015-02-18 01:02:25 +00:00
|
|
|
) ||true
|
2014-12-18 21:25:21 +00:00
|
|
|
}
|
2014-12-17 00:44:58 +00:00
|
|
|
|
|
|
|
# Find the name of all channels which are listed in the directory.
|
2014-12-18 21:25:21 +00:00
|
|
|
echo "Fetching channels from $NIXOS_CHANNELS:"
|
2015-02-18 01:02:25 +00:00
|
|
|
for channelName in : $(curl -s "$NIXOS_CHANNELS" | sed -n '/folder/ { s,.*href=",,; s,/".*,,; p }'); do
|
2014-12-17 00:44:58 +00:00
|
|
|
test "$channelName" = : && continue;
|
|
|
|
|
|
|
|
# Do not follow redirections, such that we can extract the
|
|
|
|
# short-changeset from the name of the directory where we are
|
|
|
|
# redirected to.
|
2015-02-18 01:02:25 +00:00
|
|
|
sha1=$(curl -sI "$NIXOS_CHANNELS$channelName" | sed -n '/Location/ { s,.*\.\([a-f0-9]*\)[ \r]*$,\1,; p; }')
|
2014-12-17 00:44:58 +00:00
|
|
|
|
2014-12-18 21:25:21 +00:00
|
|
|
updateRef "remotes/$channelName" "$sha1"
|
2014-12-18 01:24:40 +00:00
|
|
|
done
|
|
|
|
|
2014-12-18 21:25:21 +00:00
|
|
|
echo "Fetching channels from nixos-version:"
|
2014-12-18 01:24:40 +00:00
|
|
|
if currentSystem=$(nixos-version 2>/dev/null); then
|
|
|
|
# If the system is entirely build from a custom nixpkgs version,
|
|
|
|
# then the version is not annotated in git version. This sed
|
|
|
|
# expression is basically matching that the expressions end with
|
|
|
|
# ".<sha1> (Name)" to extract the sha1.
|
2015-02-18 01:02:25 +00:00
|
|
|
sha1=$(echo "$currentSystem" | sed -n 's,^.*\.\([a-f0-9]*\) *(.*)$,\1,; T skip; p; :skip;')
|
2014-12-18 01:24:40 +00:00
|
|
|
|
2014-12-18 21:25:21 +00:00
|
|
|
updateRef current-system "$sha1"
|
2014-12-18 01:24:40 +00:00
|
|
|
fi
|
|
|
|
|
2015-02-18 01:02:25 +00:00
|
|
|
echo "Fetching channels from $HOME/.nix-defexpr:"
|
|
|
|
for revFile in : $(find -L "$HOME/.nix-defexpr/" -maxdepth 4 -name svn-revision); do
|
2014-12-18 01:24:40 +00:00
|
|
|
test "$revFile" = : && continue;
|
|
|
|
|
|
|
|
# Deconstruct a path such as, into:
|
2014-12-18 21:25:21 +00:00
|
|
|
#
|
2014-12-18 01:24:40 +00:00
|
|
|
# /home/luke/.nix-defexpr/channels_root/nixos/nixpkgs/svn-revision
|
2014-12-18 21:25:21 +00:00
|
|
|
# channelName = root/nixos
|
2014-12-18 01:24:40 +00:00
|
|
|
#
|
|
|
|
# /home/luke/.nix-defexpr/channels/nixpkgs/svn-revision
|
2014-12-18 21:25:21 +00:00
|
|
|
# channelName = nixpkgs
|
|
|
|
#
|
2014-12-18 01:24:40 +00:00
|
|
|
user=${revFile#*.nix-defexpr/channels}
|
|
|
|
repo=${user#*/}
|
|
|
|
repo=${repo%%/*}
|
|
|
|
user=${user%%/*}
|
|
|
|
user=${user#_}
|
|
|
|
test -z "$user" && user=$USER
|
2014-12-18 21:25:21 +00:00
|
|
|
channelName="$user${user:+/}$repo"
|
2014-12-18 01:24:40 +00:00
|
|
|
|
2015-02-18 01:02:25 +00:00
|
|
|
sha1=$(sed -n 's,^.*\.\([a-f0-9]*\)$,\1,; T skip; p; :skip;' "$revFile")
|
2014-12-18 01:24:40 +00:00
|
|
|
|
2014-12-18 21:25:21 +00:00
|
|
|
updateRef "$channelName" "$sha1"
|
2014-12-17 00:44:58 +00:00
|
|
|
done
|
2014-12-18 21:25:21 +00:00
|
|
|
|
|
|
|
# Suggest to remove channel branches which are no longer found by this
|
|
|
|
# script. This is to handle the cases where a local/remote channel
|
|
|
|
# disappear. We should not attempt to remove manually any branches, as they
|
|
|
|
# might be user branches.
|
|
|
|
if test -n "$deadChannels"; then
|
|
|
|
|
|
|
|
echo "
|
|
|
|
Some old channel branches are still in your repository, if you
|
|
|
|
want to remove them, run the following command(s):
|
|
|
|
"
|
|
|
|
|
|
|
|
while read branch; do
|
|
|
|
echo " git update-ref -d $branch"
|
|
|
|
done <<EOF
|
|
|
|
$deadChannels
|
|
|
|
EOF
|
|
|
|
|
|
|
|
echo
|
|
|
|
fi
|