Skip to content

Instantly share code, notes, and snippets.

@CapsAdmin
Last active January 28, 2018 19:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CapsAdmin/ee77100c499ec9a55730e999759a166b to your computer and use it in GitHub Desktop.
Save CapsAdmin/ee77100c499ec9a55730e999759a166b to your computer and use it in GitHub Desktop.

Building nix on msys2

I don't have windows:

You can try this for free by using Virtual Box and a non activated Windows

  1. Install virtual box
  2. Create a virtual machine and call it Windows 10 or something. The wizard should auto complete most of the information
  3. Download the Windows 10 iso from Microsoft, mount it in your virtual machine and install it
  4. Install some text editor to edit files. I would recommend https://notepad-plus-plus.org/

The only limitations of not activating Windows that I'm aware of is that you get a transparent watermark and are unable to change your desktop background.

In the setup you can also choose to install the N/EuropeanUnion version to reduce bloat. So Skype, OneDrive, and some other things are not preinstalled.

I have windows:

Setup msys2

Install msys2 by getting the one click installer and just follow the wizard.

Enable real symlinks

Msys2 has some limitations with symlinks unless the shell is run as admin. You can build Nix without fixing this but make install will fail when creating links of the built .exe files to usr/bin.

To fix this you have to edit C:\msys64\msys2_shell.cmd and uncomment and change the line:

rem set MSYS=winsymlinks:nativestrict

to

set MSYS=winsymlinks

Which is located nearly at the top.

Once you've done this you need to run MSYS2 MinGW 64-bit as admin. The installer should add some shortcuts to the start menu in the recently added section. Open the start menu, right click MSYS2 MinGW 64-bit click on More > Open file location. An explorer window should popup. In there right click the shortcut and click run as administrator

Sources:

Install the required packages

pacman -Syu #update msys2 first if you haven't

pacman -Syu --noconfirm autoconf 
pacman -Syu --noconfirm automake 
pacman -Syu --noconfirm tar 
pacman -Syu --noconfirm gcc 
pacman -Syu --noconfirm make 
pacman -Syu --noconfirm patch 
pacman -Syu --noconfirm perl 
pacman -Syu --noconfirm pkg-config 
pacman -Syu --noconfirm libbz2-devel 
pacman -Syu --noconfirm mingw-w64-i686-libressl 
pacman -Syu --noconfirm liblzma-devel
pacman -Syu --noconfirm libcurl-devel 
pacman -Syu --noconfirm libunistring-devel #this one is not checked for in ./configure
pacman -Syu --noconfirm bison #this one is not checked for in ./configure
#see workarounds for the rest (2018 January 28th)
#pacman -Syu perl-DBI
#cpan WWW::Curl # requires DBI.
#cpan DBD::SQLite # requires DBI.

Package workarounds (2018 January 28th)

pacman -Syu perl-DBI

msys2/MSYS2-packages#1119

perl-DBI will successfully install but perl -e 'use DBI' will fail because DBI.dll depends on perl 5.22 while the current version of perl in msys is at 5.24

To workaround this issue just rebuild the DBI package.

mkdir tempworkaround && cd tempworkaround
wget https://github.com/Alexpux/MSYS2-packages/raw/master/perl-DBI/PKGBUILD
wget https://github.com/Alexpux/MSYS2-packages/raw/master/perl-DBI/DBI-1.627.patch
makepkg
pacman -U perl-DBI-1.634-1-x86_64.pkg.tar.xz

cpan WWW::Curl

curl/curl#839

Something is messed up with the defines when building this library. A workaround is to #define CURL_STRICTER=0

mkdir tempworkaround && cd tempworkaround
wget https://github.com/szbalint/WWW--Curl/archive/master.tar.gz
tar -xf master.tar.gz && WWW--Curl-master
perl Makefile.PL
make CCFLAGS=-DCURL_STRICTER=0 #the workaround
make install

Building Nix

wget https://github.com/NixOS/nix/archive/master.tar.gz
tar -xzvf master.tar.gz && cd nix-master
./bootstrap

#https://github.com/NixOS/nix/issues/506
./configure --disable-doc-gen

#in mysys2, echo $OS returns Windows_NT 
#and the Nix makefiles has many workarounds for Cygwin 
make OS=CYGWIN
make install OS=CYGWIN

Make issues

relocation truncated to fit: R_X86_64_PC32 against undefined symbol TLS init function for nix::curActivity'

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59364

This seems to only affect x64 builds. I did this which seemed to work but is probably wrong. (please suggest a better way)

  • in src/libutil∕logging.cc:88 remove thread_local
  • in src/libutil∕logging.hh:80 remove thread_local
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment