haskell.nix/ci-lib.nix
Hamish Mackenzie d1102d342c
Add pins and materialization for ghc-boot-packages and ghc-extra-packages (#546)
* Include `tests` in path for cross compiled tests

* Add ghc-boot-packages-nix to haskellNixRoots

* Fix naming warnings in tests sources

* Uses a single cleanGit call for all the tests

* Add memoize code for ghc-boot and ghc-extra pkgs

* Memoize ghc-boot and ghc-extra pkgs nix

* Fix release.nix being more strict than ci.nix by updating filterAttrsOnlyRecursive in ci-lib.nix

* Nicer errors when materialized path does not exist

* Updated materialization docs

* Add internalHackageIndexState to set the index-state used within haskell.nix
2020-04-20 13:27:52 +12:00

46 lines
2.2 KiB
Nix

let
# Generic nixpkgs, use *only* for lib functions that are stable across versions
pkgs = import (import ./nixpkgs/default.nix).nixpkgs-default {};
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;
}