on hkm/haskell-nix-tools help sign in
haskell.nix/ci-lib.nix
45 lines 2.3 kB history raw
1let
2 # Generic nixpkgs, use *only* for lib functions that are stable across versions
3 pkgs = import (import ./nixpkgs/default.nix).nixpkgs-default {};
4 lib = pkgs.lib;
5in rec {
6 inherit (import ./dimension.nix) dimension;
8 # A filter for removing packages that aren't supported on the current platform
9 # according to 'meta.platforms'.
10 platformFilterGeneric = pkgs: system:
11 # This needs to use the correct nixpkgs version so all the systems line up
12 let lib = pkgs.lib;
13 platform = lib.systems.elaborate { inherit system; };
14 # Can't just default to [] for platforms, since no meta.platforms
15 # means "all platforms" not "no platforms"
16 in drv : if drv ? meta && drv.meta ? platforms then
17 lib.any (lib.meta.platformMatch platform) drv.meta.platforms
18 else true;
20 # Hydra doesn't like these attributes hanging around in "jobsets": it thinks they're jobs!
21 stripAttrsForHydra = filterAttrsOnlyRecursive (n: _: n != "recurseForDerivations" && n != "dimension");
23 # Keep derivations and attrsets with 'recurseForDerivations'. This ensures that we match the
24 # derivations that Hercules will see, and prevents Hydra from trying to pick up all sorts of bad stuff
25 # (like attrsets that contain themselves!).
26 filterDerivations = filterAttrsOnlyRecursive (n: attrs: lib.isDerivation attrs || attrs.recurseForDerivations or false);
28 # A version of 'filterAttrsRecursive' that doesn't recurse into derivations. This prevents us from going into an infinite
29 # loop with the 'out' attribute on derivations.
30 # TODO: Surely this shouldn't be necessary. I think normal 'filterAttrsRecursive' will effectively cause infinite loops
31 # if you keep derivations and your predicate forces the value of the attribute, as this then triggers a loop on the
32 # 'out' attribute. Weird.
33 # To make this function faster, unwanted attributes are mapped to {} instead of being
34 # removed. This keeps the function lazy and avoids unwanted evaluation of sibling
35 # derivations.
36 filterAttrsOnlyRecursive = pred: set:
37 lib.mapAttrs (name: v:
38 if pred name v
39 then
40 if builtins.isAttrs v
41 && !lib.isDerivation v
42 then filterAttrsOnlyRecursive pred v
43 else v
44 else {}) set;