diff --git a/mirror-nixos-branch.pl b/mirror-nixos-branch.pl index 23ab3a8..682bbd7 100755 --- a/mirror-nixos-branch.pl +++ b/mirror-nixos-branch.pl @@ -12,8 +12,9 @@ use List::MoreUtils qw(uniq); my $branch = $ARGV[0]; my $jobset = $ARGV[1]; +my $isMainRelease = ($ARGV[2] // 0) eq 1; -die "Usage: $0 BRANCH-NAME JOBSET_NAME\n" unless defined $branch && defined $jobset; +die "Usage: $0 BRANCH-NAME JOBSET_NAME [IS-MAIN-RELEASE]\n" unless defined $branch && defined $jobset; my $releaseUrl = "https://hydra.nixos.org/job/nixos/$jobset/tested/latest-finished"; my $releasesDir = "/data/releases/nixos/$branch"; @@ -150,4 +151,31 @@ system("cat $channelsDir/.htaccess-nix* > $channelsDir/.htaccess") == 0 or die; system("git remote update origin >&2") == 0 or die; system("git push channels $rev:refs/heads/$channelName >&2") == 0 or die; -print "$releaseDir\n"; +# If this is the "main" stable release, generate a .htaccess with some +# symbolic redirects to the latest ISOs. + +if ($isMainRelease) { + + my $baseURL = "/releases/nixos/$branch/$releaseName"; + my $res = "Redirect /releases/nixos/latest $baseURL\n"; + + sub add { + my ($name, $wildcard) = @_; + my @files = glob "$releaseDir/$wildcard"; + die if scalar @files != 1; + my $fn = basename($files[0]); + $res .= "Redirect /releases/nixos/$name $baseURL/$fn\n"; + $res .= "Redirect /releases/nixos/$name-sha256 $baseURL/$fn.sha256\n"; + } + + add("latest-iso-minimal-i686-linux", "nixos-minimal-*-i686-linux.iso"); + add("latest-iso-minimal-x86_64-linux", "nixos-minimal-*-x86_64-linux.iso"); + add("latest-iso-graphical-i686-linux", "nixos-graphical-*-i686-linux.iso"); + add("latest-iso-graphical-x86_64-linux", "nixos-graphical-*-x86_64-linux.iso"); + add("latest-ova-i686-linux", "nixos-*-i686-linux.ova"); + add("latest-ova-x86_64-linux", "nixos-*-x86_64-linux.ova"); + + my $htaccess2 = "/data/releases/nixos/.htaccess"; + write_file("$htaccess2.tmp", $res); + rename("$htaccess2.tmp", $htaccess2) or die; +} diff --git a/mirror-nixos-branch.sh b/mirror-nixos-branch.sh deleted file mode 100755 index acc08a1..0000000 --- a/mirror-nixos-branch.sh +++ /dev/null @@ -1,125 +0,0 @@ -#! /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" -export GIT_DIR=/home/hydra-mirror/nixpkgs-channels - -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 - -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 - -# Figure out the Git revision from which this release was -# built. FIXME: get this from Hydra directly. -git remote update nixpkgs >&2 -shortRev=$(echo "$release" | sed 's/.*\.//') -rev=$(git rev-parse "$shortRev") -echo "revision is $rev" >&2 - -if [ -d $releaseDir ]; then - echo "release already exists" >&2 -else - tmpDir="$(dirname $releaseDir)/.tmp-$release-$$" - mkdir -p $tmpDir - - trap 'rm -rf -- "$tmpDir"' EXIT - - echo -n "$url" > $tmpDir/src-url - echo -n "$rev" > $tmpDir/git-revision - - # Copy the manual. - $curl -L $url/job/nixos.manual.x86_64-linux/output/out | bzip2 -d | nix-store --restore $tmpDir/foo - mv $tmpDir/foo/share/doc/nixos $tmpDir/manual - rm -rf $tmpDir/foo - if ! [ -e $tmpDir/manual/index.html ]; then - ln -s manual.html $tmpDir/manual/index.html - fi - - $wget --directory=$tmpDir $url/job/nixos.iso_minimal.x86_64-linux/download - if ! [[ $branch =~ small ]]; then - $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 - fi - - shopt -s nullglob - for i in $tmpDir/*.iso $tmpDir/*.ova; do - nix-hash --type sha256 --flat $i > $i.sha256 - done - shopt -u nullglob - - perl -w ./mirror-channel.pl "$url/channel" "$tmpDir" \ - nix-cache https://cache.nixos.org \ - "$url/job/nixos.channel/download/1" - - # 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/*) - ./generate-programs-index.pl "$exprDir" "$exprDir/programs.sqlite" "$tmpDir/MANIFEST" - tar cfJ $tmpDir/nixexprs.tar.xz -C $tmpDir/unpack "$(basename "$exprDir")" - rm -rf $tmpDir/unpack - - mv $tmpDir $releaseDir - trap '' EXIT -fi - -# Prevent concurrent writes to the channels and the Git clone. -exec 10>$channelsDir/.htaccess.lock -flock 10 - -# 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 -echo "Redirect /channels/$channelName /releases/nixos/$branch/$release" > $htaccess.tmp -echo "Redirect /releases/nixos/channels/$channelName /releases/nixos/$branch/$release" >> $htaccess.tmp # obsolete -mv $htaccess.tmp $htaccess -ln -sfn $releaseDir $channelsDir/$channelName # dummy symlink - -cat $channelsDir/.htaccess-nix* > $channelsDir/.htaccess - -cd "$channelsDir" -rsync -avR . hydra-mirror@nixos.org:"$channelsDir" --delete >&2 - -# Update the nixpkgs-channels repo. -git push nixpkgs-channels "$rev:refs/heads/$channelName" >&2 - -echo "$releaseDir" diff --git a/mirror-nixos-stable.sh b/mirror-nixos-stable.sh deleted file mode 100755 index d13eda5..0000000 --- a/mirror-nixos-stable.sh +++ /dev/null @@ -1,33 +0,0 @@ -#! /bin/sh -e - -version="$1" -if [ -z "$version" ]; then echo "syntax: $0 VERSION"; exit 1; fi - -releaseDir=$(./mirror-nixos-branch.sh "$version" "release-$version") -echo $releaseDir - -release=$(basename $releaseDir) - -# Generate a .htaccess with some symbolic redirects to the latest ISOs. -htaccess=/data/releases/nixos/.htaccess - -link() { - local name="$1" - local wildcard="$2" - fn=$(cd $releaseDir && echo $wildcard) - echo "Redirect /releases/nixos/$name $baseURL/$fn" >> $htaccess.tmp - echo "Redirect /releases/nixos/${name}-sha256 $baseURL/${fn}.sha256" >> $htaccess.tmp -} - -baseURL="/releases/nixos/$version/$release" -echo "Redirect /releases/nixos/latest $baseURL" > $htaccess.tmp -link latest-iso-minimal-i686-linux "nixos-minimal-*-i686-linux.iso" -link latest-iso-minimal-x86_64-linux "nixos-minimal-*-x86_64-linux.iso" -link latest-iso-graphical-i686-linux "nixos-graphical-*-i686-linux.iso" -link latest-iso-graphical-x86_64-linux "nixos-graphical-*-x86_64-linux.iso" -link latest-ova-i686-linux "nixos-*-i686-linux.ova" -link latest-ova-x86_64-linux "nixos-*-x86_64-linux.ova" - -mv $htaccess.tmp $htaccess - -rsync -av $htaccess hydra-mirror@nixos.org:$htaccess >&2