4 : ${NIXOS_CHANNELS:=https://nixos.org/channels/}
5 : ${CHANNELS_NAMESPACE:=refs/heads/channels/}
7 # List all channels which are currently in the repository which we would
8 # have to remove if they are not found again.
9 deadChannels
=$
(git for-each-ref
--format="%(refname)" "$CHANNELS_NAMESPACE")
15 # if the inputs are not valid, then we do not update any branch.
16 test -z "$newRev" -o -z "$channelName" && return;
18 # Update the local refs/heads/channels/* branches to be in-sync with the
20 local branch
=$CHANNELS_NAMESPACE$channelName
21 oldRev
=$
(git rev-parse
--short "$branch" 2>/dev
/null || true
)
22 if test "$oldRev" != "$newRev"; then
23 if git update-ref
"$branch" "$newRev" 2>/dev
/null
; then
24 if test -z "$oldRev"; then
25 echo " * [new branch] $newRev -> ${branch#refs/heads/}"
27 echo " $oldRev..$newRev -> ${branch#refs/heads/}"
30 if test -z "$oldRev"; then
31 echo " * [missing rev] $newRev -> ${branch#refs/heads/}"
33 echo " [missing rev] $oldRev..$newRev -> ${branch#refs/heads/}"
38 # Filter out the current channel from the list of dead channels.
39 deadChannels
=$
(grep -v "$CHANNELS_NAMESPACE$channelName" <<EOF
45 # Find the name of all channels which are listed in the directory.
46 echo "Fetching channels from $NIXOS_CHANNELS:"
47 for channelName
in : $
(curl
-s "$NIXOS_CHANNELS" |
sed -n '/folder/ { s,.*href=",,; s,/".*,,; p }'); do
48 test "$channelName" = : && continue;
50 # Do not follow redirections, such that we can extract the
51 # short-changeset from the name of the directory where we are
53 sha1
=$
(curl
-sI "$NIXOS_CHANNELS$channelName" |
sed -n '/Location/ { s,.*\.\([a-f0-9]*\)[ \r]*$,\1,; p; }')
55 updateRef
"remotes/$channelName" "$sha1"
58 echo "Fetching channels from nixos-version:"
59 if currentSystem
=$
(nixos-version
2>/dev
/null
); then
60 # If the system is entirely build from a custom nixpkgs version,
61 # then the version is not annotated in git version. This sed
62 # expression is basically matching that the expressions end with
63 # ".<sha1> (Name)" to extract the sha1.
64 sha1
=$
(echo "$currentSystem" |
sed -n 's,^.*\.\([a-f0-9]*\) *(.*)$,\1,; T skip; p; :skip;')
66 updateRef current-system
"$sha1"
69 echo "Fetching channels from $HOME/.nix-defexpr:"
70 for revFile
in : $
(find -L "$HOME/.nix-defexpr/" -maxdepth 4 -name svn-revision
); do
71 test "$revFile" = : && continue;
73 # Deconstruct a path such as, into:
75 # /home/luke/.nix-defexpr/channels_root/nixos/nixpkgs/svn-revision
76 # channelName = root/nixos
78 # /home/luke/.nix-defexpr/channels/nixpkgs/svn-revision
79 # channelName = nixpkgs
81 user
=${revFile#*.nix-defexpr/channels}
86 test -z "$user" && user
=$USER
87 channelName
="$user${user:+/}$repo"
89 sha1
=$
(sed -n 's,^.*\.\([a-f0-9]*\)$,\1,; T skip; p; :skip;' "$revFile")
91 updateRef
"$channelName" "$sha1"
94 # Suggest to remove channel branches which are no longer found by this
95 # script. This is to handle the cases where a local/remote channel
96 # disappear. We should not attempt to remove manually any branches, as they
97 # might be user branches.
98 if test -n "$deadChannels"; then
101 Some old channel branches are still in your repository, if you
102 want to remove them, run the following command(s):
105 while read branch
; do
106 echo " git update-ref -d $branch"