2019-05-23 08:13:04 +03:00
|
|
|
{ pkgs ? import nixpkgs nixpkgsArgs
|
2019-03-22 02:43:20 +03:00
|
|
|
# Use a pinned nixpkgs rather than the one on NIX_PATH
|
|
|
|
, nixpkgs ? ./nixpkgs
|
2019-05-23 08:13:04 +03:00
|
|
|
# Provide args to the nixpkgs instantiation.
|
|
|
|
, nixpkgsArgs ? {}
|
2019-02-13 08:08:49 +03:00
|
|
|
# You can provide different pins for hackage.nix and stackage.nix if required.
|
|
|
|
# It's also possible to override these sources with NIX_PATH.
|
|
|
|
, hackageSourceJSON ? ./hackage-src.json
|
|
|
|
, stackageSourceJSON ? ./stackage-src.json
|
2019-02-05 06:50:34 +03:00
|
|
|
}:
|
|
|
|
|
2018-11-19 07:57:08 +03:00
|
|
|
let
|
|
|
|
# pkg-def's may reference boot packages, but those
|
|
|
|
# are not guaranteed to be available on hackage, as
|
|
|
|
# it is a manual process. They might eventually show
|
|
|
|
# up much later on hackage; but are not installable
|
|
|
|
# anyway. Therefore we just strip them out of the
|
|
|
|
# pkg-def's packages.
|
2019-03-18 16:20:33 +03:00
|
|
|
#
|
|
|
|
# Note: these will need to be provided by alternative
|
|
|
|
# means outside of hackage.
|
|
|
|
boot-pkgs = [ "rts" "ghc" "ghc-boot-th" "ghc-boot" "ghci"
|
2019-01-18 09:40:05 +03:00
|
|
|
"ghc-heap" # since ghc 8.6.
|
2019-08-02 16:42:22 +03:00
|
|
|
"iserv" "libiserv" "iserv-proxy"
|
2019-01-18 09:40:05 +03:00
|
|
|
];
|
2018-11-19 07:57:08 +03:00
|
|
|
strip-pkg-def = pkgs: pkg-def: hackage: with pkgs.lib;
|
|
|
|
mapAttrs (k: v: if k == "packages"
|
|
|
|
then filterAttrs (k: _: !(builtins.elem k boot-pkgs)) v
|
|
|
|
else v)
|
|
|
|
(pkg-def hackage);
|
2019-02-05 06:50:34 +03:00
|
|
|
|
2019-01-18 05:48:22 +03:00
|
|
|
# ghc hackage patches.
|
|
|
|
# these are patches that turn hackage packages into the same as the ones
|
|
|
|
# ghc ships with the supposedly same version. See GHC Track Issue: 16199
|
|
|
|
ghcHackagePatches = import ./patches;
|
|
|
|
|
2019-02-05 05:57:15 +03:00
|
|
|
compat = import ./lib/compat.nix;
|
2019-01-25 12:58:53 +03:00
|
|
|
|
2019-02-05 06:50:34 +03:00
|
|
|
# Utility function for downloading a pinned git repo, that can be
|
|
|
|
# overridden with NIX_PATH.
|
|
|
|
fetchExternal = import ./lib/fetch-external.nix;
|
|
|
|
|
2019-05-22 06:14:12 +03:00
|
|
|
# Function for cleaning haskell source directories pulled from iohk-nix
|
|
|
|
cleanSourceHaskell = pkgs.callPackage ./lib/clean-source-haskell.nix {};
|
|
|
|
|
2019-02-05 06:50:34 +03:00
|
|
|
# All packages from Hackage as Nix expressions
|
2019-06-02 00:21:21 +03:00
|
|
|
hackageSrc = fetchExternal {
|
2019-02-05 06:50:34 +03:00
|
|
|
name = "hackage-exprs-source";
|
2019-02-13 08:08:49 +03:00
|
|
|
specJSON = hackageSourceJSON;
|
2019-02-05 06:50:34 +03:00
|
|
|
override = "hackage";
|
2019-06-02 00:21:21 +03:00
|
|
|
};
|
|
|
|
hackage = import hackageSrc;
|
2019-02-05 06:50:34 +03:00
|
|
|
|
2019-06-08 10:21:02 +03:00
|
|
|
# Contains the hashes of the cabal 01-index.tar.gz for given
|
|
|
|
# index states. Starting from April 1st 2019.
|
|
|
|
indexStateHashesPath = hackageSrc + "/index-state-hashes.nix";
|
|
|
|
|
2019-02-05 06:50:34 +03:00
|
|
|
# The set of all Stackage snapshots
|
2019-06-02 00:21:21 +03:00
|
|
|
stackageSrc = fetchExternal {
|
2019-02-05 06:50:34 +03:00
|
|
|
name = "stackage-snapshot-source";
|
2019-02-13 08:08:49 +03:00
|
|
|
specJSON = stackageSourceJSON;
|
2019-02-05 06:50:34 +03:00
|
|
|
override = "stackage";
|
2019-06-02 00:21:21 +03:00
|
|
|
};
|
|
|
|
stackage = import stackageSrc;
|
2019-02-05 06:50:34 +03:00
|
|
|
|
2019-07-13 17:13:15 +03:00
|
|
|
packages = pkgs: self: (rec {
|
|
|
|
inherit pkgs; # Make pkgs available (it is the underlying nixpkgs)
|
|
|
|
|
|
|
|
# Packages built to run on the build platform, not the host platform
|
|
|
|
buildPackages = pkgs.buildPackages.lib.makeScope pkgs.buildPackages.newScope
|
|
|
|
(packages pkgs.buildPackages);
|
|
|
|
|
2019-02-05 06:50:34 +03:00
|
|
|
# Utility functions for working with the component builder.
|
|
|
|
haskellLib = let hl = import ./lib { inherit (pkgs) lib; haskellLib = hl; }; in hl;
|
2019-01-25 12:58:53 +03:00
|
|
|
|
2019-02-05 06:50:34 +03:00
|
|
|
# Create a Haskell package set based on a cabal build plan (plan-to-nix)
|
|
|
|
# and Nix expressions representing cabal packages (cabal-to-nix).
|
|
|
|
mkPkgSet =
|
|
|
|
{ pkg-def # Base package set. Either from stackage (via stack-to-nix) or from a cabal projects plan file (via plan-to-nix)
|
2019-03-15 06:10:57 +03:00
|
|
|
, pkg-def-extras ? [] # Additional packages to augment the Base package set `pkg-def` with.
|
2019-02-05 06:50:34 +03:00
|
|
|
, modules ? []
|
|
|
|
}@args:
|
2019-01-25 12:58:53 +03:00
|
|
|
|
2019-02-05 06:50:34 +03:00
|
|
|
import ./package-set.nix (args // {
|
|
|
|
inherit hackage pkgs;
|
|
|
|
pkg-def = strip-pkg-def pkgs pkg-def;
|
|
|
|
});
|
|
|
|
|
|
|
|
# Create a Haskell package set based on a Stack configuration.
|
|
|
|
mkStackPkgSet =
|
|
|
|
{ stack-pkgs # Path to the output of stack-to-nix
|
2019-03-15 06:10:57 +03:00
|
|
|
, pkg-def-extras ? []
|
2019-02-05 06:50:34 +03:00
|
|
|
, modules ? []
|
|
|
|
}@args:
|
|
|
|
|
|
|
|
let
|
|
|
|
# The Stackage release referenced in the stack config
|
2019-07-04 03:09:02 +03:00
|
|
|
pkg-def = stackage.${stack-pkgs.resolver} or (throw ''
|
|
|
|
This version of stackage.nix does not know about the Stackage resolver ${stack-pkgs.resolver}.
|
|
|
|
You may need to update haskell.nix to one that includes a newer stackage.nix.
|
|
|
|
'');
|
2019-02-05 06:50:34 +03:00
|
|
|
# The compiler referenced in the stack config
|
2019-03-15 06:10:57 +03:00
|
|
|
compiler = (stack-pkgs.extras hackage).compiler or (pkg-def hackage).compiler;
|
2019-05-10 08:44:10 +03:00
|
|
|
patchesModule = ghcHackagePatches.${compiler.nix-name} or {};
|
2019-02-05 06:50:34 +03:00
|
|
|
in self.mkPkgSet {
|
|
|
|
inherit pkg-def;
|
2019-03-15 06:10:57 +03:00
|
|
|
pkg-def-extras = [ stack-pkgs.extras ] ++ pkg-def-extras;
|
2019-07-16 10:14:57 +03:00
|
|
|
# set doExactConfig = true. The stackage set should be consistent
|
|
|
|
# and we should trust stackage here!
|
2019-10-11 07:19:31 +03:00
|
|
|
modules = [ { doExactConfig = true; } patchesModule ] ++ stack-pkgs.modules or [] ++ modules;
|
2019-02-05 06:50:34 +03:00
|
|
|
};
|
|
|
|
|
2019-02-15 10:40:14 +03:00
|
|
|
# Create a Haskell package set based on a Cabal configuration.
|
|
|
|
mkCabalProjectPkgSet =
|
|
|
|
{ plan-pkgs # Path to the output of plan-to-nix
|
2019-03-15 06:10:57 +03:00
|
|
|
, pkg-def-extras ? []
|
2019-02-15 10:40:14 +03:00
|
|
|
, modules ? []
|
|
|
|
}@args:
|
|
|
|
|
|
|
|
let
|
|
|
|
pkg-def = plan-pkgs.pkgs;
|
|
|
|
# The compiler referenced in the stack config
|
2019-03-15 06:10:57 +03:00
|
|
|
compiler = (plan-pkgs.extras hackage).compiler or (pkg-def hackage).compiler;
|
2019-07-04 03:09:02 +03:00
|
|
|
patchesModule = ghcHackagePatches.${compiler.nix-name} or {};
|
2019-02-15 10:40:14 +03:00
|
|
|
in self.mkPkgSet {
|
|
|
|
inherit pkg-def;
|
2019-03-15 06:10:57 +03:00
|
|
|
pkg-def-extras = [ plan-pkgs.extras ] ++ pkg-def-extras;
|
2019-07-16 10:14:57 +03:00
|
|
|
# set doExactConfig = true, as we trust cabals resolution for
|
|
|
|
# the plan.
|
2019-10-11 07:19:31 +03:00
|
|
|
modules = [ { doExactConfig = true; } patchesModule ] ++ plan-pkgs.modules or [] ++ modules;
|
2019-02-15 10:40:14 +03:00
|
|
|
};
|
|
|
|
|
2019-05-27 11:05:42 +03:00
|
|
|
# Package sets for all stackage snapshots.
|
|
|
|
snapshots = self.callPackage ./snapshots.nix {};
|
|
|
|
# Pick a recent LTS snapshot to be our "default" package set.
|
2019-07-02 11:25:40 +03:00
|
|
|
haskellPackages = self.snapshots."lts-13.26";
|
2019-05-27 11:05:42 +03:00
|
|
|
|
2019-02-08 03:17:10 +03:00
|
|
|
# Programs for generating Nix expressions from Cabal and Stack
|
2019-07-13 17:13:15 +03:00
|
|
|
# files. This version of nix-tools may be cross compiled.
|
|
|
|
# We probably never want to actually cross compile nix-tools on
|
|
|
|
# it's own.
|
|
|
|
nix-tools-cross-compiled = pkgs.callPackage ./nix-tools {
|
2019-05-30 08:13:18 +03:00
|
|
|
inherit fetchExternal cleanSourceHaskell;
|
2019-07-13 17:13:15 +03:00
|
|
|
hpack = pkgs.haskell.lib.justStaticExecutables
|
|
|
|
(pkgs.haskellPackages.hpack);
|
2019-05-30 08:13:18 +03:00
|
|
|
inherit (self) mkCabalProjectPkgSet;
|
|
|
|
};
|
2019-07-13 17:13:15 +03:00
|
|
|
# While `nix-tools-cross-compiled` may be cross compiled,
|
|
|
|
# getting it from `buildPackages` we should get
|
|
|
|
# nix-tools suitable for running on the build system.
|
|
|
|
nix-tools = buildPackages.nix-tools-cross-compiled;
|
|
|
|
# TODO perhaps there is a cleaner way to get a suitable nix-tools.
|
2019-02-08 03:17:10 +03:00
|
|
|
|
2019-02-05 06:50:34 +03:00
|
|
|
# Snapshots of Hackage and Stackage, converted to Nix expressions,
|
|
|
|
# regularly updated.
|
2019-06-08 10:21:02 +03:00
|
|
|
inherit hackageSrc stackageSrc;
|
2019-02-05 06:50:34 +03:00
|
|
|
inherit hackage stackage;
|
2019-06-08 10:21:02 +03:00
|
|
|
inherit indexStateHashesPath;
|
2019-02-08 03:45:02 +03:00
|
|
|
|
2019-05-18 17:00:28 +03:00
|
|
|
# Make this handy overridable fetch function available.
|
|
|
|
inherit fetchExternal;
|
|
|
|
|
2019-05-22 06:14:12 +03:00
|
|
|
# Function for cleaning haskell source diretories.
|
|
|
|
inherit cleanSourceHaskell;
|
|
|
|
|
2019-05-21 15:05:03 +03:00
|
|
|
# Produce a fixed output derivation from a moving target (hackage index tarball)
|
|
|
|
hackageTarball = { index-state, sha256 }:
|
2019-05-23 08:13:04 +03:00
|
|
|
assert sha256 != null;
|
|
|
|
pkgs.fetchurl {
|
|
|
|
name = "01-index.tar.gz-at-${builtins.replaceStrings [":"] [""] index-state}";
|
|
|
|
url = "https://hackage.haskell.org/01-index.tar.gz";
|
|
|
|
downloadToTemp = true;
|
|
|
|
postFetch = "${self.nix-tools}/bin/truncate-index -o $out -i $downloadedFile -s ${index-state}";
|
|
|
|
|
2019-05-21 15:05:03 +03:00
|
|
|
outputHashAlgo = "sha256";
|
|
|
|
outputHash = sha256;
|
2019-05-23 08:13:04 +03:00
|
|
|
};
|
2019-05-21 15:05:03 +03:00
|
|
|
|
|
|
|
mkLocalHackageRepo = import ./mk-local-hackage-repo { inherit (self) hackageTarball; inherit pkgs; };
|
|
|
|
|
2019-08-26 13:27:47 +03:00
|
|
|
dotCabal = { index-state, sha256, cabal-install ? pkgs.cabal-install }@args:
|
|
|
|
pkgs.runCommand "dot-cabal-at-${builtins.replaceStrings [":"] [""] index-state}" { nativeBuildInputs = [ cabal-install ]; } ''
|
2019-05-21 15:05:03 +03:00
|
|
|
mkdir -p $out/.cabal
|
|
|
|
cat <<EOF > $out/.cabal/config
|
|
|
|
repository cached
|
2019-08-26 13:27:47 +03:00
|
|
|
url: file:${self.mkLocalHackageRepo
|
|
|
|
(builtins.removeAttrs args ["cabal-install"])}
|
2019-05-21 15:05:03 +03:00
|
|
|
secure: True
|
|
|
|
root-keys:
|
|
|
|
key-threshold: 0
|
|
|
|
EOF
|
|
|
|
mkdir -p $out/.cabal/packages/cached
|
|
|
|
HOME=$out cabal new-update cached
|
|
|
|
'';
|
|
|
|
|
2019-06-08 10:21:02 +03:00
|
|
|
update-index-state-hashes = self.callPackage ./scripts/update-index-state-hashes.nix {};
|
2019-05-21 15:05:03 +03:00
|
|
|
|
2019-07-13 17:13:15 +03:00
|
|
|
# Function to call stackToNix
|
|
|
|
callStackToNix = import ./lib/call-stack-to-nix.nix {
|
|
|
|
pkgs = buildPackages.pkgs;
|
|
|
|
inherit (buildPackages.pkgs) runCommand;
|
|
|
|
inherit (buildPackages) nix-tools;
|
|
|
|
};
|
|
|
|
|
2019-05-18 17:00:28 +03:00
|
|
|
# Takes a haskell src directory runs cabal new-configure and plan-to-nix.
|
|
|
|
# Resulting nix files are added to nix-plan subdirectory.
|
2019-07-13 17:13:15 +03:00
|
|
|
callCabalProjectToNix = import ./lib/call-cabal-project-to-nix.nix {
|
2019-06-08 10:21:02 +03:00
|
|
|
index-state-hashes = import indexStateHashesPath;
|
2019-08-26 13:27:47 +03:00
|
|
|
inherit (buildPackages) dotCabal haskellLib;
|
|
|
|
pkgs = buildPackages.pkgs;
|
2019-07-13 17:13:15 +03:00
|
|
|
inherit (buildPackages.pkgs.haskellPackages) hpack;
|
|
|
|
inherit (buildPackages.pkgs) runCommand cabal-install ghc symlinkJoin cacert;
|
|
|
|
inherit (buildPackages) nix-tools;
|
2019-05-18 17:00:28 +03:00
|
|
|
};
|
2019-06-02 00:21:21 +03:00
|
|
|
|
2019-08-26 13:27:47 +03:00
|
|
|
# Loads a plan and filters the package directories using cleanSourceWith
|
|
|
|
importAndFilterProject = import ./lib/import-and-filter-project.nix {
|
|
|
|
inherit pkgs haskellLib;
|
|
|
|
};
|
|
|
|
|
2019-06-02 00:21:21 +03:00
|
|
|
# References to the unpacked sources, for caching in a Hydra jobset.
|
|
|
|
source-pins = self.callPackage ./lib/make-source-pins.nix {
|
|
|
|
sources = [ hackageSrc stackageSrc pkgs.path ];
|
|
|
|
};
|
2019-07-15 15:47:02 +03:00
|
|
|
|
|
|
|
# Build a specific package (name, version) against a given index-stage
|
|
|
|
# from hackage. This is useful if you want to build an executable from
|
|
|
|
# a given package.
|
|
|
|
# NB: If no explicit index-state is provided the most recent one from
|
|
|
|
# the index-state-hashes is used. This guarantees reproducability wrt
|
|
|
|
# to the haskell.nix revision. If reproducability beyond haskell.nix
|
|
|
|
# is required, a specific index-state should be provided!
|
|
|
|
hackage-package =
|
|
|
|
{ name
|
|
|
|
, version
|
|
|
|
, index-state ? builtins.trace "Using latest index state!" pkgs.lib.last (builtins.attrNames (import indexStateHashesPath))
|
|
|
|
}:
|
|
|
|
let tarball = pkgs.fetchurl {
|
|
|
|
url = "mirror://hackage/${name}-${version}.tar.gz";
|
|
|
|
inherit (hackage.${name}.${version}) sha256; };
|
|
|
|
in let src = buildPackages.pkgs.runCommand "${name}-${version}-src" { } ''
|
|
|
|
tmp=$(mktemp -d)
|
|
|
|
cd $tmp
|
|
|
|
tar xzf ${tarball}
|
|
|
|
mv "${name}-${version}" $out
|
|
|
|
'';
|
2019-08-26 13:27:47 +03:00
|
|
|
in let plan-pkgs = (callCabalProjectToNix { inherit src; index-state = builtins.trace "Using index-state: ${index-state}" index-state; }).pkgs;
|
2019-07-15 15:47:02 +03:00
|
|
|
in let pkg-set = mkCabalProjectPkgSet { inherit plan-pkgs; };
|
|
|
|
in pkg-set.config.hsPkgs.${name};
|
2019-02-05 06:50:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
in
|
2019-07-13 17:13:15 +03:00
|
|
|
pkgs.lib.makeScope pkgs.newScope (packages pkgs)
|