haskell / ghcup-hs

https://www.haskell.org/ghcup/
GNU Lesser General Public License v3.0
290 stars 90 forks source link

/c/ghcup/bin not in msys2 PATH #981

Closed karamellpelle closed 10 months ago

karamellpelle commented 10 months ago

I installed GHCup for Windows 11 using PowerShell as described. Installation goes well, and I get a nice msys2 unix shell with pacman which lets me enjoy Windows 11 a lot [^1].

But the haskell commands like ghc, ghci, stack are not available in msys2! That's because (the default) install location /c/ghcup/bin is not in PATH. To cite msys2 "For optimal usage, MSYS2 automatically strips your PATH environment variable, essentially only leaving C:\Windows\System32 and few others.".

There is a variable MSYS2_PATH_TYPE to override the Path strip behaviour, but I don't think that's a good solution (there is a reason msys2 strips Path). Maybe better to add /c/ghcup/bin to the/a launcher script?

c:\ghcup\bin is however in windows Path, so the haskell commands are available in PowerShell.

Bonus question: How are we supposed to use GHCup to build native (professional) programs for Windows? Should we only work in PowerShell? Or can we likewise build with msys2 (are there any difference between the two build environments)?


Thanks a lot for GHCup that makes it very easy to do Haskell on Windows! :star: :star: :star: :star: :star:


[^1]: After debloating my Windows installation by removing apps, widgets, etc, Windows 11 is actually a nice OS.

hasufell commented 10 months ago

I can't reproduce this. How do you start msys2? There's a desktop icon that executes C:\ghcup\msys64\msys2_shell.cmd -mingw64. That is the correct way.

karamellpelle commented 10 months ago

Yes, I'm using that Desktop icon/Windows shortcut. I have Windows 11. Strange!

Did you try a new install of GHCup for Windows? C:\ghcup\bin has been added to my Windows environment variable Path.

Here is my msys2 version:

cat /proc/version                                                                                                                                                                                  
MINGW64_NT-10.0-22631 version 3.4.10.x86_64 (runneradmin@fv-az1495-832) (gcc version 13.2.0 (GCC) ) 2023-12-22 10:06 UTC
hasufell commented 10 months ago

What is your home directory inside mingw? What does your bahrc say?

karamellpelle commented 10 months ago

My .bashrc at C:\ghcup\msys64\home\karamellpelle is commented out, except for this code:

# If not running interactively, don't do anything
[[ "$-" != *i* ]] && return

Now I'm using zsh (pacman -S zsh and set set "LOGINSHELL=zsh" instead of bash in the beginning of _msys2shell.cmd), but the problem was still present so I had to add /c/ghcup/bin to msys2 PATH in zsh config file.

Here is the output of env in msys2:

!::=::\
!C:=C:\Users\karamellpelle\Desktop
ALLUSERSPROFILE=C:\ProgramData
APPDATA=C:\Users\karamellpelle\AppData\Roaming
CABAL_DIR=C:\cabal
COMMONPROGRAMFILES=C:\Program Files\Common Files
CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files
CommonProgramW6432=C:\Program Files\Common Files
COMPUTERNAME=LEGION-WIN
COMSPEC=C:\WINDOWS\system32\cmd.exe
CONICON=mingw64.ico
CONTITLE=MinGW x64
DriverData=C:\Windows\System32\Drivers\DriverData
EFC_131784=1
GHCUP_INSTALL_BASE_PREFIX=C:\
HOMEDRIVE=C:
HOMEPATH=\Users\karamellpelle
LOCALAPPDATA=C:\Users\karamellpelle\AppData\Local
LOGINSHELL=zsh
LOGONSERVER=\\LEGION-WIN
MSYSCON=mintty.exe
MSYSTEM=MINGW64
NUMBER_OF_PROCESSORS=16
OneDrive=C:\Users\karamellpelle\OneDrive
OneDriveConsumer=C:\Users\karamellpelle\OneDrive
OS=Windows_NT
PATH=/c/ghcup/bin:C:\Users\karamellpelle\AppData\Roaming/local/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=AMD64 Family 25 Model 116 Stepping 1, AuthenticAMD
PROCESSOR_LEVEL=25
PROCESSOR_REVISION=7401
ProgramData=C:\ProgramData
PROGRAMFILES=C:\Program Files
ProgramFiles(x86)=C:\Program Files (x86)
ProgramW6432=C:\Program Files
PROMPT=%F{green}%n@%m%f %F{magenta}MINGW64%f %F{yellow}%~%f %# 
PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PUBLIC=C:\Users\Public
SESSIONNAME=Console
SYSTEMDRIVE=C:
SYSTEMROOT=C:\WINDOWS
TEMP=/tmp
TMP=/tmp
USERDOMAIN=LEGION-WIN
USERDOMAIN_ROAMINGPROFILE=LEGION-WIN
USERNAME=karamellpelle
USERPROFILE=C:\Users\karamellpelle
WD=C:\ghcup\msys64\usr\bin\
WINDIR=C:\WINDOWS
TERM=xterm
HOME=/c/Users/karamellpelle
LC_CTYPE=en_US.UTF-8
TERM_PROGRAM=mintty
TERM_PROGRAM_VERSION=3.7.0
LOGNAME=karamellpelle
SHLVL=1
PWD=/c/Users/karamellpelle
OLDPWD=/c/Users/karamellpelle/Desktop
MSYSTEM_PREFIX=/mingw64
MSYSTEM_CARCH=x86_64
MSYSTEM_CHOST=x86_64-w64-mingw32
MINGW_CHOST=x86_64-w64-mingw32
MINGW_PREFIX=/mingw64
MINGW_PACKAGE_PREFIX=mingw-w64-x86_64
XDG_DATA_DIRS=/mingw64/share/:/usr/local/share/:/usr/share/
TZ=Europe/Oslo
ACLOCAL_PATH=/mingw64/share/aclocal:/usr/share/aclocal
MANPATH=/mingw64/local/man:/mingw64/share/man:/usr/local/man:/usr/share/man:/usr/man:/share/man
INFOPATH=/mingw64/local/info:/mingw64/share/info:/usr/local/info:/usr/share/info:/usr/info:/share/info
PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig
PKG_CONFIG_SYSTEM_INCLUDE_PATH=/mingw64/include
PKG_CONFIG_SYSTEM_LIBRARY_PATH=/mingw64/lib
USER=karamellpelle
PRINTER=
HOSTNAME=legion-win
PS1=%B%(?..[%?] )%b%n@%U%m%u> 
SHELL=/usr/bin/zsh
ORIGINAL_TMP=/c/Users/KARAME~1/AppData/Local/Temp
ORIGINAL_TEMP=/c/Users/KARAME~1/AppData/Local/Temp
ORIGINAL_PATH=/c/Windows/System32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0/
CONFIG_SITE=/etc/config.site
EDITOR=vim
VISUAL=vim
LANG=en_US.UTF-8
LESS=-g -i -M -R -S -w -X -z-4
LESS_TERMCAP_mb=
LESS_TERMCAP_md=
LESS_TERMCAP_me=
LESS_TERMCAP_se=
LESS_TERMCAP_so=
LESS_TERMCAP_ue=
LESS_TERMCAP_us=
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
GREP_COLOR=37;45
GREP_COLORS=mt=37;45
_=/usr/bin/env
karamellpelle commented 10 months ago

Things work when I add /c/msys2/bin to my msys2 PATH, so I'm not in trouble.

I thought this could be a problem for more people, especially Haskell beginners which I want to give a good experience. The GHCup installation on Windows 11 works perfectly otherwise!

hasufell commented 10 months ago

C:\ghcup\msys64\home\karamellpelle

I don't think this is the HOME directory that's relevant.

https://github.com/haskell/ghcup-hs/blob/9a7eb11c738492ca9f37eb07bf9eac49d5c0ac6a/scripts/bootstrap/bootstrap-haskell.ps1#L501

This changes the home dir to your true windows user directory.

Now I'm using zsh (pacman -S zsh and set set "LOGINSHELL=zsh" instead of bash in the beginning of msys2_shell.cmd),

It appears you're doing custom configuration, which I don't know how to support. If you do custom config, you have to take care of PATH yourself.


The question is whether ghc/ghcup is in PATH in the mingw env (following the desktop icon) after a normal installation.

hasufell commented 10 months ago

https://github.com/haskell/ghcup-hs/pull/986