Recently I've been attempting to contribute to arraymancer - a n-dimensional tensor (ndarray) library written in Nim. While trying to make Windows tests work, I decided to try building Nim from source on Windows.

Nim + Docker + Windows

Building from source on Windows is actually detailed relatively well on the windows install page of the official language site: https://nim-lang.org/install_windows.html

Rather than using the zip and exe provided there, I thought I would try writing a Dockerfile to build the language in a more reproducible way: here you can see the Dockerfile source. I did find that building Nim from source differed slightly from the instructions on the README of the language though. After using chocolately to install git, 7zip, and mingw, it boils down to just a few steps in powershell:

# Clone the main repo
git clone https://github.com/nim-lang/Nim.git
cd Nim

# Clone the csources
git clone --depth 1 https://github.com/nim-lang/csources.git
cd csources;

# Run the build batch script
.\build64.bat
cd ..

# Bootstrap the koch helper
bin\nim.exe c koch
.\koch.exe boot -d:release
.\koch.exe tools

# Download the additional dlls to the bin folder
cd bin
Invoke-WebRequest -UseBasicParsing https://nim-lang.org/download/dlls.zip -O dlls.zip

# Unzip them
7z x dlls.zip
rm dlls.zip

# Use the Set-Path.ps1 script to add Nim & Nimble bin dirs to the PATH
.\Set-Path.ps1 -NewLocation "C:\Nim\bin"; `
.\Set-Path.ps1 -NewLocation "$env:USERPROFILE\.nimble\bin";

In the last few lines, the .\Set-Path.ps1 file can be found here - which I took from Peter Hahndorf's blog here. It's actually surprising how many answers and variance there is on trying to add a variable to the PATH variable on windows.

Automating with Appveyor

Thereafter, I wanted to automate the process of pushing a docker image to Docker Hub - and after reading Stefan Scherer's blog post on deploying images using Appveyor - I only had to make one small change:

deploy_script:
  - ps: echo $env:DOCKER_PASS | docker login -u="$env:DOCKER_USER" --password-stdin

Without using the --password-stdin docker will raise an error which fails the build. Additionally, you need to prefix the line with ps: to ensure you can access the $env: variables.

Now you can see the image published here: https://hub.docker.com/r/metasyn/nim-servercore/

And you can use it by simply pulling:

docker pull metasyn/nim-servercore