Skip to content

Instantly share code, notes, and snippets.

@j-mueller
Last active February 6, 2018 12:59
Show Gist options
  • Save j-mueller/49cc07586f4ef964fdd80eeaf98582d5 to your computer and use it in GitHub Desktop.
Save j-mueller/49cc07586f4ef964fdd80eeaf98582d5 to your computer and use it in GitHub Desktop.
GHCJS with Nix on WINDOWS

1. Prerequisites

2. Start a nix shell with docker

  • Create a new folder and open a terminal inside it
  • Start a docker container with interactive shell, forwarding port 6400 for GHCJSi:
docker run -p 6400:6400 -it -v <local path>:/project -w /project lnl7/nix:2018-01-13 bash

3. Create project and nix files

  • Run nix-env -i cabal-install cabal2nix ghc
    • Installs cabal, cabal2nix and ghc using nix
  • Run cabal update && cabal init
    • Initialise cabal and create a new project
  • Run cabal2nix . > default.nix
    • This creates a nix derivation with dependencies based on the .cabal file
    • Run this again when the dependencies in the .cabal file have changed

3. Create project and nix files

  • Create a release.nix with the following content:
 let
   bootstrap = import <nixpkgs> { };
 
   nixpkgs = builtins.fromJSON (builtins.readFile ./nixpkgs.json);
 
   src = bootstrap.fetchFromGitHub {
     owner = "NixOS";
     repo  = "nixpkgs";
     inherit (nixpkgs) rev sha256;
   };
 
   pkgs = import src { };
 in
 {
   project = pkgs.haskell.packages.ghcjsHEAD.callPackage ./default.nix { };
 }
  • This pins the version of 'nixpkgs' to the one specified in nixpkgs.json (next slide)

3. Create project and nix files

..and a nixpkgs.json with

  {
    "url": "https://github.com/NixOS/nixpkgs.git",
    "rev": "fcc8cae88d5429ae2693b03e870dfc4fe6a1c6bf",
    "date": "2018-01-20T15:47:59-05:00",
    "sha256": "0bpzwiyam6a68wp8bizlkdsazdfq2xyfwa7wjaydf8ps64avr23p",
    "fetchSubmodules": true
  }
  • We need to use fcc8cae or newer to get a working build of GHCJS
  • This file was created with nix-prefetch-git

4. Open a shell with GHCJS

  • nix-shell --attr project.env release.nix
    • Brings all packages into scope
  • cabal new-configure -O0 --ghcjs
  • cabal new-build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment