forked from IntersectMBO/plutus-apps
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ci.nix
121 lines (116 loc) · 5.1 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
{
# 'supportedSystems' restricts the set of systems that we will evaluate for. Useful when you're evaluting
# on a machine with e.g. no way to build the Darwin IFDs you need!
supportedSystems ? [ "x86_64-linux" "x86_64-darwin" ]
, rootsOnly ? false
, sourcesOverride ? { }
, sources ? import ./nix/sources.nix { system = builtins.currentSystem; } // sourcesOverride
, plutus-apps-commit ? { outPath = ./.; rev = "abcdef"; }
}:
let
# pkgs that we only use for lib
libPkgs = (import ./default.nix {
system = "x86_64-linux";
}).pkgs;
inherit (libPkgs.callPackage ./nix/lib/ci.nix { }) dimension platformFilterGeneric filterAttrsOnlyRecursive filterSystems;
# limit supportedSystems to what the CI can actually build
# currently that is linux and darwin.
systems = filterSystems supportedSystems;
crossSystems =
# System doesn't matter as long as we only use lib
{ inherit (libPkgs.lib.systems.examples) mingwW64; };
# 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 = import ./default.nix { inherit system crossSystem; };
pkgs = packages.pkgs;
plutus-apps = packages.plutus-apps;
# Map `crossSystem.config` to a name used in `lib.platforms`
platformString =
if crossSystem == null then system
else if crossSystem.config == "x86_64-w64-mingw32" then "x86_64-windows"
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;
};
forceNewEval = pkgs.runCommand "forceNewEval"
{
text = plutus-apps-commit.rev;
meta.platforms = [ "x86_64-linux" ];
preferLocalBuild = true;
allowSubstitutes = false;
} ''
n=$out
mkdir -p "$(dirname "$n")"
echo -n "$text" > "$n"
'';
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 (plutus-apps.haskell.project) roots;
# forceNewEval will generate at least one new job based off the commit hash.
# This ensures no eval failures because hydra has nothing new to build.
inherit forceNewEval;
} // pkgs.lib.optionalAttrs (!rootsOnly) (filterCross {
# build relevant top level attributes from default.nix
inherit (packages) docs tests plutus-use-cases;
# Build the shell expression to be sure it works on all platforms
#
# The shell should never depend on any of our Haskell packages, which can
# sometimes happen by accident. In practice, everything depends transitively
# on 'plutus-ledger', so this does the job.
# FIXME: this should simply be set on the main shell derivation, but this breaks
# lorri: https://github.com/target/lorri/issues/489. In the mean time, we set it
# only on the CI version, so that we still catch it, but lorri doesn't see it.
shell = (import ./shell.nix { inherit packages; }).overrideAttrs (attrs: attrs // {
disallowedRequisites = [ plutus-apps.haskell.packages.plutus-ledger.components.library ];
});
# build all haskell packages and tests
haskell = pkgs.recurseIntoAttrs (mkHaskellDimension pkgs plutus-apps.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