Add a script for updating the Stackage rev

This commit is contained in:
Rodney Lorrimar 2019-02-11 13:37:10 +10:00
parent 12076ea8f0
commit a6d28bacb2
No known key found for this signature in database
GPG Key ID: 2CCD588917A9A868
4 changed files with 89 additions and 30 deletions

View File

@ -90,6 +90,7 @@ let
# Scripts for keeping Hackage and Stackage up to date.
maintainer-scripts = {
update-hackage = self.callPackage ./scripts/update-hackage.nix {};
update-stackage = self.callPackage ./scripts/update-stackage.nix {};
};
});

View File

@ -0,0 +1,26 @@
{ stdenv, writeScript, glibc, coreutils, git, nix-tools, cabal-install, nix-prefetch-git }:
{ name, script }:
with stdenv.lib;
writeScript "update-${name}-nix.sh" ''
#!${stdenv.shell}
set -euo pipefail
export PATH="${makeBinPath [ coreutils glibc git nix-tools cabal-install nix-prefetch-git ]}"
${script}
git add .
git commit --allow-empty -m "Automatic update for $(date)"
rev=$(git rev-parse HEAD)
git push
cd ..
nix-prefetch-git https://github.com/input-output-hk/${name}.nix.git --rev "$rev" | tee ${name}-src.json
''

View File

@ -1,36 +1,24 @@
{ stdenv, writeScriptBin, coreutils, git, nix-tools, cabal-install, nix-prefetch-git }:
{ stdenv, writeScript, coreutils, glibc, git, nix-tools, cabal-install, nix-prefetch-git }@args:
with stdenv.lib;
import ./update-external.nix args {
name = "hackage";
script = ''
# Make sure the hackage index is recent.
cabal new-update
writeScriptBin "update-hackage-nix" ''
#!${stdenv.shell}
# Clone or update the Hackage Nix expressions repo.
if [ -d hackage.nix ]; then
cd hackage.nix
git pull --ff-only
cd ..
else
git clone git@github.com:input-output-hk/hackage.nix.git
fi
set -euo pipefail
echo "Running hackage-to-nix..."
export PATH="${makeBinPath [ coreutils git nix-tools cabal-install nix-prefetch-git ]}"
hackage-to-nix hackage.nix
# Make sure the hackage index is recent.
cabal new-update
if [ -d hackage.nix ]; then
cd hackage.nix
git pull --ff-only
cd ..
else
git clone git@github.com:input-output-hk/hackage.nix.git
fi
hackage-to-nix hackage.nix
cd hackage.nix
git add .
git commit --allow-empty -m "Automatic update for $(date)"
rev=$(git rev-parse HEAD)
git push
cd ..
nix-prefetch-git https://github.com/input-output-hk/hackage.nix.git --rev "$rev" | tee hackage-src.json
''
'';
}

View File

@ -0,0 +1,44 @@
{ stdenv, writeScript, coreutils, glibc, git, nix-tools, cabal-install, nix-prefetch-git }@args:
import ./update-external.nix args {
name = "stackage";
script = ''
# Clone or update the main Stackage Nix expressions repo.
# The upstream LTS and Nightly package sets are in submodules, which
# should also be updated.
if [ -d stackage.nix ]; then
cd stackage.nix
git pull --ff-only
git submodule update --init
git submodule foreach git pull origin master
else
git clone git@github.com:input-output-hk/stackage.nix.git
cd stackage.nix
git submodule update --init
fi
echo "Running lts-to-nix for all snapshots..."
# update them all in parallel...
N=$(getconf _NPROCESSORS_ONLN)
for lts in {lts-haskell,stackage-nightly}/*.yaml
do
lts-to-nix $lts > $(basename ''${lts%.yaml}.nix) &
while [[ $(jobs -r -p | wc -l) -gt $N ]]; do
# can't use `wait -n` on older bash versions.
# e.g. what ships with macOS High Sierra
sleep 1;
done
done
wait
# update nightlies
echo "{" > nightlies.nix;
for a in nightly-*.nix; do echo " \"''${a%%.nix}\" = import ./$a;" >> nightlies.nix; done;
echo "}" >> nightlies.nix
# update lts
echo "{" > ltss.nix;
for a in lts-*.nix; do echo " \"''${a%%.nix}\" = import ./$a;" >> ltss.nix; done;
echo "}" >> ltss.nix
'';
}