Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created June 29, 2019 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightybyte/ddbd649f0c45461667ebc32f7fb0a736 to your computer and use it in GitHub Desktop.
Save mightybyte/ddbd649f0c45461667ebc32f7fb0a736 to your computer and use it in GitHub Desktop.
A default.nix template for nixifying Haskell projects
{ compiler ? "ghc844"
, rev ? "497e6f1705107a7d60e400e3b6dd6df5ca8bcdba"
, sha256 ? "1gwdxpx5ix3k6j5q3704xchw4cfzmmr2sd6gsqmsln9yrmjzg9p4"
, pkgs ?
import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256; }) {
config.allowBroken = false;
config.allowUnfree = true;
}
}:
let gitignore = pkgs.callPackage (pkgs.fetchFromGitHub {
owner = "siers";
repo = "nix-gitignore";
rev = "4f2d85f2f1aa4c6bff2d9fcfd3caad443f35476e";
sha256 = "1vzfi3i3fpl8wqs1yq95jzdi6cpaby80n8xwnwa8h2jvcw3j7kdz";
}) {};
in
pkgs.haskell.packages.${compiler}.developPackage {
name = builtins.baseNameOf ./.;
root = gitignore.gitignoreSource [".git" "README.md"] ./.;
overrides = self: super: with pkgs.haskell.lib;
# Working on getting this function upstreamed into nixpkgs.
# (See https://github.com/NixOS/nixpkgs/pull/52848 for status)
# This actually gets things directly from hackage and doesn't
# depend on the state of nixpkgs. Allows you to have fewer
# fetchFromGitHub overrides.
let callHackageDirect = {pkg, ver, sha256}@args:
let pkgver = "${pkg}-${ver}";
in self.callCabal2nix pkg (pkgs.fetchzip {
url = "http://hackage.haskell.org/package/${pkgver}/${pkgver}.tar.gz";
inherit sha256;
}) {};
in {
# Don't run a package's test suite
# foo = dontCheck super.foo;
#
# Don't enforce package's version constraints
# bar = doJailbreak super.bar;
#
# Get a specific hackage version straight from hackage. Unlike the above
# callHackage approach, this will always succeed if the version is on
# hackage. The downside is that you have to specify the hash manually.
# aeson = callHackageDirect {
# pkg = "aeson";
# ver = "1.4.2.0";
# sha256 = "0qcczw3l596knj9s4ha07wjspd9wkva0jv4734sv3z3vdad5piqh";
# };
#
# To discover more functions that can be used to modify haskell
# packages, run "nix-repl", type "pkgs.haskell.lib.", then hit
# <TAB> to get a tab-completed list of functions.
};
source-overrides = {
# Use a specific hackage version using callHackage. Only works if the
# version you want is in the version of all-cabal-hashes that you have.
# bytestring = "0.10.8.1";
#
# Use a particular commit from github
# parsec = pkgs.fetchFromGitHub
# { owner = "hvr";
# repo = "parsec";
# rev = "c22d391c046ef075a6c771d05c612505ec2cd0c3";
# sha256 = "0phar79fky4yzv4hq28py18i4iw779gp5n327xx76mrj7yj87id3";
# };
};
modifier = drv: pkgs.haskell.lib.overrideCabal drv (attrs: {
buildTools = (attrs.buildTools or []) ++ [
pkgs.haskell.packages.${compiler}.cabal-install
pkgs.haskell.packages.${compiler}.ghcid
];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment