AjayKMehta / setup-machine

Notes and scripts to setup new Windows machine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Setup machine

Overview

Important

This document assumes that your C: drive has limited space (e.g. SSD) and you have another hard drive (D:) which you can use to install apps on instead. If that is not the case, you can omit custom location (-l) in winget install invocation or specify a directory on your C drive instead.

Setting up a new Windows machine for development is painful.

This document hopefully alleviates the pain.

Note

🚧 Look into using winget configure to replace script to install apps. 👉 Need to learn how to specify custom install path.

winget

Install winget from Microsoft Store if it is not already installed.

Advanced System Font Changer

The Advanced System Font Changer lets you change system font settings.

Firefox

  • Install: winget install Mozilla.Firefox.
  • Use Firefox account to sync various items.

Fonts

Notepad++

  • Download from web and install or use winget:

    winget install -e Notepad++.Notepad++
  • Enable support for fonts with ligatures: Preferences ➡️MISC. Make sure Use DirectWrite (May improve rendering special characters, need to restart Notepad++) is ✅.

Plugins

  • Compare
  • EditorConfig
  • JSTool
  • Location Navigate
  • XML Tools

OpenSSH

See here.

- Install: winget install Microsoft.OpenSSH.Beta

- Add install folder (C:\Program Files\OpenSSH) to $Path.

KeePassXC

  • Install KeePassXC:

    winget install KeePassXCTeam.KeePassXC -l D:\Apps\KeePassXC
  • See here for information on getting started.

  • Add installation folder to $Path if needed:

    $path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
    $path += ';D:\Apps\KeePassXC'
    [System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')

PowerShell

  • Install:

    winget install -e --id Microsoft.PowerShell
  • Install Oh My Posh as theme engine:

    Invoke-RestMethod https://ohmyposh.dev/install.ps1 | Invoke-Expression

    This will add install path to $Path.

    In a new shell:

    oh-my-posh completion powershell | Out-File -encoding utf8 ~\Documents\PowerShell\Scripts\ArgumentCompleters\oh-my-posh.ps1
  • Disable telemetry:

    [System.Environment]::SetEnvironmentVariable('POWERSHELL_TELEMETRY_OPTOUT', 1, 'User')
  • See here for info on how to resolve the issue Enabling PowerShell remoting fails due to Public network connection type

Modules

See ModulesToInstall.txt for list of modules to install.

Secrets Management

  • Install modules if necessary:

    Install-Module -Name Microsoft.PowerShell.SecretManagement -Repository PSGallery
    Install-Module -Name Microsoft.PowerShell.SecretStore -Repository PSGallery
    Install-Module SecretManagement.KeePass
  • Configure secret store:

    Set-secretstoreConfiguration -Scope CurrentUser -Authentication Password -PasswordTimeout 3600
    Set-SecretStorePassword
  • Register vaults:

    Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
    # Assuming you created a Keepass DB with path below
    Register-SecretVault -Name 'Keepass' -ModuleName 'SecretManagement.Keepass' -VaultParameters @{
    Path = "D:\keepass\Passwords.kdbx"
    UseMasterPassword = $true
    }
  • Test that it works:

    Get-SecretInfo
    Test-SecretVault -Name 'Keepass'

git

  • Install: winget install --id Git.Git -e --source winget.

  • Enable auto-signing Git commits with GnuPG:

    • Install required apps:

      winget install --id GnuPG.GnuPG -l 'D:\Apps\GnuPG'
      winget install --id GnuPG.Gpg4win -l 'D:\Apps\Gpg4win'
    • Add to $Path if needed:

      $path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
      $path += ';D:\Apps\Gpg4win\bin;D:\Apps\GnuPG\bin'
      [System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')
    • Managing GPG keys 🚧 WIP

GitHub CLI

  • Download GitHub CLI. See Releases for latest version.

    $version = '2.39.0'
    Invoke-RestMethod "https://github.com/cli/cli/releases/download/v${version}/gh_${version}_windows_amd64.zip" -OutFile ~/Downloads/gh_${version}_windows_amd64.zip
  • Copy binary to desired location.

    [string] $folder = 'D:\Apps'
    7z e C:\Users\Ajay\Downloads\gh_2.39.0_windows_amd64.zip bin\gh.exe -o"$($folder)"
  • Add shell completion script (that you can dot-source in PowerShell profile):

    gh completion -s powershell | Out-File -Encoding utf8 ~\Documents\PowerShell\Scripts\ArgumentCompleters\gh.ps1

GitHub PAT

Extensions

Install extensions:

gh extension install actions/gh-actions-cache
gh extension install securesauce/gh-alerts
gh extension install mislav/gh-branch
gh extension install chelnak/gh-changelog
gh extension install vilmibm/gh-contribute
gh extension install mislav/gh-cp
gh extension install dlvhdr/gh-dash
gh extension install yuler/gh-download
gh extension install owenvoke/gh-gpg-key
gh extension install k1LoW/gh-grep
gh extension install redraw/gh-install
gh extension install heaths/gh-label
gh extension install meiji163/gh-notify
gh extension install seachicken/gh-poi
gh extension install samcoe/gh-repo-explore
gh extension install samcoe/gh-triage
gh extension install vilmibm/gh-user-status

GitLab CLI

  • Install:

    winget install Glab.Glab
  • Get a GitLab PAT with at least api and write_repository scopes.

  • Setup: glab auth login.

  • Shell completion: glab completion -s powershell | Out-File ~\Documents\PowerShell\Scripts\ArgumentCompleters\glab.ps1 -Encoding utf8

GitExtensions

Install: winget install GitExtensionsTeam.GitExtensions.

Java

  • Install:

    winget install Oracle.JDK.17
  • Set $JAVA_HOME:

    [System.Environment]::SetEnvironmentVariable('JAVA_HOME', 'C:\Program Files\Java\jdk-17.0.5', 'Machine')
  • Add bin folder (C:\Program Files\Java\jdk-17.0.5\bin) to $Path.

  • Install maven from https://maven.apache.org/download.cgi and add installation folder to $Path.

CLI Apps

💡 Install CLI apps in a common directory and add common directory to $Path.

less

less is a pager.

  • Install:

    winget install JohnTaylor.less -l D:\Apps
    winget install JohnTaylor.lesskey -l D:\Apps
  • Set environment variables:

    [System.Environment]::SetEnvironmentVariable('LESS', '-RX', 'Machine')
    [System.Environment]::SetEnvironmentVariable('LESSCHARSET', 'UTF8', 'Machine')

fzf

fzf is a command-line fuzzy finder.

  1. Get latest binaries from here. If you have already installed GitHub CLI and 7zip:

    $downloadFolder = (Resolve-Path ~\Downloads).Path
    $pattern = 'fzf*windows*amd64.zip'
    gh release download --repo junegunn/fzf --pattern $pattern -D $downloadPath
    $zipFile = Get-Item $downloadPath -Filter $pattern | Select-Object -First 1
    $destination = 'D:\Apps'
    7z e -o"$destination" $zipFile 'fzf.exe'
    $zipFile | Delete-Item
  2. Override default command: set $FZF_DEFAULT_COMMAND to rg --files . 2> nul.

  3. Override default options:

    $opts = @'
    --color=fg:-1,bg:-1,hl:#5fff87,fg+:-1,bg+:-1,hl+:#ffaf5f
    --color=info:#af87ff,prompt:#5fff87,pointer:#ff87d7,marker:#ff87d7,spinner:#ff87d7
    --bind alt-up:preview-page-up,alt-down:preview-page-down,alt-e:preview-top,alt-f:preview-bottom,ctrl-e:half-page-up,ctrl-f:half-page-down
    '@
    [System.Environment]::SetEnvironmentVariable('FZF_DEFAULT_OPTS', $opts, 'User')

ripgrep

ripgrep is a powerful search tool.

  • Get it from here.
  • Add installation path to $Path.

delta

delta is a syntax-highlighting pager for git, diff, and grep output. In order to use it with git, you need to modify .gitconfig or you can import dot files.

yq

yq is a portable command-line YAML, JSON, XML, CSV and properties processor.

Install: winget install yq -l D:\Apps -r yq.exe.

jq

jq is a command-line JSON processor.

Install: winget install stedolan.jq -l D:\Apps -r jq.exe.

bat

  • Install bat from here.

  • Add installation path to $Path.

  • Create folder if it does not exist: $env:AppData\Local\bat\cache

  • Add following environment variables: BAT_PAGER = less -RF.

  • A default configuration file can be created with the --generate-config-file option.

    bat --generate-config-file

gum

Gum provides highly configurable, ready-to-use utilities to help you write useful shell scripts and dotfiles aliases with just a few lines of code.

winget install charmbracelet.gum -l D:\Apps

duckdb

winget install DuckDB.cli -l D:\Apps

Upgrading

Before installing new version of CLI, you need to export any databases from old CLI and re-import in new CLI 😦

For example, let's say you have a database D:/duck_db/nyc-taxi.duckdb.

  1. In CLI for old version, execute: .open D:/duck_db/nyc-taxi.duckdb

  2. In CLI for old version: EXPORT DATABASE 'D:/duckdb_export/nyc-taxi';

  3. Delete old file D:/duck_db/nyc-taxi.duckdb.

  4. In R using latest version of duckdb package:

    con <- dbConnect(duckdb::duckdb(), dbdir = "D:/duckdb/nyc-taxi.duckdb", read_only = FALSE)
    dbExecute(con, "IMPORT DATABASE 'D:/duckdb_export/nyc-taxi'")

wget2

winget install GNU.wget2

Dot files

  • Install chezmoi:

    winget install twpayne.chezmoi
  • Run chezmoi init to create an initial chezmoi.toml using template in repo:

    chezmoi init AjayKMehta

Tip

You can supply --apply in the above command to generate dot files at same time.

Hugo

Hugo is an open-source static site generator.

  • Install:

    winget install Hugo.Hugo -l D:\apps\Hugo
  • Add installation folder to $Path.

WSL

See wsl.md.

Docker

winget install Docker.DockerDesktop

Docker Credentials Helper

  1. Go to the Releases page and download the binary (docker-credential-wincred) that works for you. Put that binary in your $PATH, so Docker can find it.

  2. Set the credsStore option in your ~/.docker/config.json file with the suffix of the program you want to use (wincred).

    {
        "credsStore": "wincred"
    }

Change images and containers directory

Follow the instructions here for WSL 2 backend:

wsl --shutdown
wsl --export docker-desktop-data docker-desktop-data.tar
wsl --unregister docker-desktop-data
# Import the exported data to D:\Docker\wsl\data
wsl --import docker-desktop-data D:/Docker/wsl/data docker-desktop-data.tar --version 2

Getting a Shell in Docker for Windows Moby VM

docker run -it --rm --privileged --pid=host justincormack/nsenter1

Source

Shrink your WSL2 Virtual Disks and Docker Images and Reclaim Disk Space

Optimize-VHD -Path D:\Docker\wsl\data\ext4.vhdx -Mode Full

Utilities

winget install wagoodman.dive -l D:\Apps
winget install JesseDuffield.Lazydocker -l D:\Apps

WezTerm

WezTerm is a powerful cross-platform terminal emulator and multiplexer.

  • Install:

    winget install wez.wezterm -l D:\Apps\WezTerm
  • (Optional) Add installation folder to $Path.

Useful links

Hadoop

See here for more details. As of the time this was written, the version of interest for Hadoop was 3.3.1.

pushd ~/Downloads
Invoke-WebRequest https://dlcdn.apache.org/hadoop/common/hadoop-3.3.1/hadoop-3.3.1.tar.gz -OutFile hadoop-3.3.1.tar.gz -Verbose
# https://stackoverflow.com/a/2903532
7z e hadoop-3.3.1.tar.gz && 7z x hadoop-3.3.1.tar -o"D:/Apps"
Remove-Item hadoop-3.3.1.tar*

# Download Hadoop native IO binary
gh download https://github.com/kontext-tech/winutils/tree/master/hadoop-3.3.1/bin

# Copy files to bin folder. Add -L to do dry-run
robocopy .\hadoop-3.3.1\bin D:\Apps\hadoop-3.3.1\bin
Remove-Item .\hadoop-3.3.1\bin 
popd

[System.Environment]::SetEnvironmentVariable('HADOOP_HOME', 'D:\Apps\hadoop-3.3.1', 'User')

Python

Note

At some point, I would like to switch to poetry due to the challenges presented when using conda and pip together.

  • Download and install Miniconda.

  • Add bin folder (D:\Apps\Miniconda\condabin) to $Path.

  • To use UTF-8 mode on Windows, set environment variable $PYTHONUTF8 to 1.

  • To enable conda in PowerShell, run the following in conda prompt:

    conda init powershell cmd.exe
  • Enable pip interoperability:

    conda config --set pip_interop_enabled True
  • Add environment variables:

    SET VS140COMNTOOLS = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\"
    SET VS90COMNTOOLS = %VS140COMNTOOLS%
  • To resolve error URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:997)>, install https://letsencrypt.org/certs/lets-encrypt-r3.der (source).

JupyterLab

Install following extensions:

  • jupyterlab-plotly
  • @jupyterlab/latex
  • @ryantam626/jupyterlab_code_formatter
mamba install jupyterlab-latex jupyterlab-plotly-extension jupyterlab_code_formatter

Workaround for Quarto

See Use with nbconvert, voila, papermill,....

Git-friendly hooks

See here for details.

GenAI

Make sure that you configure environment variables for API keys.

PaLM

Cohere

Replicate

Weights & Biases

LLM

To override the directory used to store prompt templates, etc., set $LLM_USER_PATH (source):

[System.Environment]::SetEnvironmentVariable('LLM_USER_PATH', 'D:\llm', 'User')

OpenAI

HuggingFace

🚧 WIP

R

  1. Download and install R from CRAN website. Alternatively, winget install RProject.R.

  2. Add <InstallPath>\bin\x64 to $PATH.

  3. Default folder of .RProfile and .REnviron is ~\Documents which leads to issues if OneDrive moves this folder to ~\OneDrive\Documents :frowning:. So, best to set environment variables:

    [System.Environment]::SetEnvironmentVariable('R_ENVIRON_USER', '~\.Renviron', 'User')
    [System.Environment]::SetEnvironmentVariable('R_PROFILE_USER', '~\.Rprofile', 'User')
  4. To avoid the issue of C: running out of disk space, set $R_LIBS to a different path, e.g.D:\packages.

  5. Set $GITHUB_PAT to GitHub PAT obtained. This is neccessary for avoiding rate-limit issues when installing packages from GitHub using the remotes package.

RStudio

winget install Posit.RStudio

RTools

  • Install location is usually C:\RTools but if you have limited disk space, set RTOOLS43_HOMEto a different path, e.g.D:\rtools43 before running the installer.
  • Download and run R Build tools.
  • Add bin folder in install path to $PATH -- this can be done by editing .Renviron: PATH="${RTOOLS40_HOME}\usr\bin;${PATH}".

Usage notes

Spark

  1. In .RProfile, set options(spark.install.dir = "D:/Apps/Spark")

  2. Install sparklyr:

    install.packages("sparklyr")
  3. Check available versions:

    library(sparklyr)
    spark_versions()
  4. Install required version:

    spark_install("3.3.2", "3")
  5. Set $SPARK_HOME to bin folder, i.e. D:\Apps\Spark\spark-3.3.2-bin-hadoop3\bin.

Stan

cmdstanr

install.packages("cmdstanr")
cmdstanr::install_cmdstan(dir = "D:/Apps", overwrite = TRUE, cores = 6)
cmdstanr::set_cmdstan_path() # D:/Apps/cmdstan-2.24.1

radian

From the project's README.md:

radian is an alternative console for the R program with multiline editing and rich syntax highlight.

Installation steps:

  1. Install radian: conda install radian.
  2. Set $R_BINARY to <InstallPath>\bin\x64\R.exe. This is needed for radian to work properly.

Setup for VS Code

  1. Install languageserver and httpgd in R: install.packages(c("languageserver", "httpgd")).
  2. Install the R extension for Visual Studio Code.
  3. Set up radian as R console in VS Code.
  4. Install VSCode-R-Debugger package: remotes::install_github(ref = "v0.5.2", "ManuelHentschel/vscDebugger").

See here for more details.

Setup for Jupyter

  1. Install R package IRKernel: install.packages("IRKernel").
  2. Activate conda environment with Jupyter installed.
  3. Use jupyter kernelspec list to get location of existing kernels. If you see a path corresponding to $Appdata\jupyter\kernels\ir, then R kernel is already installed.
  4. Launch radian in conda environment's shell.
  5. In radian: IRKernel::installspec().

Alternatively, you can copy files from IRKernel package installation directory's kernelspec subfolder to $Appdata\jupyter\kernels\ir.

catboost

This is available from GitHub.

  1. Download latest release from https://github.com/catboost/catboost/releases.
  2. Install: install.packages(repo = NULL, type = "source", r"{C:\Users\Ajay\Downloads\catboost-R-windows-x86_64-1.2.2.tgz}").

INLA

See here.

Quarto

Quarto is a replacement for RMarkdown that also works with Python.

To install:

  1. Download installer from https://github.com/quarto-dev/quarto-cli/releases and run.

  2. Add installation path (D:\Apps\Quarto\bin) to $PATH if not already available.

  3. RStudio ships with its owb version of Quarto + Pandoc. To use Quarto and its bundled version of Pandoc, add the following to your .Renviron file:

    QUARTO_PATH="D:/Apps/quarto/bin/quarto.cmd"
    RSTUDIO_PANDOC="D:/Apps/quarto/bin/tools"

Extras

To support rendering of PDF documents that include SVG files, automatically converting them to PDF images in Quarto 1.3+, install rsvg-convert from https://github.com/miyako/console-rsvg-convert and add to$PATH.

(Optional) tinytex is a lightweight alternative to MikTeX:

quarto install tinytex

Use OpenBLAS

You can use OpenBLAS to speed up linear algebra operations but use at your own risk! Instructions below are modified from this SO post and https://medium.com/@FredHo42/using-intel-mkl-library-on-r-4-0-641dc0c3c06b.

  1. Download latest version of OpenBLAS from https://github.com/OpenMathLib/OpenBLAS/releases.
  2. Copy Rlapack.dll and Rblas.dll from ./bin/x64 in R installation folder to safe location.
  3. Now create 2 copies of libopenblas.dll named Rlapack.dll and Rblas.dll and copy them to folder from step 1.
  4. If you run into problems, you can revert back to the original DLLs.

Check performance:

Before

> system.time(svd(matrix(runif(10000*2000), 10000, 2000), nu=0, nv=0))
   user  system elapsed 
  43.50    0.09   44.06 

After

> system.time(svd(matrix(runif(10000*2000), 10000, 2000), nu=0, nv=0))
   user  system elapsed
  20.72    1.20    5.30

DotNet

  • Install Visual Studio Community 2022:

    winget install Microsoft.VisualStudio.2022.Community

    This will also install .NET 8 SDK.

  • Install templates for dotnet new:

    dotnet new install "Boxed.Templates"
    dotnet new install "Amazon.Lambda.Templates"
    dotnet new install "NUnit3.DotNetNew.Template"
  • Set environment variables related to runtime configuration for compilation:

    [System.Environment]::SetEnvironmentVariable('DOTNET_TC_QuickJitForLoops', 1, 'User')
    [System.Environment]::SetEnvironmentVariable('DOTNET_TieredPGO', 1, 'User')
  • Disable telemetry:

    [System.Environment]::SetEnvironmentVariable('DOTNET_CLI_TELEMETRY_OPTOUT', 1, 'User')
    [System.Environment]::SetEnvironmentVariable('DOTNET_UPGRADEASSISTANT_TELEMETRY_OPTOUT', 1, 'User')

NuGet

  • Change directory for NuGet packages

    [System.Environment]::SetEnvironmentVariable('NUGET_PACKAGES', 'D:\NuGet\packages', 'Machine')
  • Install NuGet: winget install Microsoft.NuGet.

  • Add installation path to $Path.

Useful apps

  • Install LinqPad 7:

    winget install --id LINQPad.LINQPad.7 -l 'D:\Apps\LINQPad7\'
  • Install ILSpy:

    winget install --id icsharpcode.ILSpy -l 'D:\Apps\ILSpy'
  • Install Nuget Package Explorer:

    winget install --id 9WZDNCRDMDM3
  • Install MSBuild Structured Log Viewer:

    winget install --id KirillOsenkov.MSBuildStructuredLogViewer
  • Install NSwagStudio:

    winget install --id RicoSuter.NSwagStudio
  • Install NUnit Console from here.

  • Install PerfView:

    winget install Microsoft.PerfView -l D:\Apps\PerfView

Dotnet Tools

Install following tools:

dotnet tool install -g benchmarkdotnet.tool
dotnet tool install -g coverlet.console
dotnet tool install -g diffenginetray
dotnet tool install -g dotnet-counters
dotnet tool install -g dotnet-depends
dotnet tool install -g dotnet-monitor
dotnet tool install -g dotnet-outdated-tool
dotnet tool install -g dotnet-reportgenerator-globaltool
dotnet tool install -g dotnet-sos
dotnet tool install -g dotnet-stack
dotnet tool install -g dotnet-stryker
dotnet tool install -g dotnet-trace
dotnet tool install -g microsoft.coyote.cli
dotnet tool install -g microsoft.dotnet-httprepl
dotnet tool install -g microsoft.dotnet-interactive
dotnet tool install -g minver-cli
dotnet tool install -g roslynator.dotnet.cli
dotnet tool install -g snitch
dotnet tool install -g upgrade-assistant

LaTeX

MikTeX

  • Download MiKTeX command-line installer from https://miktex.org/download.

  • Extract miktexsetup_standalone.exe and set current directory to its folder location.

  • Run the following comand to download MiKTeX into a local package repository:

    . .\miktexsetup_standalone.exe --verbose --local-package-repository=D:\miktex-repository --package-set=basic download
  • Next, run:

    $installFolder = 'D:\Apps\Miktex'
    
    $dataFolder = 'D:\ProgramData\Miktex'
    
    . .\miktexsetup_standalone.exe --common-config=$dataFolder --common-data=$dataFolder --common-install=$installFolder --local-package-repository=D:\miktex-repository --modify-path --package-set=basic --shared=yes --user-config="$env:APPDATA\MiKTeX" --user-data="$env:LOCALAPPDATA\MiKTeX" --print-info-only  install
  • Output should look like this:

    setup task: install from local package repository
    local package repository: D:\miktex-repository
    package set: basic
    install for all users?: yes
    portable? : no
    use registry?: yes
    modify path?: yes
    program folder name: MiKTeX
    common install root: D:\Apps\Miktex
    common config root: "D:\ProgramData\Miktex"
    common data root: "D:\ProgramData\Miktex"
    user config root: C:\Users\Ajay\AppData\Roaming\MiKTeX
    user data root: C:\Users\Ajay\AppData\Local\MiKTeX
  • If the output looks OK, remove --print-info-only from above CLI command and run to install MikTex.

  • Add $installFolder\bin\x64\ to $Path.

Packages

See miktex_packages.txt for list of packages to install.

VS Code

  • Install:

    winget install --id Microsoft.VisualStudioCode -l 'D:\Apps\VSCode'
  • Add installation folder (e.g. D:\Apps\VSCode\bin) to $Path.

  • Use settings sync to get settings.

WinMerge

WinMerge is a diff/merge tool.

  • Install:

    winget install --id WinMerge.WinMerge -l 'D:\Apps\WinMerge'
  • Add to $Path:

    $path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
    $path += ';D:\Apps\WinMerge'
    [System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')

SlickRun

SlickRun is a free-floating utility for Windows that can launch programs. Download it from here.

Node

Haskell

GHCup is the main installer for Haskell. Setting up Haskell on Windows is still painful but less so than before GHCup came around.

Regular installation steps

  • If you wish to specify the installation root directory for ghcup, you can set $GHCUP_INSTALL_BASE_PREFIX1 (user-level environment variable). If not set, you can pass install directory choice to the install script or the script will prompt you if it doesn't find a drive with > 5 GB free space to install on.
  • Download install script:

    cd ~\Downloads\ && Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -OutFile bootstrap-haskell.ps1

Warning

Although the website says to run it directly, I think it's a good idea to review the script first and possibly customize invocation as the script has several parameters and the default values may not work for you.

  • Run script in non-admin powershell:

    # Hash from https://github.com/msys2/msys2-installer/releases/download/2023-07-18/msys2-base-x86_64-20230718.sfx.exe.sha256
    . .\bootstrap-haskell.ps1 -InstallStack -InStallHLS -InstallDir D:\Apps -Msys2Version '20230718' -Msys2Hash 'ab9b9a25e92d0c71136c79eeac954f1ce023341224de8d81401439f38c8b9232'

Caution

This did not work when specifying msys details. I got an error about file hash not being equal though that was not the case 😦

Alternative installation steps

This section is based on the following links:

Environment variables

  1. Assuming you plan to install msys to D:\msys64 and ghcup.exe to D:\Apps\ghcup\bin, set the following environment variables first:

    Env Variable Value Notes
    GHCUP_INSTALL_BASE_PREFIX D:\Apps Defaults to $HOME
    CABAL_DIR D:\Apps\cabal If set, all cabal-install content files will be stored as subdirectories of this directory, including the configuration file if CABAL_CONFIG is unset. See here.
    CABAL_CONFIG %USERPROFILE%\.config\cabal\config Path for global configuration file.
    GHCUP_MSYS2 D:\msys64 Has to point to the root of an existing MSYS2 installation
    STACK_ROOT D:\sr This is where stack stores downloaded programs and snapshot packages. See here.
    GITHUB_TOKEN GitHub PAT. See GitHub Token for details. Used by stack to authenticate when using GitHub REST API. See here.

Important

You also need to add D:\Apps\ghcup\bin to $Path.

ghcup

msys2

  • Download latest version from https://github.com/msys2/msys2-installer/releases/.

  • Install the self extracting archive to D:\msys64:

    .\msys2-base-x86_64-20230718.sfx.exe -y -oD:\
  • Update msys2:

    ghcup run -m -- pacman --noconfirm -Syuu
    ghcup run -m -- pacman --noconfirm -S --needed curl autoconf mingw-w64-x86_64-pkgconf
    ghcup run -m -- pacman --noconfirm -S ca-certificates

    Also, refer to this.

  • Set up msys2 shell:

    • Run ghcup run -m -- sed -i -e 's/db_home:.*$/db_home: windows/' /etc/nsswitch.conf to make the `$HOME`` in your msys2 shell match the one from windows.
    • Make a desktop shortcut from D:\msys64\msys2_shell.cmd, which will allow you to start a proper msys2 shell: New-Item -ItemType SymbolicLink -Path ~\Desktop\Msys2 -Value D:\msys64\msys2_shell.cmd
    • Run ghcup run -m -- sed -i -e "s/#MSYS2_PATH_TYPE=.*/MSYS2_PATH_TYPE=inherit/" /d/msys64/msys2.ini
    • Run ghcup run -m -- sed -i -e "s/rem set MSYS2_PATH_TYPE=inherit/set MSYS2_PATH_TYPE=inherit/" /d/msys64/msys2_shell.cmd

ghc

  • Install ghc:

    ghcup install ghc --set recommended
  • Edit config files as needed. The ghci.conf file in $AppData\ghc can be used for turning on favorite options (e.g. :set +s), and defining useful macros. ~/.ghci can be used as a startup script. See here for good ideas.

cabal

  • Install: gcup install cabal

  • Edit config file:

    extra-include-dirs: D:\msys64\mingw64\include
    extra-lib-dirs: D:\msys64\mingw64\lib
    -- Would also need install folder if cabal installed in stand-alone folder: D:\cabal\bin
    extra-prog-path: D:\ghcup\bin, D:\msys64\mingw64\bin
    

stack

  • Edit D:/sr/config.yaml3:

    local-bin-path: d:/stack
    local-programs-path: d:/stack
    skip-msys: true
    # https://www.haskell.org/ghcup/install/#vscode-integration
    system-ghc: true
    install-ghc: false
    extra-path:
      - 'D:\msys64\usr\bin'
      - 'D:\msys64\mingw64\bin'
    extra-include-dirs:
      - 'D:\msys64\mingw64\include'
    extra-lib-dirs:
      - 'D:\msys64\mingw64\lib'
  • Run ghcup install stack latest.

  • Make sure that the value of local-bin-path (if not set, value is ~\AppData\Roaming\local\bin) is in $PATH as that is where stack install installs generated binaries (source).

  • In $STACK_ROOT\global-project\stack.yaml, specify resolver corresponding to the version of GHC you installed. This info can be obtained from https://www.stackage.org e.g. for GHC 9.4.8, this should be:

    resolver: lts-21.22
  • In Windows, GDB can be installed to debug an executable with ghcup run -m -- pacman -S gdb.

Checks:

  1. Output of stack path --stack-root should match $STACK_ROOT.

  2. Output of stack path --local-bin should be in $PATH

  3. Sanity checks:

    where.exe stack
    stack path
    stack exec -- which ghc
    stack exec sh

Haskell Language Server

Miscellaneous

  • Install following apps:

    winget install --id VideoLAN.VLC
    winget install --id ImageMagick.ImageMagick
    winget install --id Mp3tag.Mp3tag
    winget install --id Citrix.Workspace
    winget install --id Postman.Postman
    winget install --id chrisant996.Clink
    winget install --id 7zip.7zip
    
    winget install --id Graphviz.Graphviz -l 'D:\Apps\Graphviz'
    winget install --id Kitware.CMake -l 'D:\Apps\CMake'
    
    winget install --id WinSCP.WinSCP -l 'D:\Apps\WinSCP\'
    winget install Microsoft.Sysinternals.ProcessExplorer
  • Add installation folders to $Path:

    $path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine')
    $path += ';C:\Program Files\7-Zip;D:\Apps\Graphviz;D:\Apps\CMake;D:\Apps\WinSCP'
    [System.Environment]::SetEnvironmentVariable('Path', $path, 'Machine')

Footnotes

  1. Whichever value you use will be set by the script as $GHCUP_INSTALL_BASE_PREFIX.

  2. The online documentation says location is ~/.ghcup/config.yaml which is not the case.

  3. If you execute a stack command before your config file is set up correctly, it will attempt to download GHC, msys2 which is not what we want 😲

    For more details, see here and here.

About

Notes and scripts to setup new Windows machine

License:MIT License


Languages

Language:PowerShell 100.0%