Skip to content

Commit a6d28ba

Browse files
committed
Add a script for updating the Stackage rev
1 parent 12076ea commit a6d28ba

File tree

4 files changed

+89
-30
lines changed

4 files changed

+89
-30
lines changed

default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ let
9090
# Scripts for keeping Hackage and Stackage up to date.
9191
maintainer-scripts = {
9292
update-hackage = self.callPackage ./scripts/update-hackage.nix {};
93+
update-stackage = self.callPackage ./scripts/update-stackage.nix {};
9394
};
9495
});
9596

scripts/update-external.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{ stdenv, writeScript, glibc, coreutils, git, nix-tools, cabal-install, nix-prefetch-git }:
2+
3+
{ name, script }:
4+
5+
with stdenv.lib;
6+
7+
writeScript "update-${name}-nix.sh" ''
8+
#!${stdenv.shell}
9+
10+
set -euo pipefail
11+
12+
export PATH="${makeBinPath [ coreutils glibc git nix-tools cabal-install nix-prefetch-git ]}"
13+
14+
${script}
15+
16+
git add .
17+
git commit --allow-empty -m "Automatic update for $(date)"
18+
19+
rev=$(git rev-parse HEAD)
20+
21+
git push
22+
23+
cd ..
24+
25+
nix-prefetch-git https://github.com/input-output-hk/${name}.nix.git --rev "$rev" | tee ${name}-src.json
26+
''

scripts/update-hackage.nix

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,24 @@
1-
{ stdenv, writeScriptBin, coreutils, git, nix-tools, cabal-install, nix-prefetch-git }:
1+
{ stdenv, writeScript, coreutils, glibc, git, nix-tools, cabal-install, nix-prefetch-git }@args:
22

3-
with stdenv.lib;
3+
import ./update-external.nix args {
4+
name = "hackage";
5+
script = ''
6+
# Make sure the hackage index is recent.
7+
cabal new-update
48
5-
writeScriptBin "update-hackage-nix" ''
6-
#!${stdenv.shell}
9+
# Clone or update the Hackage Nix expressions repo.
10+
if [ -d hackage.nix ]; then
11+
cd hackage.nix
12+
git pull --ff-only
13+
cd ..
14+
else
15+
git clone [email protected]:input-output-hk/hackage.nix.git
16+
fi
717
8-
set -euo pipefail
18+
echo "Running hackage-to-nix..."
919
10-
export PATH="${makeBinPath [ coreutils git nix-tools cabal-install nix-prefetch-git ]}"
20+
hackage-to-nix hackage.nix
1121
12-
# Make sure the hackage index is recent.
13-
cabal new-update
14-
15-
if [ -d hackage.nix ]; then
1622
cd hackage.nix
17-
git pull --ff-only
18-
cd ..
19-
else
20-
git clone [email protected]:input-output-hk/hackage.nix.git
21-
fi
22-
23-
hackage-to-nix hackage.nix
24-
25-
cd hackage.nix
26-
git add .
27-
git commit --allow-empty -m "Automatic update for $(date)"
28-
29-
rev=$(git rev-parse HEAD)
30-
31-
git push
32-
33-
cd ..
34-
35-
nix-prefetch-git https://github.com/input-output-hk/hackage.nix.git --rev "$rev" | tee hackage-src.json
36-
''
23+
'';
24+
}

scripts/update-stackage.nix

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{ stdenv, writeScript, coreutils, glibc, git, nix-tools, cabal-install, nix-prefetch-git }@args:
2+
3+
import ./update-external.nix args {
4+
name = "stackage";
5+
script = ''
6+
# Clone or update the main Stackage Nix expressions repo.
7+
# The upstream LTS and Nightly package sets are in submodules, which
8+
# should also be updated.
9+
if [ -d stackage.nix ]; then
10+
cd stackage.nix
11+
git pull --ff-only
12+
git submodule update --init
13+
git submodule foreach git pull origin master
14+
else
15+
git clone [email protected]:input-output-hk/stackage.nix.git
16+
cd stackage.nix
17+
git submodule update --init
18+
fi
19+
20+
echo "Running lts-to-nix for all snapshots..."
21+
22+
# update them all in parallel...
23+
N=$(getconf _NPROCESSORS_ONLN)
24+
for lts in {lts-haskell,stackage-nightly}/*.yaml
25+
do
26+
lts-to-nix $lts > $(basename ''${lts%.yaml}.nix) &
27+
while [[ $(jobs -r -p | wc -l) -gt $N ]]; do
28+
# can't use `wait -n` on older bash versions.
29+
# e.g. what ships with macOS High Sierra
30+
sleep 1;
31+
done
32+
done
33+
wait
34+
35+
# update nightlies
36+
echo "{" > nightlies.nix;
37+
for a in nightly-*.nix; do echo " \"''${a%%.nix}\" = import ./$a;" >> nightlies.nix; done;
38+
echo "}" >> nightlies.nix
39+
# update lts
40+
echo "{" > ltss.nix;
41+
for a in lts-*.nix; do echo " \"''${a%%.nix}\" = import ./$a;" >> ltss.nix; done;
42+
echo "}" >> ltss.nix
43+
'';
44+
}

0 commit comments

Comments
 (0)