diff --git a/scripts/build-repo.sh b/scripts/build-repo.sh
index 61138a460d0fe7c1341514bc72fd619d924f8504..e7e3d60e6931f8ccafff7bb7db9c0caf32ebc672 100755
--- a/scripts/build-repo.sh
+++ b/scripts/build-repo.sh
@@ -104,7 +104,7 @@ EOF
     packages from <a href="https://hackage.haskell.org/">Hackage</a> for use
     with <a href="https://gitlab.haskell.org/ghc/ghc">GHC</a> prereleases.
 
-	<p>The source of this package repository is at <a href="https://gitlab.haskell.org/ghc/head.hackage">gitlab.haskell.org/ghc/head.hackage</a>.
+    <p>The source of this package repository is at <a href="https://gitlab.haskell.org/ghc/head.hackage">gitlab.haskell.org/ghc/head.hackage</a>.
 
     <p>To use package repository with <code>cabal-install</code> add the following
     to your project's <code>cabal.project.local</code> and run
@@ -112,6 +112,11 @@ EOF
     <pre><code>
 $(cat repo/cabal.project.local)
     </code></pre>
+
+    <p>Finally, you may want to add the <a
+    href="cabal.constraints">constraints</a> to your project to ensure that
+    cabal chooses the patched releases.
+
     <p>If you find a package that doesn't build with a recent GHC
     pre-release see the <a
     href="https://gitlab.haskell.org/ghc/head.hackage#adding-a-patch">contributor
@@ -133,6 +138,26 @@ $(cat repo/cabal.project.local)
 EOF
 }
 
+split_pkg_version() {
+    package=$(echo $1 | sed 's/\(.\+\)-\([0-9]\+\(\.[0-9]\+\)*\)/\1/')
+    version=$(echo $1 | sed 's/\(.\+\)-\([0-9]\+\(\.[0-9]\+\)*\)/\2/')
+}
+
+build_constraints() {
+  cat <<EOF
+allow-newer: *:base
+allow-newer: *:template-haskell
+allow-newer: *:time
+allow-newer: *:Cabal
+allow-newer: *:ghc
+EOF
+  echo "constraints:"
+  for f in $(ls patches); do
+    split_pkg_version $(basename $(basename $f .patch) .cabal)
+    echo "  $package ==$version"
+  done
+}
+
 # Build the hackage repository
 build_repo() {
   extract_keys_tarball
@@ -155,6 +180,7 @@ build_repo() {
     --template=template \
     ./repo
 
+  build_constraints > repo/cabal.constraints
   build_index
 }
 
@@ -162,7 +188,9 @@ case $1 in
   gen-keys) gen_keys_tarball ;;
   extract-keys) extract_keys_tarball ;;
   build-repo) build_repo ;;
-  build-index) build_index ;;
+  build-index)
+    build_constraints > repo/cabal.constraints
+    build_index ;;
   *)
     echo "Unknown command $1"
     exit 1