Get started with purescript on nixos

On nixos, installing the tools for purescript is a little different from how it is described in the Purescript by Example book (purchase link).  Until a few days ago I had to rely on a local copy of bower for each project, and before that there was a problem with the purescript haskell package.  However, that’s all been fixed, so getting purescript working on nixos is pretty straightforward now (2015-01-11) if you are on the unstable channel.

You can check what channel you’re on like this:

[bburdette@nixosthe1:~]$ sudo nix-channel --list
[sudo] password for bburdette:

If you aren’t on unstable, you can switch like this:

[bburdette@nixosthe1:~]$ sudo nix-channel --add nixos

Then you’ll want to do the usual updating, to 1) update the package registry, 2) rebuild packages according to the new stuff, and 3) (optional) upgrade any packages you’ve installed with “nix-env -i “.

1> sudo nix-channel –update
2> sudo nixos-rebuild switch
3> nix-env –upgrade

With that out of the way you can install purescript and friends:

> nix-env -i nodejs
> nix-env -iA nixos.pkgs.haskellPackages.purescript
> nix-env -i bin-grunt-cli
> nix-env -i bin-gulp
> nix-env -i bin-bower

I used -iA for purescript because various guesses for the regular name didn’t work for me.  You don’t need gulp for the book examples, but some projects on github use gulp.

You can install them all with one command like so:
> nix-env -iA nixos.pkgs.nodejs nixos.pkgs.haskellPackages.purescript nixos.pkgs.nodePackages.grunt-cli nixos.pkgs.nodePackages.gulp nixos.pkgs.nodePackages.bower

Great! Now you can clone the purescript code repo for the Purescript by Example book.

> git clone

Now let’s build and run the chapter 2 example, with these commands:

> cd purescript-book/chapter2
> npm update
> bower update
> grunt
> node dist/Main.js

The output from these commands looks like this:

[bburdette@nixosthe1:~/purescript-book/chapter2]$ npm update
grunt-purescript@0.5.3 node_modules/grunt-purescript
grunt@0.4.5 node_modules/grunt
├── which@1.0.8
├── dateformat@1.0.2-1.2.3
├── eventemitter2@0.4.14
├── getobject@0.1.0
├── rimraf@2.2.8
├── colors@0.6.2
├── async@0.1.22
├── grunt-legacy-util@0.2.0
├── hooker@0.2.3
├── exit@0.1.2
├── nopt@1.0.10 (abbrev@1.0.5)
├── lodash@0.9.2
├── coffee-script@1.3.3
├── underscore.string@2.2.1
├── iconv-lite@0.2.11
├── minimatch@0.2.14 (sigmund@1.0.0, lru-cache@2.5.0)
├── glob@3.1.21 (inherits@1.0.0, graceful-fs@1.2.3)
├── findup-sync@0.1.3 (glob@3.2.11, lodash@2.4.1)
├── grunt-legacy-log@0.1.1 (underscore.string@2.3.3, lodash@2.4.1)
└── js-yaml@2.0.5 (esprima@1.0.4, argparse@0.1.16)

[bburdette@nixosthe1:~/purescript-book/chapter2]$ bower update
bower purescript-math#0.1.0 cached git://
bower purescript-math#0.1.0 validate 0.1.0 against git://
bower purescript-math#0.1.0 install purescript-math#0.1.0

purescript-math#0.1.0 bower_components/purescript-math

[bburdette@nixosthe1:~/purescript-book/chapter2]$ grunt
Running "psc:all" (psc) task
>> Created file dist/Main.js.

Running "dotPsci:0" (dotPsci) task
>> Created .psci file

Done, without errors.

[bburdette@nixosthe1:~/purescript-book/chapter2]$ node dist/Main.js