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

Actually pass through the env vars to the Haskell installer #139

Merged
merged 3 commits into from
Nov 30, 2022
Merged

Conversation

jcbhmr
Copy link
Contributor

@jcbhmr jcbhmr commented Nov 29, 2022

Fixes the env vars not being passed to the sudo command as detailed in #94 (comment)

@DaneWeber Is this commit/fix what you had in mind?

This PR will...

  • Add the following vars to the sudo context:
export BOOTSTRAP_HASKELL_NONINTERACTIVE='$BOOTSTRAP_HASKELL_NONINTERACTIVE'
export GHCUP_USE_XDG_DIRS='$GHCUP_USE_XDG_DIRS'
export BOOTSTRAP_HASKELL_GHC_VERSION='$BOOTSTRAP_HASKELL_GHC_VERSION'
export BOOTSTRAP_HASKELL_CABAL_VERSION='$BOOTSTRAP_HASKELL_CABAL_VERSION'
export BOOTSTRAP_HASKELL_DOWNLOADER='$BOOTSTRAP_HASKELL_DOWNLOADER'
export BOOTSTRAP_HASKELL_INSTALL_NO_STACK='$BOOTSTRAP_HASKELL_INSTALL_NO_STACK'
export BOOTSTRAP_HASKELL_ADJUST_BASHRC='$BOOTSTRAP_HASKELL_ADJUST_BASHRC'
export BOOTSTRAP_HASKELL_INSTALL_NO_STACK_HOOK='$BOOTSTRAP_HASKELL_INSTALL_NO_STACK_HOOK'

Jacob Hummer added 2 commits November 29, 2022 14:20
Responds to my own dumb dumb mishaps with env vars and passing through sudo (since it's a different shell)

#94 (comment)

@DaneWeber Is this commit/fix what you had in mind?

Signed-off-by: Jacob Hummer <jcbhmr@outlook.com>
Actually need more vars
@jcbhmr jcbhmr marked this pull request as draft November 29, 2022 20:34
@jcbhmr
Copy link
Contributor Author

jcbhmr commented Nov 29, 2022

This should be thoroughly checked before being merged to avoid things like #136 and others.

@DaneWeber
Copy link
Contributor

I just saw this notification. I'll test it out locally in a minute.

@DaneWeber
Copy link
Contributor

DaneWeber commented Nov 29, 2022

Something is weird about the install. GHCI, Cabal, and Stack are getting installed and are accessible, but they aren't being managed by GHCup.

Results from this PR's Feature:

vscode ➜ /workspaces/haskell_example $ ghcup list -c installed
   Tool  Version  Tags               Notes
✔✔ ghcup 0.1.18.0 latest,recommended      
vscode ➜ /workspaces/haskell_example $ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.4
vscode ➜ /workspaces/haskell_example $ cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library 
vscode ➜ /workspaces/haskell_example $ stack --version
Version 2.9.1, Git revision 409d56031b4240221d656db09b2ba476fe6bb5b1 x86_64 hpack-0.35.0

If I run the following as a non-root user in the same base image but without the Feature installed, I get the following behavior:

Setup commands in place of Feature:

sudo apt-get update -y
sudo apt-get -y install --no-install-recommends curl build-essential libffi-dev libffi8ubuntu1 libgmp-dev libgmp10 libncurses-dev libncurses5 libtinfo5
export BOOTSTRAP_HASKELL_NONINTERACTIVE=1
export GHCUP_USE_XDG_DIRS=1
export BOOTSTRAP_HASKELL_GHC_VERSION=9.2.4
export BOOTSTRAP_HASKELL_CABAL_VERSION=3.8.1.0
export BOOTSTRAP_HASKELL_DOWNLOADER=curl
export BOOTSTRAP_HASKELL_INSTALL_NO_STACK=
export BOOTSTRAP_HASKELL_ADJUST_BASHRC=true
export BOOTSTRAP_HASKELL_INSTALL_NO_STACK_HOOK=
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

Results of the above non-root install:

vscode ➜ ~/.cache/ghcup/logs $ ghcup list -c installed
[ Warn  ] New ghc version available. To upgrade, run 'ghcup install ghc 9.4.3'
   Tool  Version  Tags               Notes
✔✔ ghc   9.2.4    base-4.16.3.0           
✔✔ cabal 3.8.1.0  latest                  
✔✔ stack 2.9.1    latest,recommended      
✔✔ ghcup 0.1.18.0 latest,recommended      
vscode ➜ ~/.cache/ghcup/logs $ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.4
vscode ➜ ~/.cache/ghcup/logs $ cabal --version
cabal-install version 3.8.1.0
compiled using version 3.8.1.0 of the Cabal library 
vscode ➜ ~/.cache/ghcup/logs $ stack --version
Version 2.9.1, Git revision 409d56031b4240221d656db09b2ba476fe6bb5b1 x86_64 hpack-0.35.0

I'm going to dig a little more, but it seems like something is getting a little messed up with the sudo install.

@jcbhmr
Copy link
Contributor Author

jcbhmr commented Nov 30, 2022

@DaneWeber I actually have no idea why it's different. 🤷‍♂️ Maybe we should ask the official source? https://github.com/haskell/ghcup-hs

Btw thanks for testing this! ♥️ Good thing you did too! 😅

Your quick and easy $HOME bodge is looking better and better, but this way's more fun. 😉

@hasufell
Copy link

That likely means that the shell you are testing this in doesn't have export GHCUP_USE_XDG_DIRS=1 set and so ghcup looks at ~/.ghcup.

@jcbhmr
Copy link
Contributor Author

jcbhmr commented Nov 30, 2022

That likely means that the shell you are testing this in doesn't have export GHCUP_USE_XDG_DIRS=1 set and so ghcup looks at ~/.ghcup.

@hasufell I don't know 🤔. It seems like it should be set to 1 since...

https://github.com/jcbhmr/devcontainers-contrib-features/blob/patch-1/src/haskell/install.sh#L32

export GHCUP_USE_XDG_DIRS=1

https://github.com/jcbhmr/devcontainers-contrib-features/blob/patch-1/src/haskell/install.sh#L57

export GHCUP_USE_XDG_DIRS='$GHCUP_USE_XDG_DIRS'
# This is inside the sudo <<EOF heredoc, thus the $GHCUP_USE_XDG_DIRS *should* be replaced with '1'
# before it gets passed to the bash interpreter, so the bash interpreter sees:
export GHCUP_USE_XDG_DIRS='1'
# ...Right?

But then again, I don't really know 🤷‍♂️

@hasufell
Copy link

Test it via ghcup whereis bindir

@DaneWeber
Copy link
Contributor

That likely means that the shell you are testing this in doesn't have export GHCUP_USE_XDG_DIRS=1 set and so ghcup looks at ~/.ghcup.

Ahh. As in, the install is actually working fine, but when I open the terminal as the nonroot user, GHCUP_USE_XDG_DIRS is not set at that point. Checking...

@DaneWeber
Copy link
Contributor

That's it! Thanks, @hasufell! 🎉

Test results:

vscode ➜ /workspaces/haskell_example $ ghcup list -c installed
[ Info  ] downloading: https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.7.yaml as file /home/vscode/.ghcup/cache/ghcup-0.0.7.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
   Tool  Version  Tags               Notes
✔✔ ghcup 0.1.18.0 latest,recommended      
vscode ➜ /workspaces/haskell_example $ /usr/bin/env | grep GHCUP
vscode ➜ /workspaces/haskell_example $ export GHCUP_USE_XDG_DIRS=1
vscode ➜ /workspaces/haskell_example $ /usr/bin/env | grep GHCUP
GHCUP_USE_XDG_DIRS=1
vscode ➜ /workspaces/haskell_example $ ghcup list -c installed
[ Info  ] downloading: https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.7.yaml as file /home/vscode/.cache/ghcup/ghcup-0.0.7.yaml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
[ Warn  ] New ghc version available. To upgrade, run 'ghcup install ghc 9.4.3'
   Tool  Version  Tags               Notes
✔✔ ghc   9.2.4    base-4.16.3.0           
✔✔ cabal 3.8.1.0  latest                  
✔✔ stack 2.9.1    latest,recommended      
✔✔ ghcup 0.1.18.0 latest,recommended 

Now we just need to add that env var to the _REMOTE_USER's sessions.

#139 (comment)

Co-authored-by: Dane Weber <DaneWeber@users.noreply.github.com>
Signed-off-by: Jacob Hummer <jcbhmr@outlook.com>
@jcbhmr
Copy link
Contributor Author

jcbhmr commented Nov 30, 2022

🎉 Nice job @hasufell and @DaneWeber!

@jcbhmr jcbhmr marked this pull request as ready for review November 30, 2022 04:13
@danielbraun89 danielbraun89 merged commit 8d7d6d2 into devcontainers-contrib:main Nov 30, 2022
@jcbhmr jcbhmr deleted the patch-1 branch November 30, 2022 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants