Posted on January 19, 2018
by Dmitry Bushev
Stackage nixpkgs Overlays
Nixpkgs overlay with Stackage LTS releases
Yesterday we published a typeable/nixpkgs-stackage Stackage Nixpkgs overlay plus a typeable/stackage2nix update with overlay support.
Here’s a quick overview of new features.
You can find more about stackage2nix in our previous blog post.
Stackage nixpkgs overlays
Overlay adds Stackage LTS releases to Nixpkgs at the pkgs.haskell.packages.stackage.
You can use these Stackage packages the same way as original Hackage packages maintained by Nix. Below you will find some examples from Nixpkgs Haskell manual with haskellPackages replaced with LTS packages.
List packages in lts-10.0 release:
nix-env -f "<nixpkgs>" -qaP -A haskell.packages.stackage.lts-100
Create a development environment from LTS package set:
nix-shell -p "haskell.packages.stackage.lts-100.ghcWithPackages (pkgs: [pkgs.mtl])"
Override and enable profiling:
with import <nixpkgs> {};
haskell.packages.stackage.lts-100.override {
overrides = self: super: {
mkDerivation = args: super.mkDerivation (args // {
enableLibraryProfiling = true;
});
};
}
Stackage packages are generated with stackage2nix and will be updated on a regular basis.
stackage2nix build support
Overlay also adds build utils at pkgs.haskell.packages.stackage.lib. You can create a build derivation from your project’s stack.yaml using callStackage2nix helper function.
{ nixpkgs ? import <nixpkgs> {} }:
nixpkgs.haskell.packages.stackage.lib.callStackage2nix "my-package" ./. {
inherit nixpkgs;
};
More complex example with pinned Nixpkgs, stackage2nix source pulled from GitHub, and overriding of the resulting Haskell packages:
let
nixpkgs = import ./nixpkgs-pinned.nix {};
inherit (nixpkgs) pkgs lib haskell;
stackage2nixSrc = pkgs.fetchFromGitHub (lib.importJSON ./stackage2nix.json);
stackagePackages = haskell.packages.stackage.lib.callStackage2nix "stackage2nix" stackage2nixSrc { inherit nixpkgs; };
stackage = stackagePackages.override {
overrides = self: super: {
stackage2nix = haskell.lib.disableSharedExecutables super.stackage2nix;
};
};
in
stackage
callStackage2nix function calls stackage2nix on provided path and produces a derivation with Haskell packages for the project. nixpkgs-stackage/examples directory contains full source code of the derivations listed above.
stackage2nix
stackage2nix was also updated to support the Stackage overlay. Now the default is to create a single default.nix with an override of existing Stackage packages. The advantage of this approach is that it does not require additional --all-cabal-hashes and --lts-haskell flags (they are only needed for Stackage generation). But it is required to have typeable/nixpkgs-stackage overlay installed in the system.
To enable the old behavior and generate all packages required for the build, pass --with-stackage or --with-stackage-closure flags.