MyNixOS website logo
Description

Convert Stack files into Nix build instructions.

stackage2nix

Build Status

stackage2nix converts a Stack file into a Nix Haskell packages set.

Create build derivation from stack.yaml

Generate targets from stack.yaml only

stack exec -- stackage2nix .

Command creates file default.nix which overrides haskell.packages.stackage packages set. You should use typeable/nixpkgs-stackage overlay that adds LTS Stackage packages to Nixpkgs.

Build package with overlay installed:

nix-build -A stackage2nix

Generate Stackage packages for the build

If you don't want to use Stackage overlay, stackage2nix can generate required packages with --with-stackage-closure flag.

stack exec -- stackage2nix \
  --all-cabal-hashes /path/to/commercialhaskell/all-cabal-hashes \
  --lts-haskell /path/to/fpco/lts-haskell \
  --with-stackage-closure \
  ./stack.yaml

To generate Stackage packages, you should supply additional --all-cabal-hashes and --lts-haskell flags that points to commercialhaskell/all-cabal-hashes checked out to hackage branch and fpco/lts-haskell respectively.

stackage2nix wrapper

You can use stackage2nix wrapper from nix directory that adds required flags:

nix-env -i -f ./nix/stackage2nix
stackage2nix --with-stackage-closure ./stack.yaml

This command will produce packages.nix and configuration-packages.nix Stackage packages and its override in default.nix

Generate full Stackage

--with-stackage parameter generates full Stackage LTS in addition to the targets from stack.yaml

nix-env -i -f ./nix/stackage2nix
stackage2nix --with-stackage ./stack.yaml

Generate Stackage from LTS resolver

You can also generate only Stackage packages set from the resolver:

nix-env -i -f ./nix/stackage2nix
stackage2nix --resolver lts-10.0

This command will produce Stackage packages packages.nix, packages config configuration-packages.nix and a Haskell packages set default.nix.

Runtime dependencies

  • nix-env is required to be on PATH by the distribution-nixpkgs dependency
  • nix-prefetch-scripts is required on PATH if you have git dependencies in stack.yaml

Override result derivation

Complex projects may require some extra customization. Snippet override.nix below shows a minimal example of how to apply additional overrides on top of Haskell packages set produced by stackage2nix.

with import <nixpkgs> {};
with haskell.lib;
let haskellPackages = import ./. {};
in haskellPackages.override {
  overrides = self: super: {
    stackage2nix = disableSharedExecutables super.stackage2nix;
  };
}
nix-build -A stackage2nix override.nix

For more complex overrides and detailed information on how to work with Haskell packages in Nix, see Nixpkgs manual User’s Guide to the Haskell Infrastructure

Tests

Integration tests that build stackage2nix form different yaml configs:

STACKAGE_REPO=<path/to/stackage/repo> \
ALL_CABAL_HASHES=<path/to/all-cabal-hashes/repo> \
STACK_FILE=stack-ghc-7103.yaml \
./ci-stackage2nix
Metadata

Version

0.7.2

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows