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

Add a feature for Haskell (GHC) #470

Open
wants to merge 4 commits into
base: main
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
1 change: 1 addition & 0 deletions .github/workflows/test-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
"git-lfs",
"github-cli",
"go",
"haskell",
"hugo",
"java",
"kubectl-helm-minikube",
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
git-lfs: ./**/git-lfs/**
github-cli: ./**/github-cli/**
go: ./**/go/**
haskell: ./**/haskell/**
hugo: ./**/hugo/**
java: ./**/java/**
kubectl-helm-minikube: ./**/kubectl-helm-minikube/**
Expand Down
7 changes: 7 additions & 0 deletions src/haskell/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@


## OS Support

This Feature should work on recent versions of Debian/Ubuntu-based distributions with the `apt` package manager installed.

`bash` is required to execute the `install.sh` script.
53 changes: 53 additions & 0 deletions src/haskell/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"id": "haskell",
"version": "1.0.0",
"name": "Glasgow Haskell Compiler",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/haskell",
"description": "Installs the Glasgow Haskell Compiler",
"options": {
"version": {
"type": "string",
"proposals": [

Choose a reason for hiding this comment

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

I'm not too familiar with how features work. My feeling is that this list can become outdated quickly. For HLS, it already is. Would it not be enough to choose between recommended and latest? Can the user enter manual strings regardless?

"latest",
"recommended",
"9.4.4",
"9.2.7"
],
"default": "recommended",
"description": "Select or enter a GHC Version to install"
},
"cabalVersion": {
"type": "string",
"proposals": [
"latest",
"recommended",
"3.6.2.0"
],
"default": "recommended",
"description": "Select or enter a Cabal Version to install"
},
"hlsVersion": {
"type": "string",
"proposals": [
"latest",
"recommended",
"1.9.0.0"
],
"default": "recommended",
"description": "Select or enter a Haskell Language Server Version to install"
},
"stackVersion": {
"type": "string",
"proposals": [
"latest",
"recommended",
"2.9.3"
],
"default": "recommended",
"description": "Select or enter a Stack Version to install"
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
42 changes: 42 additions & 0 deletions src/haskell/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -e
set -o xtrace

GHCUP_VERSION="0.1.19.2"
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved

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.


architecture="$(arch)"
GHCUP_BIN="${architecture}-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
Comment on lines +12 to +15
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be better to use a generic snippet to check other Features to do this.

Copy link
Author

Choose a reason for hiding this comment

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

I don't quite follow this comment, can you clarify?

Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I believe @eitsupi is referring to using check_packages helper function instead of this logic.
https://github.com/devcontainers/features/blob/main/src/docker-in-docker/install.sh#LL86-L91C2

I think it would be nice to use check_packages in this Feature as well for consistency.
(Would also need to copy apt_get_update along with check_packages)

Copy link
Author

Choose a reason for hiding this comment

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

Hrm, I'm not sure that those scripts do exactly what I want to do here. For example, they won't work correctly on a non-debian image where gcc is already installed.

Additionally, copying functions from one install.sh to another doesn't seem to be a great practice, is there a way to share common script snippets between features?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that those scripts do exactly what I want to do here. For example, they won't work correctly on a non-debian image where gcc is already installed.

Note that this repository is focused on debian-based containers at this time. Most Features will only work with debian-based images.

"image": "mcr.microsoft.com/devcontainers/base:ubuntu", // Any generic, debian-based image.

Additionally, copying functions from one install.sh to another doesn't seem to be a great practice, is there a way to share common script snippets between features?

See devcontainers/spec#209


GHCUP_DIR=${_REMOTE_USER_HOME}/.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.

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.

echo https://downloads.haskell.org/~ghcup/${GHCUP_VERSION}/${architecture}-linux-ghcup-${GHCUP_VERSION} --output ${GHCUP_BIN}
curl https://downloads.haskell.org/~ghcup/${GHCUP_VERSION}/${architecture}-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

export GHCUP_INSTALL_BASE_PREFIX=${_REMOTE_USER_HOME}

${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 $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 $CABALVERSION
${GHCUP_DIR}/ghcup set hls $HLSVERSION
${GHCUP_DIR}/ghcup set stack $STACKVERSION
brendandburns marked this conversation as resolved.
Show resolved Hide resolved

# Clean up
rm -rf /var/lib/apt/lists/*

echo "Done!"
12 changes: 12 additions & 0 deletions test/haskell/custom_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "version" ~/.ghcup/bin/ghc --version | grep 9.2.6

Choose a reason for hiding this comment

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

So is ~/.ghcup/bin in PATH?

# Report result
reportResults
14 changes: 14 additions & 0 deletions test/haskell/default_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
EXPECTED_VERSION=$(~/.ghcup/bin/ghcup list | grep "ghc " | grep recommended | awk '{print $3}')
samruddhikhandale marked this conversation as resolved.
Show resolved Hide resolved
echo ${EXPECTED_VERSION}
check "version" ~/.ghcup/bin/ghc --version | grep "${EXPECTED_VERSION}"

# Report result
reportResults
12 changes: 12 additions & 0 deletions test/haskell/mcr_version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "version" ~/.ghcup/bin/ghc --version | grep 9.2.6

# Report result
reportResults
24 changes: 24 additions & 0 deletions test/haskell/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"custom_version": {
"image": "ubuntu:focal",
"features": {
"haskell": {
"version": "9.2.6"
}
}
},
"default_version": {
"image": "ubuntu:jammy",
"features": {
"haskell": {}
}
},
"mcr_version": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"haskell": {
"version": "9.2.6"
}
}
}
}
12 changes: 12 additions & 0 deletions test/haskell/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "version" ~/.ghcup/bin/ghcup list

# Report result
reportResults