From 1dbcb4195017bfecc2ff2668d19685c1eae77dae Mon Sep 17 00:00:00 2001 From: Divam Date: Fri, 31 May 2024 17:34:21 +0900 Subject: [PATCH 1/3] Add docs for supporting multiple user install on windows --- docs/guide.md | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/docs/guide.md b/docs/guide.md index 560e998f..97ad1fb6 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -766,6 +766,44 @@ ghcup run --ghc 8.10.7 --cabal latest --hls latest --stack latest --install -- c This will execute vscode with GHC set to 8.10.7 and all other tools to their latest version. +## Support multiple users on Windows + +On Windows, by default GHCup is installed in `C:\ghcup`, and not in the `C:\Users` directory. + +To allow all users of a Windows machine to make use of GHCup all you have to do is set the right global environment variables (and possibly file permissions). + +```sh +$env:PATH += ";C:\ghcup\bin" +``` + +If the GHCup is not installed at the `C:\ghcup`, then additionally the following environment variables would also need adjustment + +* GHCUP_INSTALL_BASE_PREFIX (to e.g. D:\) +* GHCUP_MSYS2 (to e.g. D:\ghcup\msys64) + +Note that if all users have read/write permissions to `C:\ghcup`, then anyone can install, remove, or set (the default) for all of the tools (ghc, cabal, hls, stack), and even remove GHCup completely via `ghcup nuke`. + +To avoid this the administrator can use the "isolate" install feature to install the tools at a shared location for multiple users. + +```sh +ghcup install ghc 9.4.8 --isolate C:\shared-dir\haskell +ghcup install cabal recommended --isolate C:\shared-dir\haskell\bin +ghcup install hls recommended --isolate C:\shared-dir\haskell\bin +``` + +Then each user can access the installed tools by setting the PATH + +```sh +$env:PATH += ";C:\shared-dir\haskell\bin" +``` + +If the users need msys2 C libraries, they will have to each adjust their `cabal.config` as [described here](https://cabal.readthedocs.io/en/latest/how-to-run-in-windows.html#ensure-that-cabal-can-use-system-libraries). Also make sure they [enable long path behavior](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later). + +Also check: + +* [GHCup: manual install on windows](https://www.haskell.org/ghcup/install/#windows_1) +* [GHCup: common env variables](https://www.haskell.org/ghcup/guide/#env-variables) + # Troubleshooting ## Script immediately exits on windows From 126df82a8bf5647aa523f7015be1c33426f6a249 Mon Sep 17 00:00:00 2001 From: Divam Date: Fri, 4 Oct 2024 20:04:31 +0900 Subject: [PATCH 2/3] rewrite the docs on multiple users support --- docs/guide.md | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/docs/guide.md b/docs/guide.md index 97ad1fb6..7ec7cbfb 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -769,36 +769,51 @@ This will execute vscode with GHC set to 8.10.7 and all other tools to their lat ## Support multiple users on Windows On Windows, by default GHCup is installed in `C:\ghcup`, and not in the `C:\Users` directory. +All users who can access `C:\ghcup` can in principle run GHCup and the installed tools with the following steps. -To allow all users of a Windows machine to make use of GHCup all you have to do is set the right global environment variables (and possibly file permissions). +1. Set up permissions -```sh -$env:PATH += ";C:\ghcup\bin" -``` - -If the GHCup is not installed at the `C:\ghcup`, then additionally the following environment variables would also need adjustment +If you wish to allow multiple users to run GHCup, install the tools, modify "set" tool for all users, and even remove GHCup completely via `ghcup nuke`. +Then the users must have write permissions to `C:\ghcup` and its subdirectories. -* GHCUP_INSTALL_BASE_PREFIX (to e.g. D:\) -* GHCUP_MSYS2 (to e.g. D:\ghcup\msys64) +On the other hand to prevent users from installing or modify the installed/set tools, the system administrator should make `C:\ghcup` readonly for other users. -Note that if all users have read/write permissions to `C:\ghcup`, then anyone can install, remove, or set (the default) for all of the tools (ghc, cabal, hls, stack), and even remove GHCup completely via `ghcup nuke`. +2. Set up environment variables globally -To avoid this the administrator can use the "isolate" install feature to install the tools at a shared location for multiple users. +- Append to PATH ```sh -ghcup install ghc 9.4.8 --isolate C:\shared-dir\haskell -ghcup install cabal recommended --isolate C:\shared-dir\haskell\bin -ghcup install hls recommended --isolate C:\shared-dir\haskell\bin +$sysPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine') +$combinedPath = $sysPath + ';C:\ghcup\bin' +[System.Environment]::SetEnvironmentVariable('PATH', $combinedPath, [System.EnvironmentVariableTarget]::Machine) ``` -Then each user can access the installed tools by setting the PATH +Note: if the GHCup is not installed at the default location of `C:\ghcup`, then additionally the following environment variables would also need to be specified. +* GHCUP_INSTALL_BASE_PREFIX +* GHCUP_MSYS2 + +For example ```sh -$env:PATH += ";C:\shared-dir\haskell\bin" +[System.Environment]::SetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', 'C:\shared-dir\haskell\', [System.EnvironmentVariableTarget]::Machine) +[System.Environment]::SetEnvironmentVariable('GHCUP_MSYS2', 'C:\shared-dir\haskell\msys64' , [System.EnvironmentVariableTarget]::Machine) ``` +If there are other users already logged during the above setup of env variables, they will have to sign out and login again to make use of GHCup / tools. + +3. Set up cabal config + +Make sure the users don't have `CABAL_DIR` env set. +This will ensure that `cabal` uses user's local dir (typically `$env:USERPROFILE\AppData\Roaming\cabal`) + If the users need msys2 C libraries, they will have to each adjust their `cabal.config` as [described here](https://cabal.readthedocs.io/en/latest/how-to-run-in-windows.html#ensure-that-cabal-can-use-system-libraries). Also make sure they [enable long path behavior](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later). +The `cabal.config` adjustment can be done by running the following command by each user + +```sh +cabal user-config -a "extra-prog-path: C:\ghcup\bin, $env:USERPROFILE\AppData\Roaming\cabal\bin, C:\ghcup\msys64\mingw64\bin, C:\ghcup\msys64\usr\bin" -a "extra-include-dirs: C:\ghcup\msys64\mingw64\include" -a "extra-lib-dirs: C:\ghcup\msys64\mingw64\lib" -f init +``` + Also check: * [GHCup: manual install on windows](https://www.haskell.org/ghcup/install/#windows_1) From 220d54ae2eeede2289c7b36ab59b17a720f9ba21 Mon Sep 17 00:00:00 2001 From: Divam <681060+dfordivam@users.noreply.github.com> Date: Fri, 4 Oct 2024 20:10:00 +0900 Subject: [PATCH 3/3] Fix some formating in guide.md --- docs/guide.md | 54 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/docs/guide.md b/docs/guide.md index 7ec7cbfb..98e156a7 100644 --- a/docs/guide.md +++ b/docs/guide.md @@ -773,51 +773,49 @@ All users who can access `C:\ghcup` can in principle run GHCup and the installed 1. Set up permissions -If you wish to allow multiple users to run GHCup, install the tools, modify "set" tool for all users, and even remove GHCup completely via `ghcup nuke`. -Then the users must have write permissions to `C:\ghcup` and its subdirectories. + If you wish to allow multiple users to run GHCup, install the tools, modify "set" tool for all users, and even remove GHCup completely via `ghcup nuke`. Then the users must have write permissions to `C:\ghcup` and its subdirectories. -On the other hand to prevent users from installing or modify the installed/set tools, the system administrator should make `C:\ghcup` readonly for other users. + On the other hand to prevent users from installing or modify the installed/set tools, the system administrator should make `C:\ghcup` readonly for other users. 2. Set up environment variables globally -- Append to PATH + Append bin dir to PATH -```sh -$sysPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine') -$combinedPath = $sysPath + ';C:\ghcup\bin' -[System.Environment]::SetEnvironmentVariable('PATH', $combinedPath, [System.EnvironmentVariableTarget]::Machine) -``` + ```sh + $sysPath = [Environment]::GetEnvironmentVariable('PATH', 'Machine') + $combinedPath = $sysPath + ';C:\ghcup\bin' + [System.Environment]::SetEnvironmentVariable('PATH', $combinedPath, [System.EnvironmentVariableTarget]::Machine) + ``` -Note: if the GHCup is not installed at the default location of `C:\ghcup`, then additionally the following environment variables would also need to be specified. + Note: if the GHCup is not installed at the default location of `C:\ghcup`, then additionally the following environment variables would also need to be specified. -* GHCUP_INSTALL_BASE_PREFIX -* GHCUP_MSYS2 + * GHCUP_INSTALL_BASE_PREFIX + * GHCUP_MSYS2 -For example -```sh -[System.Environment]::SetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', 'C:\shared-dir\haskell\', [System.EnvironmentVariableTarget]::Machine) -[System.Environment]::SetEnvironmentVariable('GHCUP_MSYS2', 'C:\shared-dir\haskell\msys64' , [System.EnvironmentVariableTarget]::Machine) -``` + For example + ```sh + [System.Environment]::SetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', 'C:\shared-dir\haskell\', [System.EnvironmentVariableTarget]::Machine) + [System.Environment]::SetEnvironmentVariable('GHCUP_MSYS2', 'C:\shared-dir\haskell\msys64' , [System.EnvironmentVariableTarget]::Machine) + ``` -If there are other users already logged during the above setup of env variables, they will have to sign out and login again to make use of GHCup / tools. + If there are other users already logged during the above setup of env variables, they will have to sign out and login again to make use of GHCup / tools. 3. Set up cabal config -Make sure the users don't have `CABAL_DIR` env set. -This will ensure that `cabal` uses user's local dir (typically `$env:USERPROFILE\AppData\Roaming\cabal`) + Make sure the users don't have `CABAL_DIR` env set. This will ensure that `cabal` uses user's local dir (typically `$env:USERPROFILE\AppData\Roaming\cabal`) -If the users need msys2 C libraries, they will have to each adjust their `cabal.config` as [described here](https://cabal.readthedocs.io/en/latest/how-to-run-in-windows.html#ensure-that-cabal-can-use-system-libraries). Also make sure they [enable long path behavior](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later). + If the users need msys2 C libraries, they will have to each adjust their `cabal.config` as [described here](https://cabal.readthedocs.io/en/latest/how-to-run-in-windows.html#ensure-that-cabal-can-use-system-libraries). Also make sure they [enable long path behavior](https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later). -The `cabal.config` adjustment can be done by running the following command by each user + The `cabal.config` adjustment can be done by running the following command by each user -```sh -cabal user-config -a "extra-prog-path: C:\ghcup\bin, $env:USERPROFILE\AppData\Roaming\cabal\bin, C:\ghcup\msys64\mingw64\bin, C:\ghcup\msys64\usr\bin" -a "extra-include-dirs: C:\ghcup\msys64\mingw64\include" -a "extra-lib-dirs: C:\ghcup\msys64\mingw64\lib" -f init -``` + ```sh + cabal user-config -a "extra-prog-path: C:\ghcup\bin, $env:USERPROFILE\AppData\Roaming\cabal\bin, C:\ghcup\msys64\mingw64\bin, C:\ghcup\msys64\usr\bin" -a "extra-include-dirs: C:\ghcup\msys64\mingw64\include" -a "extra-lib-dirs: C:\ghcup\msys64\mingw64\lib" -f init + ``` -Also check: + Also check: -* [GHCup: manual install on windows](https://www.haskell.org/ghcup/install/#windows_1) -* [GHCup: common env variables](https://www.haskell.org/ghcup/guide/#env-variables) + * [GHCup: manual install on windows](https://www.haskell.org/ghcup/install/#windows_1) + * [GHCup: common env variables](https://www.haskell.org/ghcup/guide/#env-variables) # Troubleshooting