Purescript and Nix

I’ve been looking around for examples of how to use Nix with purescript. Getting a dev environment set up is not a problem but putting together a derivation that builds and installs my project is.

  • I tried using yarn since it seemed simple enough (in particular since purescript is broken quite often in nixpkgs-unstable). However, I don’t seem to have a network when building because yarn can’t fetch packages during nix-build.
  • I had a look at yarn2nix, running it to produce a yarn.nix file is easy enough, but actually making us of it is not. At the (outdated) sources the example brings in /home/maarten/code/nixos/yarn2nix, I’m at a complete loss as to what to replace that with. A complete and working example that isn’t tied to a particular person’s computer would help.

Is there a current state-of-the-art setup for developing and building purescript on Nix? Where can I find it?

since purescript is broken quite often in nixpkgs-unstable

I’m quite surprised you find purescript broken in unstable / master. I don’t recall ever being pinged on a GitHub issue about it in the last couple months. It is just a patchelf'd binary, and those tend to be pretty reliable.

Please feel free to open an issue if you ever find problems with it.

As for how to use PureScript with Nix/NixOS, I generally just get nodejs, spago, and purescript from Nixpkgs, then do development mostly normally.

However, if you want to actually build your PureScript project with Nix, that is a little more tricky. There are various projects for building a PureScript codebase with Nix, but I’ve never used any of them.

I suggest that you search on the PureScript discourse, and possibly ask this same question there. I know that there are some PureScripters that use Nix, but I don’t know if any of them read this NixOS Discourse.

Ah, yes apparently I have always picked up purescript from pkgs.haskellPackages and it’s often broken. pkgs.purescript is working (though it seems to be a version behind the latest release on Hackage, but I don’t care about that).

Thanks for the link to the PureScript discourse, I’ll see if I can find some hints on how to build using Nix too.


If you find anything helpful, don’t forget to leave a message here!

I’m sure there are other people that might check here first instead of the PureScript discourse, and would be thankful if you could point them in the right direction.

1 Like

There are two ways mentioned on the PureScript discourse

  • spago2nix - a separate tool creating a spago-packages.nix
  • purs-nix - a pure Nix solution, a flake but apparently also usable with a stable nix

I tried out the former and it was very easy to set up a dev environment with the tool, but the instructions on making a derivation for building and installing are beyond me, so I created a ticket.


The quest continues, now on the PureScript Discourse: Spago2nix, any complete example to look at?

I’m now stuck on bundling the app in the CI environment :disappointed:

1 Like

Now that last part is solved too, by turning off the global cache (not much need in creating a global cache during a CI build anyway, unless it’s shared with other jobs). The full story is now in the post on the PureScript Discourse.