From f0c21ab3f74127c8614500d6f8aa9cf7ccb36842 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Wed, 17 Dec 2014 00:44:58 +0000 Subject: [PATCH 1/3] Add a script to add git branches for each channel. --- maintainers/scripts/update-channel-branches.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100755 maintainers/scripts/update-channel-branches.sh diff --git a/maintainers/scripts/update-channel-branches.sh b/maintainers/scripts/update-channel-branches.sh new file mode 100755 index 00000000000..0157fe1db10 --- /dev/null +++ b/maintainers/scripts/update-channel-branches.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +: ${NIXOS_CHANNELS:=https://nixos.org/channels/} + +# Find the name of all channels which are listed in the directory. +for channelName in : $(curl -s $NIXOS_CHANNELS | sed -n '/folder/ { s,.*href=",,; s,/".*,,; p }'); do + 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. + sha1=$(curl -s --max-redirs 0 $NIXOS_CHANNELS$channelName | sed -n '/has moved/ { s,.*\.\([a-z0-9A-Z]*\)".*,\1,; p; }') + test -z "$sha1" -o -z "$channelName" && continue; + + # Update the local channels/* branches to be in-sync with the + # channel references. + git update-ref refs/heads/channels/$channelName $sha1 +done From d7edec4888fae4bd4611d94e89b1af234fdacbc4 Mon Sep 17 00:00:00 2001 From: Nicolas Pierron Date: Thu, 18 Dec 2014 01:24:40 +0000 Subject: [PATCH 2/3] Add other source of channels, and distinguish between local and remote channels. --- .../scripts/update-channel-branches.sh | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/maintainers/scripts/update-channel-branches.sh b/maintainers/scripts/update-channel-branches.sh index 0157fe1db10..d7fbcb75690 100755 --- a/maintainers/scripts/update-channel-branches.sh +++ b/maintainers/scripts/update-channel-branches.sh @@ -9,10 +9,51 @@ for channelName in : $(curl -s $NIXOS_CHANNELS | sed -n '/folder/ { s,.*href=",, # Do not follow redirections, such that we can extract the # short-changeset from the name of the directory where we are # redirected to. - sha1=$(curl -s --max-redirs 0 $NIXOS_CHANNELS$channelName | sed -n '/has moved/ { s,.*\.\([a-z0-9A-Z]*\)".*,\1,; p; }') + sha1=$(curl -sI $NIXOS_CHANNELS$channelName | sed -n '/Location/ { s,.*\.\([a-f0-9]*\)[ \r]*$,\1,; p; }') test -z "$sha1" -o -z "$channelName" && continue; - # Update the local channels/* branches to be in-sync with the - # channel references. - git update-ref refs/heads/channels/$channelName $sha1 + # Update the local refs/heads/channels/remotes/* branches to be + # in-sync with the channel references. + git update-ref refs/heads/channels/remotes/$channelName $sha1 +done + +if currentSystem=$(nixos-version 2>/dev/null); then + channelName=current-system + + # 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 + # ". (Name)" to extract the sha1. + sha1=$(echo $currentSystem | sed -n 's,^.*\.\([a-f0-9]*\) *(.*)$,\1,; T skip; p; :skip;') + if test -n "$sha1"; then + + # Update the local refs/heads/channels/locals/* branches to be + # in-sync with the channel references. + git update-ref refs/heads/channels/locals/$channelName $sha1 + fi +fi + +for revFile in : $(find -L ~/.nix-defexpr/ -maxdepth 4 -name svn-revision); do + test "$revFile" = : && continue; + + # Deconstruct a path such as, into: + # /home/luke/.nix-defexpr/channels_root/nixos/nixpkgs/svn-revision + # user=root repo=nixos channelName=root/nixos + # + # /home/luke/.nix-defexpr/channels/nixpkgs/svn-revision + # user=luke repo=nixpkgs channelName=luke/nixpkgs + user=${revFile#*.nix-defexpr/channels} + repo=${user#*/} + repo=${repo%%/*} + user=${user%%/*} + user=${user#_} + test -z "$user" && user=$USER + channelName="$user/$repo" + + sha1=$(cat $revFile | sed -n 's,^.*\.\([a-f0-9]*\)$,\1,; T skip; p; :skip;') + test -z "$sha1" -o -z "$channelName" && continue; + + # Update the local refs/heads/channels/locals/* branches to be + # in-sync with the channel references. + git update-ref refs/heads/channels/locals/$channelName $sha1 done From 9334085e80600e4baf9561b3a9836937a6f73d5f Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Thu, 18 Dec 2014 22:25:21 +0100 Subject: [PATCH 3/3] update-channel-branches.sh: Add verbosity to improve the user experience, and update NixOS documentation. --- .../scripts/update-channel-branches.sh | 88 +++++++++++++++---- nixos/doc/manual/development/sources.xml | 18 ++-- 2 files changed, 80 insertions(+), 26 deletions(-) diff --git a/maintainers/scripts/update-channel-branches.sh b/maintainers/scripts/update-channel-branches.sh index d7fbcb75690..5dbbec9393c 100755 --- a/maintainers/scripts/update-channel-branches.sh +++ b/maintainers/scripts/update-channel-branches.sh @@ -1,8 +1,48 @@ #!/bin/sh : ${NIXOS_CHANNELS:=https://nixos.org/channels/} +: ${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. +deadChannels=$(git for-each-ref --format="%(refname)" $CHANNELS_NAMESPACE) + +function updateRef() { + 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 + oldRev=$(git rev-parse --short $branch 2>/dev/null || true) + if test "$oldRev" != "$newRev"; then + if git update-ref $branch $newRev 2>/dev/null; then + 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. + deadChannels=$(grep -v $CHANNELS_NAMESPACE$channelName </dev/null); then - channelName=current-system - # 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 # ". (Name)" to extract the sha1. sha1=$(echo $currentSystem | sed -n 's,^.*\.\([a-f0-9]*\) *(.*)$,\1,; T skip; p; :skip;') - if test -n "$sha1"; then - # Update the local refs/heads/channels/locals/* branches to be - # in-sync with the channel references. - git update-ref refs/heads/channels/locals/$channelName $sha1 - fi + updateRef current-system "$sha1" fi +echo "Fetching channels from ~/.nix-defexpr:" for revFile in : $(find -L ~/.nix-defexpr/ -maxdepth 4 -name svn-revision); do test "$revFile" = : && continue; # Deconstruct a path such as, into: + # # /home/luke/.nix-defexpr/channels_root/nixos/nixpkgs/svn-revision - # user=root repo=nixos channelName=root/nixos + # channelName = root/nixos # # /home/luke/.nix-defexpr/channels/nixpkgs/svn-revision - # user=luke repo=nixpkgs channelName=luke/nixpkgs + # channelName = nixpkgs + # user=${revFile#*.nix-defexpr/channels} repo=${user#*/} repo=${repo%%/*} user=${user%%/*} user=${user#_} test -z "$user" && user=$USER - channelName="$user/$repo" + channelName="$user${user:+/}$repo" sha1=$(cat $revFile | sed -n 's,^.*\.\([a-f0-9]*\)$,\1,; T skip; p; :skip;') - test -z "$sha1" -o -z "$channelName" && continue; - # Update the local refs/heads/channels/locals/* branches to be - # in-sync with the channel references. - git update-ref refs/heads/channels/locals/$channelName $sha1 + updateRef "$channelName" "$sha1" done + +# 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 < -$ nixos-version -14.04.273.ea1952b (Baboon) - -$ git checkout -b local ea1952b +$ /my/sources/nixpkgs/maintainers/scripts/update-channel-branches.sh +Fetching channels from https://nixos.org/channels: + * [new branch] cbe467e -> channels/remotes/nixos-unstable +Fetching channels from nixos-version: + * [new branch] 9ff4738 -> channels/current-system +Fetching channels from ~/.nix-defexpr: + * [new branch] 0d4acad -> channels/root/nixos +$ git checkout -b local channels/current-system Or, to base your local branch on the latest version available in the NixOS channel: -$ curl -sI https://nixos.org/channels/nixos-unstable/ | grep Location -Location: https://releases.nixos.org/nixos/unstable/nixos-14.10pre43986.acaf4a6/ - -$ git checkout -b local acaf4a6 +$ /my/sources/nixpkgs/maintainers/scripts/update-channel-branches.sh +$ git checkout -b local channels/remotes/nixos-unstable You can then use git rebase to sync your local