Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing of GHC version; pull snapshot from cabal config #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you agree with the env var change:

Suggested change
init-haskell 9.2.1
INIT_HASKELL_GHC=9.2.1 init-haskell

```

### Build and run

```
Expand Down
23 changes: 18 additions & 5 deletions init-haskell
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
#! /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}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on changing this to an env var INIT_HASKELL_GHC so people can set it in their profile (and we don't have to do arg parsing for further arguments)?

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##*/}
cat <<EOF >$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
Expand Down