Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 5 additions & 6 deletions src/haskell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"id": "haskell",
"version": "0.0.1",
"version": "1.0.0",
"name": "Glasgow Haskell Compiler",
"documentationURL": "https://github.com/brendandburns/ghc-feature",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/haskell",
"description": "Installs the Glasgow Haskell Compiler",
"options": {
"version": {
Expand All @@ -16,7 +16,7 @@
"default": "recommended",
"description": "Select or enter a GHC Version to install"
},
"cabal_version": {
"cabalVersion": {
"type": "string",
"proposals": [
"latest",
Expand All @@ -26,7 +26,7 @@
"default": "recommended",
"description": "Select or enter a Cabal Version to install"
},
"hls_version": {
"hlsVersion": {
"type": "string",
"proposals": [
"latest",
Expand All @@ -36,7 +36,7 @@
"default": "recommended",
"description": "Select or enter a Haskell Language Server Version to install"
},
"stack_version": {
"stackVersion": {
"type": "string",
"proposals": [
"latest",
Expand All @@ -47,7 +47,6 @@
"description": "Select or enter a Stack Version to install"
}
},
"mounts": [],
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
Expand Down
22 changes: 14 additions & 8 deletions src/haskell/install.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
#!/usr/bin/env bash
set -e

GHCUP_VERSION="0.1.19.2"

Choose a reason for hiding this comment

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

Yeah, please use the bootstrap script to always get the latest ghcup. Pinning ghcup version is not recommended.

GHCUP_BIN="x86_64-linux-ghcup-${GHCUP_VERSION}"
BOOTSTRAP_HASKELL_GHC_VERSION="${VERSION:-"recommended "}"

# Maybe install curl, gcc, make
for x in curl gcc make; do
which $x > /dev/null || (apt update && apt install $x -y -qq)
done

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_MINIMAL=1 sh

GHCUP_DIR=~/.ghcup/bin
mkdir -p $GHCUP_DIR
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should add a new user group haskell and chown & set sticky bit for this folder .ghcup

Ref: https://github.com/devcontainers/features/blob/main/src/ruby/install.sh#LL206-L209C7 &
https://github.com/devcontainers/features/blob/main/src/ruby/install.sh#L283-L285

Copy link
Member

Choose a reason for hiding this comment

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

where

USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"

We have https://github.com/devcontainers/features/blob/main/src/ruby/install.sh#L39-L59 to automatically figure out the USERNAME

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure it's necessary, this will land in the home directory, but it doesn't really need a different username imho.

curl https://downloads.haskell.org/~ghcup/${GHCUP_VERSION}/x86_64-linux-ghcup-${GHCUP_VERSION} --output ${GHCUP_BIN}
echo "25b7fc417c1a811dd7ff439b67ea647a59cf5b8d71b274f97e917d50b2150d5b ${GHCUP_BIN}" | sha256sum --check --status

mv ${GHCUP_BIN} $GHCUP_DIR/ghcup
chmod a+x $GHCUP_DIR/ghcup

${GHCUP_DIR}/ghcup install ghc $BOOTSTRAP_HASKELL_GHC_VERSION

Choose a reason for hiding this comment

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

I suggest to not do all this manually, but use the bootstrap script, which allows fine grained control via env vars.

E.g.

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 BOOTSTRAP_HASKELL_CABAL_VERSION=$CABALVERSION BOOTSTRAP_HASKELL_INSTALL_HLS=1 BOOTSTRAP_HASKELL_ADJUST_BASHRC=1 sh

This will also try do adjust shell config to add ~/.ghcup/bin to PATH and most importantly install stack installation hooks that make sure HLS actually works with stack (there are ABI issues). See https://www.haskell.org/ghcup/guide/#strategy-2-stack-hooks-new-recommended

Right now the bootstrap script assumes you want latest of stack and HLS, but I can add environment variables to control that as well.

Choose a reason for hiding this comment

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

Oh and the bootstrap script also creates a ~/.ghcup/env file that can be sourced to get the correct PATH.

${GHCUP_DIR}/ghcup install cabal $CABAL_VERSION
${GHCUP_DIR}/ghcup install hls $HLS_VERSION
${GHCUP_DIR}/ghcup install stack $STACK_VERSION
${GHCUP_DIR}/ghcup install cabal $CABALVERSION
${GHCUP_DIR}/ghcup install hls $HLSVERSION
${GHCUP_DIR}/ghcup install stack $STACKVERSION

${GHCUP_DIR}/ghcup set ghc $BOOTSTRAP_HASKELL_GHC_VERSION
${GHCUP_DIR}/ghcup set cabal $CABAL_VERSION
${GHCUP_DIR}/ghcup set hls $HLS_VERSION
${GHCUP_DIR}/ghcup set stack $STACK_VERSION
${GHCUP_DIR}/ghcup set cabal $CABALVERSION
${GHCUP_DIR}/ghcup set hls $HLSVERSION
${GHCUP_DIR}/ghcup set stack $STACKVERSION
3 changes: 1 addition & 2 deletions test/haskell/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"default_version": {
"image": "ubuntu:jammy",
"features": {
"haskell": {
}
"haskell": {}
}
}
}