haskell.nix/ci-lib.nix
Hamish Mackenzie 4cac8bd00f
Remove internal deps on default ghc and stackage (#738)
Changes to the interface of haskell.nix (from the changelog.md file):

* Removed `sources.nixpkgs-default`, use `sources.nixpkgs` instead.
* Removed `./nixpkgs` directory, use  `(import ./. {}).sources`
  or `./nix/sources.nix` instead.
* Removes V1 interface for details on how to fix old code see:
    https://github.com/input-output-hk/haskell.nix/issues/709
* Removed defaultCompilerNixName.
* cabalProject, cabalProject', hackage-project and hackage-package
  now require a `compiler-nix-name` argument.
* `haskell-nix.tool` and `.tools` now require a `compiler-nix-name` argument.
  New functions `p.tool` and `p.tools` (where p is a project) do not.
  Like `shellFor { tools = ... }` they will use the compiler nix name
  from the project (including stack projects where it is derived from
  the resolver).
* `haskell-nix.alex` and `haskell-nix.happy` have been removed. Use
  `p.tool "alex" "3.2.5"` or `shellFor { tools = { alex = "3.2.5"; } }`.
* `haskell-nix.nix-tools` -> `haskell-nix.nix-tools.ghc883` (it includes
  the hpack exe now).
* `haskell-nix.cabal-install` -> 
  `p.tool "cabal" "3.2.0.0"` or `shellFor { tools = { cabal = "3.2.0.0"; } }`
* `haskell-nix.haskellNixRoots` -> `haskell-nix.roots ghc883` or `p.roots`

Other changes:

Adds hpack executable to the nix-tools derivations.

Adds a `cabal-hpack` test to make sure `hpack` works with
`cabalProject`.

Reduces the number of calls to `cabalProject` (particularly when
checking materialization), by giving internal tools a per-compiler
attribute.

Uses happy 1.19.12 when building newer ghc versions.

Updates cabal-install 3.2.0.0 to use the source from github that
is compatible with ghc 8.10.1.

Updates the docs for callCabalProjectToNix.

Adds a license mapping to fix a common warning.
2020-07-08 22:54:01 +12:00

46 lines
2.2 KiB
Nix

let
# Generic nixpkgs, use *only* for lib functions that are stable across versions
pkgs = import (import ./nix/sources.nix).nixpkgs {};
lib = pkgs.lib;
in rec {
inherit (import ./dimension.nix) dimension;
# A filter for removing packages that aren't supported on the current platform
# according to 'meta.platforms'.
platformFilterGeneric = pkgs: system:
# This needs to use the correct nixpkgs version so all the systems line up
let lib = pkgs.lib;
platform = lib.systems.elaborate { inherit system; };
# Can't just default to [] for platforms, since no meta.platforms
# means "all platforms" not "no platforms"
in drv : if drv ? meta && drv.meta ? platforms then
lib.any (lib.meta.platformMatch platform) drv.meta.platforms
else true;
# Hydra doesn't like these attributes hanging around in "jobsets": it thinks they're jobs!
stripAttrsForHydra = filterAttrsOnlyRecursive (n: _: n != "recurseForDerivations" && n != "dimension");
# Keep derivations and attrsets with 'recurseForDerivations'. This ensures that we match the
# derivations that Hercules will see, and prevents Hydra from trying to pick up all sorts of bad stuff
# (like attrsets that contain themselves!).
filterDerivations = filterAttrsOnlyRecursive (n: attrs: lib.isDerivation attrs || attrs.recurseForDerivations or false);
# A version of 'filterAttrsRecursive' that doesn't recurse into derivations. This prevents us from going into an infinite
# loop with the 'out' attribute on derivations.
# TODO: Surely this shouldn't be necessary. I think normal 'filterAttrsRecursive' will effectively cause infinite loops
# if you keep derivations and your predicate forces the value of the attribute, as this then triggers a loop on the
# 'out' attribute. Weird.
# To make this function faster, unwanted attributes are mapped to {} instead of being
# removed. This keeps the function lazy and avoids unwanted evaluation of sibling
# derivations.
filterAttrsOnlyRecursive = pred: set:
lib.mapAttrs (name: v:
if pred name v
then
if builtins.isAttrs v
&& !lib.isDerivation v
then filterAttrsOnlyRecursive pred v
else v
else {}) set;
}