This repository has been archived by the owner on Dec 24, 2020. It is now read-only.
forked from NixOS/cabal2nix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregenerate-nixpkgs.sh
executable file
·85 lines (73 loc) · 2.94 KB
/
regenerate-nixpkgs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#! /usr/bin/env nix-shell
#! nix-shell -p cabal-install -i bash
# This script finds the last generation of hackage-packages.nix in nixpkgs and
# rebuilds it based on the configuration-hackage2nix.yaml in nixpkgs.
# Assumptions:
# 1. Being run out of the cabal2nix repo.
# 2. A checkout or symlink to checkout of nixpkgs under ./nixpkgs
# What you should do:
# 1. Change pkgs/development/haskell-modules/configuration-hackage2nix.yaml in ./nixpkgs to your liking.
# 2. Run ./regenerate-nixpkgs.sh
# 3. Enjoy your adapted pkgs/development/haskell-modules/hackage-packages.nix
# Possible improvements for this script:
# 1. Share code with update-nixpkgs.
# 2. Integrate preferred-versions into hackage2nix.
# 3. Use cabal tarballs in hackage2nix.
set -eu
exit_trap()
{
local lc="$BASH_COMMAND" rc=$?
test $rc -eq 0 || echo "*** error $rc: $lc"
}
trap exit_trap EXIT
cd "$(dirname "$0")"
if [[ ! -a nixpkgs ]]; then
echo "You need a checkout of nixpkgs under $PWD/nixpkgs. Maybe create a symlink to your checkout?"
exit 1
fi
cd nixpkgs
msg=$(git log pkgs/development/haskell-modules/hackage-packages.nix | grep -A1 -B6 "This update was generated by hackage2nix .* from Hackage revision" | head -n8)
nixpkgsCommit=$(echo $msg | sed -E 's/.*commit ([a-z0-9]{7}).*/\1/')
nixpkgsCommitDate=$(echo $msg | sed 's/.*Date: \(.*\) hackage-packages.nix.*/\1/')
usedCabal2nix=$(echo $msg | sed 's/.*hackage2nix \(.*\) from Hackage revision.*/\1/')
usedCabalHashes=$(echo $msg | sed -E 's/.*all-cabal-hashes\/commit\/([a-z0-9]{7}).*/\1/')
echo "The last commit found in ./nixpkgs which updated hackage-packages.nix was $nixpkgsCommit at $nixpkgsCommitDate."
nixpkgsPath=$PWD
cd ..
dir=$PWD/pinned-hackage2nix
echo -n "Checking out version $usedCabal2nix of cabal2nix to $dir ... "
git fetch --all -q
if [[ ! -a $dir ]]; then
git worktree add $dir $usedCabal2nix -q
else
git -C $dir checkout $usedCabal2nix -q
fi
echo "done."
echo -n "Checking out all-cabal-hashes commit $usedCabalHashes to ./hackage ... "
if [[ ! -a hackage ]]; then
echo "No checkout of all-cabal-hashes found in $PWD/hackage. Cloning ... "
git clone git://github.com/commercialhaskell/all-cabal-hashes.git hackage
fi
cd hackage
git fetch --all -q
git checkout $usedCabalHashes -q
rm -f preferred-versions
for n in */preferred-versions; do
cat >>preferred-versions "$n"
echo >>preferred-versions
done
echo "done."
hackagePath=$PWD
cd ..
buildDir=$PWD/dist-newstyle
echo -n "Preparing build environment for compiling hackage2nix from <nixpkgs> ... "
cd $dir
ghc=$(cat $(nix-build --no-out-link "<nixpkgs>" -A haskellPackages.cabal2nix.env))/bin/ghc
echo "done."
echo -n "Building hackage2nix ... "
cabal -v0 --with-compiler=$ghc v2-build hackage2nix
echo "done."
echo -n "Running hackage2nix on ./nixpkgs ... "
cabal -v0 --with-compiler=$ghc v2-run hackage2nix -- --nixpkgs="$nixpkgsPath" --hackage="$hackagePath" --preferred-versions="$hackagePath/preferred-versions"
echo "done."
echo "hackage-packages.nix regenerated. "