Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


Build Status

Generate a derivation of Spago dependencies, and use them to install them into the directory structure used by Spago.


For now, simply clone this repo and run npm link. Requires a Node runtime and nix-prefetch-git.

Remember to set npm prefix to something like ~/.npm.


First, generate the spago-packages.nix:

$ spago2nix generate
getting packages..
got 65 packages from Spago list-packages.
# ...
wrote spago-packages.nix

Then install these, optionally with more jobs provided to Nix:

$ spago2nix install -j 100
installing dependencies...
# ...
Wrote install script to .spago2nix/install

Then build the project:

$ spago2nix build
building project...
Wrote build script to .spago2nix/build

When using in your own Nix derivation, the best practice is calling generated scripts from spago-packages.nix:

{ pkgs, stdenv }:

  spagoPkgs = import ./spago-packages.nix { inherit pkgs; };
pkgs.stdenv.mkDerivation rec {
  # < ... >
  buildPhase = 
    ${spagoPkgs.installSpagoStyle} # == spago2nix install
    ${spagoPkgs.buildSpagoStyle}   # == spago2nix build
    ${spagoPkgs.buildFromNixStore} # == spago2nix build
  # < ... >


The workflow of spago2nix is:

  1. Ensure you have Spago installed, a packages.dhall file, and a spago.dhall file.

  2. Run spago2nix generate to generate a new spago-packages.nix file which describes how to build the dependencies.

    You can add spago2nix to the nativeBuildInputs of a mkShell just by importing the spago2nix repository default.nix.

    spago2nix = import (builtins.fetchGit {
      url = "";
      rev = "...";
    }) { inherit pkgs; };
    pkgs.mkShell {
      nativeBuildInputs = with pkgs; [

    Then you'll be able to run spago2nix generate in an impure shell. It will call out to the network to look up hashes for the versions of packages in your spago.dhall.

    The output of spago2nix generate will be a spago-packages.nix file, which contains pure derivations for each package dependency, and which you should check into source control.

  3. In the Nix expression which describes how to build your project, import the generated spago-packages.nix file to get the package dependencies.

    spagoPkgs = import ./spago-packages.nix { inherit pkgs; };
  4. When describing the build steps, either use spago2nix build or spago build --no-install or call to the compiler directly with purs compile "src/**/*.purs" ${spagoPackages.compilePaths}.

    Or do something like this:

    pkgs.stdenv.mkDerivation {
      name = "myderiv";
      buildInputs = [
      nativeBuildInputs = with pkgs; [
      src = ./.;
      unpackPhase = ''
        cp $src/spago.dhall .
        cp $src/packages.dhall .
        cp -r $src/src .
      buildPhase = ''
        build-spago-style "./src/**/*.purs"
      installPhase = ''
        mkdir $out
        mv output $out/

This has a key drawback: steps 2 and 3 really ought to be a single step. Because the spago.dhall file doesn't contain any cryptographic verification of the dependencies, we can't do this as a pure one-step derivation.

Further Reading

Here is a blog post I did about this project:


I get MissingRevOrRepoResult on a package with branch name as a version

Nix gives out the specific constant SHA256 hash for broken Git fetches, so the error is thrown. One of the causes for a broken fetch is wrong checkout revision. Nix supports fetches by commit hash and tags out of the box, but fails at plain branch names.

You can use more verbose reference refs/heads/branch-name at packages.dhall before generating a .nix file. However, the branch name usage is discouraged in Spago (refer to Note here), it's better using a particular commit hash.

I don't know how to compile my project in a derivation

Spago2nix will install and build your project dependencies, but you may still want to use spago to bundle your project. You should not use Spago installation or build commands in a derivation. Use Spago's --no-install and --no-build flags when bundling your project as part of the build phase of a derivation:

pkgs.stdenv.mkDerivation {
  # < ... >
  buildPhase = ''
    ${spago}/bin/spago bundle-app --no-install --no-build --to $out/index.js
  # < ... >

If you attempt to use Spago commands to install or build in your project, you'll see the following error:

spago: security: createProcess: runInteractiveProcess: exec: does not exist (No such file or directory)


Generate a derivation of Spago dependencies, and use them to install them into the directory structure used by Spago.





No releases published


No packages published