2013-10-09 12:04:29 +00:00
|
|
|
|
#! /bin/sh -e
|
|
|
|
|
|
|
|
|
|
branch="$1"
|
|
|
|
|
jobset="$2"
|
|
|
|
|
|
|
|
|
|
if [ -z "$branch" -o -z "$jobset" ]; then
|
|
|
|
|
echo "Usage: $0 BRANCH-NAME JOBSET-NAME" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
releaseUrl="http://hydra.nixos.org/job/nixos/$jobset/tested/latest-finished"
|
|
|
|
|
releasesDir="/data/releases/nixos/$branch"
|
|
|
|
|
channelsDir=/data/releases/channels
|
|
|
|
|
channelName=nixos-"$branch"
|
2015-03-05 16:40:48 +00:00
|
|
|
|
export GIT_DIR=/home/hydra-mirror/nixpkgs-channels
|
2013-10-09 12:04:29 +00:00
|
|
|
|
|
|
|
|
|
curl="curl --silent --show-error --fail"
|
|
|
|
|
wget="wget --no-verbose --content-disposition"
|
|
|
|
|
|
|
|
|
|
json=$($curl -L -H 'Accept: application/json' $releaseUrl)
|
|
|
|
|
|
|
|
|
|
releaseId=$(echo "$json" | json id)
|
|
|
|
|
if [ -z "$releaseId" ]; then echo "Failed to get release id"; exit 1; fi
|
|
|
|
|
|
|
|
|
|
release=$(echo "$json" | json nixname)
|
|
|
|
|
if [ -z "$release" ]; then echo "Failed to get release"; exit 1; fi
|
|
|
|
|
|
|
|
|
|
url=$($curl --head http://hydra.nixos.org/build/$releaseId/eval | sed 's/Location: \(.*\)\r/\1/; t; d')
|
|
|
|
|
if [ -z "$url" ]; then exit 1; fi
|
|
|
|
|
|
|
|
|
|
releaseDir=$releasesDir/$release
|
|
|
|
|
|
|
|
|
|
echo "release is ‘$release’ (build $releaseId), eval is ‘$url’, dir is ‘$releaseDir’" >&2
|
|
|
|
|
|
2015-09-02 09:16:51 +00:00
|
|
|
|
curRelease=$(basename $(readlink $channelsDir/$channelName 2> /dev/null) 2> /dev/null || true)
|
|
|
|
|
|
|
|
|
|
if [ -n "$curRelease" ]; then
|
|
|
|
|
d="$(nix-instantiate --eval -E "builtins.compareVersions (builtins.parseDrvName \"$curRelease\").version (builtins.parseDrvName \"$release\").version")"
|
|
|
|
|
if [ "$d" = 1 ]; then
|
|
|
|
|
echo "channel would go back in time from $curRelease to $release, bailing out" >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2015-03-05 16:40:48 +00:00
|
|
|
|
# Figure out the Git revision from which this release was
|
|
|
|
|
# built. FIXME: get this from Hydra directly.
|
|
|
|
|
shortRev=$(echo "$release" | sed 's/.*\.//')
|
|
|
|
|
rev=$(git rev-parse "$shortRev")
|
2015-08-13 12:16:34 +00:00
|
|
|
|
echo "revision is $rev" >&2
|
2015-03-05 16:40:48 +00:00
|
|
|
|
|
2013-10-09 12:04:29 +00:00
|
|
|
|
if [ -d $releaseDir ]; then
|
|
|
|
|
echo "release already exists" >&2
|
|
|
|
|
else
|
|
|
|
|
tmpDir="$(dirname $releaseDir)/.tmp-$release-$$"
|
|
|
|
|
mkdir -p $tmpDir
|
|
|
|
|
|
2014-12-09 12:42:06 +00:00
|
|
|
|
trap 'rm -rf -- "$tmpDir"' EXIT
|
|
|
|
|
|
2015-03-05 16:40:48 +00:00
|
|
|
|
echo -n "$url" > $tmpDir/src-url
|
|
|
|
|
echo -n "$rev" > $tmpDir/git-revision
|
2013-10-09 12:04:29 +00:00
|
|
|
|
|
|
|
|
|
# Copy the manual.
|
2013-11-01 15:56:22 +00:00
|
|
|
|
$curl -L $url/job/nixos.manual.x86_64-linux/output/out | bzip2 -d | nix-store --restore $tmpDir/foo
|
2013-10-09 12:04:29 +00:00
|
|
|
|
mv $tmpDir/foo/share/doc/nixos $tmpDir/manual
|
|
|
|
|
rm -rf $tmpDir/foo
|
2014-08-29 15:20:23 +00:00
|
|
|
|
if ! [ -e $tmpDir/manual/index.html ]; then
|
2015-02-03 10:19:59 +00:00
|
|
|
|
ln -s manual.html $tmpDir/manual/index.html
|
2014-08-29 15:20:23 +00:00
|
|
|
|
fi
|
2013-10-09 12:04:29 +00:00
|
|
|
|
|
|
|
|
|
$wget --directory=$tmpDir $url/job/nixos.iso_minimal.x86_64-linux/download
|
2014-12-09 12:42:06 +00:00
|
|
|
|
if ! [[ $branch =~ small ]]; then
|
2015-02-03 10:19:59 +00:00
|
|
|
|
$wget --directory=$tmpDir $url/job/nixos.iso_minimal.i686-linux/download
|
|
|
|
|
$wget --directory=$tmpDir $url/job/nixos.iso_graphical.x86_64-linux/download
|
|
|
|
|
$wget --directory=$tmpDir $url/job/nixos.iso_graphical.i686-linux/download
|
|
|
|
|
$wget --directory=$tmpDir $url/job/nixos.ova.x86_64-linux/download
|
|
|
|
|
$wget --directory=$tmpDir $url/job/nixos.ova.i686-linux/download
|
2014-12-09 12:42:06 +00:00
|
|
|
|
fi
|
2013-10-09 12:04:29 +00:00
|
|
|
|
|
2014-12-09 12:42:06 +00:00
|
|
|
|
shopt -s nullglob
|
2014-08-29 15:19:00 +00:00
|
|
|
|
for i in $tmpDir/*.iso $tmpDir/*.ova; do
|
|
|
|
|
nix-hash --type sha256 --flat $i > $i.sha256
|
|
|
|
|
done
|
2014-12-09 12:42:06 +00:00
|
|
|
|
shopt -u nullglob
|
2014-08-29 15:19:00 +00:00
|
|
|
|
|
2013-10-09 12:04:29 +00:00
|
|
|
|
perl -w ./mirror-channel.pl "$url/channel" "$tmpDir" \
|
2014-12-09 12:42:06 +00:00
|
|
|
|
nix-cache https://cache.nixos.org \
|
2014-09-10 12:16:36 +00:00
|
|
|
|
"$url/job/nixos.channel/download/1"
|
2013-10-09 12:04:29 +00:00
|
|
|
|
|
|
|
|
|
# Generate the programs.sqlite database and put it in nixexprs.tar.xz.
|
|
|
|
|
mkdir $tmpDir/unpack
|
|
|
|
|
tar xfJ $tmpDir/nixexprs.tar.xz -C $tmpDir/unpack
|
|
|
|
|
exprDir=$(echo $tmpDir/unpack/*)
|
2014-12-09 12:42:06 +00:00
|
|
|
|
./generate-programs-index.pl "$exprDir" "$exprDir/programs.sqlite" "$tmpDir/MANIFEST"
|
2013-10-09 12:04:29 +00:00
|
|
|
|
tar cfJ $tmpDir/nixexprs.tar.xz -C $tmpDir/unpack "$(basename "$exprDir")"
|
|
|
|
|
rm -rf $tmpDir/unpack
|
|
|
|
|
|
|
|
|
|
mv $tmpDir $releaseDir
|
2014-12-09 12:42:06 +00:00
|
|
|
|
trap '' EXIT
|
2013-10-09 12:04:29 +00:00
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Copy over to nixos.org.
|
|
|
|
|
cd "$releasesDir"
|
|
|
|
|
rsync -avR . hydra-mirror@nixos.org:"$releasesDir" --exclude .htaccess --exclude ".tmp.*" --delete >&2
|
|
|
|
|
|
|
|
|
|
# Update the channel.
|
|
|
|
|
htaccess=$channelsDir/.htaccess-$channelName
|
2014-08-05 10:52:18 +00:00
|
|
|
|
echo "Redirect /channels/$channelName /releases/nixos/$branch/$release" > $htaccess.tmp
|
|
|
|
|
echo "Redirect /releases/nixos/channels/$channelName /releases/nixos/$branch/$release" >> $htaccess.tmp # obsolete
|
2013-10-09 12:04:29 +00:00
|
|
|
|
mv $htaccess.tmp $htaccess
|
|
|
|
|
ln -sfn $releaseDir $channelsDir/$channelName # dummy symlink
|
|
|
|
|
|
|
|
|
|
flock -x $channelsDir/.htaccess.lock -c "cat $channelsDir/.htaccess-nix* > $channelsDir/.htaccess"
|
|
|
|
|
|
|
|
|
|
cd "$channelsDir"
|
|
|
|
|
rsync -avR . hydra-mirror@nixos.org:"$channelsDir" --delete >&2
|
|
|
|
|
|
2015-08-13 12:16:34 +00:00
|
|
|
|
# Update the nixpkgs-channels repo. FIXME: protect against concurrent access
|
|
|
|
|
git remote update nixpkgs >&2
|
|
|
|
|
git push nixpkgs-channels "$rev:refs/heads/$channelName" >&2
|
2015-03-05 16:40:48 +00:00
|
|
|
|
|
2013-10-09 12:04:29 +00:00
|
|
|
|
echo "$releaseDir"
|