* Remove unused (and broken) test files * Make default.nix expose pinned nixpkgs Also make `nixpkgs/default.nix` just an attribute set of sources. This is simpler, and consistent with what e.g. `niv` does. * Add backwards compatibility shim, and version argument to allow evolution in future * Fix some missed things * Fix and improve quickstart
4.5 KiB
- ⚠️ Please use /ilyakooo0/haskell.nix/src/commit/277c9b4acc06af26c34503d3eac6c50f565a8244/iohk.cachix.org instead of /ilyakooo0/haskell.nix/src/commit/277c9b4acc06af26c34503d3eac6c50f565a8244/nix-tools.cachix.org
- Alternative Haskell Infrastructure for Nixpkgs
⚠️ Please use /ilyakooo0/haskell.nix/src/commit/277c9b4acc06af26c34503d3eac6c50f565a8244/iohk.cachix.org instead of /ilyakooo0/haskell.nix/src/commit/277c9b4acc06af26c34503d3eac6c50f565a8244/nix-tools.cachix.org warning
Alternative Haskell Infrastructure for Nixpkgs
https://badge.buildkite.com/d453edcd29bd2f8f3f3b32c9b7d6777a33773d9671c37a6ccc.svg?branch=master https://img.shields.io/buildkite/c8d5a20d3ff0f440f82adb9190b43c16c91e5e47e8adfa867a/master.svg?label=nightly%20updates
haskell.nix
is an experimental new builder for Haskell packages.
It works by automatically translating your Cabal or Stack project and its dependencies into Nix code. It provides IFD (imports from derviation) functions that can minimize the amount of nix code you need to add.
For the documentation, see https://input-output-hk.github.io/haskell.nix/.
Quickstart
For cabal.project
project add a default.nix
:
let
# Fetch the latest haskell.nix and import its default.nix
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
# haskell.nix provides access to the nixpkgs pins which are used by our CI, hence
# you will be more likely to get cache hits when using these.
# But you can also just use your own, e.g. '<nixpkgs>'
nixpkgsSrc = haskellNix.sources.nixpkgs-1909;
# haskell.nix provides some arguments to be passed to nixpkgs, including some patches
# and also the haskell.nix functionality itself as an overlay.
nixpkgsArgs = haskellNix.nixpkgsArgs;
in
{ pkgs ? import nixpkgsSrc nixpkgsArgs
, haskellCompiler ? "ghc865"
}:
# 'cabalProject' generates a package set based on a cabal.project (and the corresponding .cabal files)
pkgs.haskell-nix.cabalProject {
# 'cleanGit' cleans a source directory based on the files known by git
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
ghc = pkgs.buildPackages.pkgs.haskell-nix.compiler.${haskellCompiler};
}
Note that you'll need to add a comment specifying the expected sha256
output for your source-repository-packages
in your cabal.project
file:
source-repository-package
type: git
location: https://github.com/input-output-hk/iohk-monitoring-framework
subdir: plugins/backend-editor
tag: 4956b32f039579a0e7e4fd10793f65b4c77d9044
--sha256: 03lyb2m4i6p7rpjqarnhsx21nx48fwk6rzsrx15k6274a4bv0pix
For a stack.yaml
project add a default.nix
:
let
haskellNix = import (builtins.fetchTarball https://github.com/input-output-hk/haskell.nix/archive/master.tar.gz) {};
nixpkgsSrc = haskellNix.sources.nixpkgs-1909;
nixpkgsArgs = haskellNix.nixpkgsArgs;
in
{ pkgs ? import nixpkgsSrc nixpkgsArgs
}:
pkgs.haskell-nix.stackProject {
src = pkgs.haskell-nix.haskellLib.cleanGit { src = ./.; };
}
To build the library component of a package in the project run:
nix build -f . your-package-name.components.library
To build an executable:
nix build -f . your-package-name.components.exes.your-exe-name
To open a shell for use with `cabal` run:
nix-shell -A shellFor
cabal new-build your-package-name
cabal new-repl your-package-name:library:your-package-name
Cache
CI pushes to cachix so you can benefit from the cache
if you pin a combination of haskell.nix
and nixpkgs
built by CI.
You'll need to configure the iohk cachix
as a substituter
for nix
and add the public key found at the url to
trusted-public-keys
.
Related repos
The haskell.nix
repository contains the runtime system for building
Haskell packages in Nix. It depends on other repos, which are:
- nix-tools — provides the programs for generating Nix expressions from Haskell projects.
- hackage.nix — the latest contents of the Hackage databases, converted to Nix expressions.
- stackage.nix — all of the Stackage snapshots, converted to Nix expressions.
IRC Channel
Join the #haskell.nix channel on irc.freenode.net to get help or discuss
the development of haskell.nix
and nix-tools
.