A brief guide to deploying Haskell apps with NixOps

I've moved to developing my Haskell stuff in a NixOS VM. In this post I'll sketch out a development/deployment workflow.

Aside: Why Nix? NixOS provides a declarative and safe way to interact with Linux. Nix is great for Haskell because:

  • binaries = fast builds
  • reliable package sets = less errors

Development

Install cabal2nix (nix-env -iA nixos.cabal2nix or similar). This will help you generate Nix code from your cabal packages.

Create a shell.nix file for local development:

You can then configure and run repls and tests like:

Deploying

The nix-copy-closure command provides a quick way to get some software on another NixOS machine. It may work for you if your needs are simple. NixOps is a more complicated tool for describing infra and deploying code.

Saluton is an interactive repo for learning EC2 deployments using NixOps. Here's an overview:

  • You need a ~/.ec2-keys file in the format: ID KEY NAME
  • Build a project.nix without the --shell switch: cabal2nix . > project.nix
  • Create a default.nix to call it:

In another directory (perhaps ../) write your physical network description and your services description. The former describes AWS attributes like instance type, the latter can be used to boot your app via systemd (for example).

Now you can create the configuration:

And fire at will!

When you make changes, simply:

And deploy again! Ping me if I can help out!