diff --git a/README.md b/README.md index 60a4373..62d2643 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,12 @@ mkdir myprojectname && cd myprojectname init-haskell ``` +The above will default to using GHC 8.10.7. If you'd like to use a different version, simply pass the full version as an argument: + +``` +init-haskell 9.2.1 +``` + ### Build and run ``` diff --git a/init-haskell b/init-haskell index eccb7b1..e012e0f 100755 --- a/init-haskell +++ b/init-haskell @@ -1,10 +1,23 @@ #! /usr/bin/env nix-shell -#! nix-shell --pure --keep NIX_SSL_CERT_FILE --keep GITHUB_TOKEN -i bash -p git mustache-go niv direnv nix +#! nix-shell --pure --keep NIX_SSL_CERT_FILE --keep GITHUB_TOKEN -i bash -p git mustache-go jq niv direnv nix set -Eeuxo pipefail # init-haskell location base=$(dirname "$(readlink -f "$0")") +ghc=${1:-8.10.7} +ghcparts=(${ghc//./ }) +ghcmajor=${ghcparts[0]} +ghcminor=${ghcparts[1]} +ghcpatch=${ghcparts[2]} + +snapshot="2022-01-01T00:00:00Z" +cabaltimestamp=~/.cabal/packages/hackage.haskell.org/timestamp.json + +if [ -f $cabaltimestamp ]; then + snapshot=$(jq -r '.signed | select(._type == "Timestamp") | .expires' $cabaltimestamp) +fi + # Variables data=$(mktemp) projectname=${PWD##*/} @@ -12,11 +25,11 @@ cat <$data { "author": "$(git config user.name)" , "email": "$(git config user.email)" , "ghc": - { major: 8 - , minor: 10 - , patch: 7 + { major: ${ghcmajor} + , minor: ${ghcminor} + , patch: ${ghcpatch} } -, "snapshot": "2022-03-01T00:00:00Z" +, "snapshot": "${snapshot}" , "projectname": "${projectname}" } EOF