Cheap n cheerful AWS Lambda + Purescript + Nix project

I wanted to mess around with AWS Lambda using Purescript. The combination of NixOS (my main OS), npm, bower, purescript and pulp seemed intimidating so I've documented my work here:

Given a normal Purescript project with a src/Main.purs file like:

We need to include pulp as a dependency in our package.json. Then we can use a Makefile such as:

This will:

  • run npm install
  • run pulp build and produce an index.js file
  • replace the normal invocation with our Lambda hook. This is a horrible hack but it works :/

Now we just need a default.nix to set this up:

We need to reference node, npm, and purescript so that this all works.

Run default.nix:

And we have our compiled Javascript :)

Which we can stick into Lambda:

Easy-ish when you know how!