forked from input-output-hk/marlowe-cardano
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.nix
93 lines (89 loc) · 3.41 KB
/
ci.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{ supportedSystems
, rootsOnly
, checkMaterialization
, inputs
, source-repo-override
, pkgs
, internal
, evalSystem
, ci-lib
}:
let
inherit (ci-lib) dimension platformFilterGeneric filterAttrsOnlyRecursive filterSystems;
# limit supportedSystems to what the CI can actually build
# currently that is linux and darwin.
systems = filterSystems supportedSystems;
crossSystems = { };
# Collects haskell derivations and builds an attrset:
#
# { library = { ... }
# , tests = { ... }
# , benchmarks = { ... }
# , exes = { ... }
# , checks = { ... }
# }
# Where each attribute contains an attribute set
# with all haskell components of that type
mkHaskellDimension = pkgs: haskellProjects:
let
# retrieve all checks from a Haskell package
collectChecks = _: ps: pkgs.haskell-nix.haskellLib.collectChecks' ps;
# retrieve all components of a Haskell package
collectComponents = type: ps: pkgs.haskell-nix.haskellLib.collectComponents' type ps;
# Given a component type and the retrieve function, retrieve components from haskell packages
select = type: selector: (selector type) haskellProjects;
# { component-type : retriever-fn }
attrs = {
"library" = collectComponents;
"tests" = collectComponents;
"benchmarks" = collectComponents;
"exes" = collectComponents;
"checks" = collectChecks;
};
in
dimension "Haskell component" attrs select;
# Collects all project derivations to build grouped by system:
#
# { linux = { ... }
# , darwin = { ... }
# }
mkSystemDimension = systems:
let
# given a system ("x86_64-linux") return an attrset of derivations to build
_select = _: system: crossSystem:
let
packages = internal.packagesFun { inherit system crossSystem checkMaterialization source-repo-override evalSystem; };
pkgs = packages.pkgs;
marlowe = packages.marlowe;
# Map `crossSystem.config` to a name used in `lib.platforms`
platformString =
if crossSystem == null then system
else crossSystem.config;
isBuildable = platformFilterGeneric pkgs platformString;
filterCross = x:
if crossSystem == null
then x
else {
# When cross compiling only include haskell for now
inherit (x) haskell;
};
in
filterAttrsOnlyRecursive (_: drv: isBuildable drv) ({
# The haskell.nix IFD roots for the Haskell project. We include these so they won't be GCd and will be in the
# cache for users
inherit (marlowe.haskell.project) roots;
} // pkgs.lib.optionalAttrs (system == "x86_64-linux") {
inherit (packages) compose-spec;
} // pkgs.lib.optionalAttrs (!rootsOnly) (filterCross {
# build relevant top level attributes from flake.nix
inherit (packages) tests;
# Build the shell expression to be sure it works on all platforms
shell = import ./dev-shell.nix { inherit packages system; };
# build all haskell packages and tests
haskell = pkgs.recurseIntoAttrs (mkHaskellDimension pkgs marlowe.haskell.projectPackages);
}));
in
dimension "System" systems (name: sys: _select name sys null)
// dimension "Cross System" crossSystems (name: crossSys: _select name "x86_64-linux" crossSys);
in
mkSystemDimension systems