All Projects → cdepillabout → purescript2nix

cdepillabout / purescript2nix

Licence: BSD-3-Clause license
Tool for easily building PureScript projects with Nix

Programming Languages

Nix
1067 projects
Dhall
116 projects
purescript
368 projects

purescript2nix

This is a Nix function for easily building PureScript projects with Nix.

The advantage of purescript2nix is that your spago.dhall and packages.dhall files act as a single source of truth. When you update dependencies in spago.dhall or the package set in packages.dhall, you don't need to update the Nix expression at all. It automatically picks up changes from these two Dhall files.

Using purescript2nix on a PureScript packages looks like the following. This is how you would build the PureScript package ./example-purescript-package/ with purescript2nix:

purescript2nix {
  pname = "example-purescript-package";
  src = ./example-purescript-package;
}

Installing / Getting purescript2nix

The purescript2nix function lives in this repo, so I would recommend either adding purescript2nix as a flake input and using the provided overlay, or just directly importing the purescript2nix repo and applying ./nix/overlay.nix.

Using the purescript2nix function

Using the purescript2nix function to build your package is as simple as calling it with pname and src arguments. See either the above example, or the example-purescript-package attribute in ./nix/overlay.nix and the example PureScript package.

Building the derivation produced by purescript2nix

Building the derivation produced by purescript2nix is as simple as calling nix-build on it. Here is how you would build the example PureScript package in this repo:

$ nix-build ./nix -A example-purescript-package
...
/nix/store/z3gvwhpnp0rfi65dgxmk1rjycpa4l1ag-example-purescript-package

This produces an output with a single directory output/. output/ contains all the transpiled PureScript code:

$ tree /nix/store/z3gvwhpnp0rfi65dgxmk1rjycpa4l1ag-example-purescript-package
/nix/store/z3gvwhpnp0rfi65dgxmk1rjycpa4l1ag-example-purescript-package
└── output
    ├── cache-db.json
    ├── Control.Alt
    │   ├── externs.cbor
    │   └── index.js
    ├── Control.Alternative
    │   ├── externs.cbor
    │   └── index.js
    ├── Control.Applicative
    │   ├── externs.cbor
    │   └── index.js
    ├── Control.Apply
    │   ├── externs.cbor
    │   ├── foreign.js
...

Caveats

One big problem with purescript2nix is that it requires a package set with hashes. The purescript/package-sets repo does not include hashes for packages in the package set. See #4 for more info.

Also, you might have problem using purescript2nix from flakes. See #1 for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].