forked from IntersectMBO/ouroboros-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
207 lines (184 loc) · 8.05 KB
/
flake.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
{
description = "ouroboros-network";
inputs = {
haskellNix.url = "github:input-output-hk/haskell.nix";
hackageNix = {
url = "github:input-output-hk/hackage.nix";
flake = false;
};
nixpkgs.follows = "haskellNix/nixpkgs-unstable";
iohkNix.url = "github:input-output-hk/iohk-nix";
flake-utils.url = "github:hamishmack/flake-utils/hkm/nested-hydraJobs";
CHaP.url = "github:input-output-hk/cardano-haskell-packages?ref=repo";
CHaP.flake = false;
};
outputs = inputs: let
# all platforms on which we build
supportedSystems = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
# default compiler used on all systems, also provided within the shell
defaultCompiler = "ghc962";
# the compiler used for cross compilation
# alternative compilers only used on Linux
#
# NOTE: cross compilation with `ghc-9.6.2` doesn't currently work
# https://ci.iog.io/build/623082/nixlog/2
crossGHCVersion = "ghc8107";
# alternative compilers
otherCompilers = ["ghc810"];
in
{inherit (inputs);}
// inputs.flake-utils.lib.eachSystem supportedSystems (
system: let
# setup our nixpkgs with the haskell.nix overlays, and the iohk-nix
# overlays...
nixpkgs = import inputs.nixpkgs {
inherit system;
inherit (inputs.haskellNix) config;
overlays = [
# haskellNix.overlay can be configured by later overlays, so need to come before them.
inputs.haskellNix.overlay
];
};
inherit (nixpkgs) lib;
haskellNix = import inputs.haskellNix { };
# see flake `variants` below for alternative compilers
inherit defaultCompiler;
#
# === CABAL PROJECT ===
#
# We use cabalProject' to ensure we don't build the plan for
# all systems.
cabalProject = nixpkgs.haskell-nix.cabalProject' ({config, pkgs, ...}: {
# pkgs - nixpkgs instatiated for cross compilation, so
# stdenv.hostPlatform.isWindows will work as expected
src = ./.;
name = "ouroboros-network";
compiler-nix-name = lib.mkDefault defaultCompiler;
cabalProjectLocal = if pkgs.stdenv.hostPlatform.isWindows
then lib.readFile ./scripts/ci/cabal.project.local.Windows
else lib.readFile ./scripts/ci/cabal.project.local.Linux;
#
# CROSS COMPILATION
# -----------------
# we also want cross compilation to windows on linux (and only with default compiler).
crossPlatforms =
p: lib.optionals (nixpkgs.stdenv.hostPlatform.isLinux && config.compiler-nix-name == crossGHCVersion) [p.mingwW64];
#
# VARIANTS
# --------
# using different compilers
flake.variants = (lib.genAttrs otherCompilers
(compiler-nix-name: { inherit compiler-nix-name; }));
#
# CHaP
# ----
# CHaP input map, so we can find CHaP packages (needs to be more
# recent than the index-state we set!). Can be updated with
#
# nix flake lock --update-input CHaP
#
inputMap = {
"https://input-output-hk.github.io/cardano-haskell-packages" = inputs.CHaP;
};
#
# SHELL
# -----
# tools we want in our shell, from hackage
shell.tools =
{
cabal = "3.10.1.0";
ghcid = "0.8.8";
}
// lib.optionalAttrs (config.compiler-nix-name == defaultCompiler) {
# tools that work only with default compiler
stylish-haskell = "0.14.5.0";
haskell-language-server = "2.0.0.1";
};
# and from nixpkgs or other inputs
shell.nativeBuildInputs = with nixpkgs; [ gh jq ];
# disable Hoogle until someone request it
shell.withHoogle = false;
# Skip cross compilers for the shell
shell.crossPlatforms = _: [];
#
# MODULES
# -------
# package customizations as needed. Where cabal.project is not
# specific enough, or doesn't allow setting these.
modules = [
({pkgs, ...}: {
# pkgs are instatiated for the host platform
packages.ouroboros-network-protocols.components.tests.cddl.build-tools = [ pkgs.cddl pkgs.cbor-diag ];
packages.ouroboros-network-protocols.components.tests.cddl.preCheck = "export HOME=`pwd`";
# don't run checks using Wine when cross compiling
packages.ntp-client.components.tests.test.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.network-mux.components.tests.test.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.ouroboros-network-api.components.tests.test.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.ouroboros-network-protocols.components.tests.test.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.ouroboros-network-framework.components.tests.sim-tests.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.ouroboros-network-framework.components.tests.io-tests.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.ouroboros-network.components.tests.sim-tests.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.ouroboros-network.components.tests.io-tests.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
packages.cardano-client.components.tests.test.doCheck = !pkgs.stdenv.hostPlatform.isWindows;
})
];
});
flake = cabalProject.flake {};
#
# HYDRA JOBS
# ----------
network-docs = nixpkgs.callPackage ./nix/network-docs.nix { };
check-stylish = nixpkgs.callPackage ./nix/check-stylish.nix { };
in
lib.recursiveUpdate flake rec {
# add a required job, that's basically all hydraJobs.
hydraJobs =
nixpkgs.callPackages inputs.iohkNix.utils.ciJobsAggregates
{
ciJobs =
flake.hydraJobs
// {
# This ensure hydra send a status for the required job (even if no change other than commit hash)
revision = nixpkgs.writeText "revision" (inputs.self.rev or "dirty");
inherit network-docs check-stylish;
};
}
# add network-docs & check-stylish to support
# `nix build .\#hydraJobs.x86_64-linux.network-docs` and
# `nix build .\#hydraJobs.x86_64-linux.check-stylis`.
// { inherit network-docs check-stylish; };
# also provide hydraJobs through legacyPackages to allow building without system prefix, e.g.
# `nix build .\#network-mux:lib:network-mux`
# `nix build .\#network-docs`
legacyPackages = { inherit hydraJobs network-docs check-stylish; };
devShells = let
profillingShell = p: {
# `nix develop .#profiling`
profiling = (p.appendModule {modules = [{enableLibraryProfiling = true;}];}).shell;
};
in
profillingShell cabalProject
# Additional shells for every GHC version supported by haskell.nix, eg. `nix develop .#ghc927`
// lib.mapAttrs (compiler-nix-name: _: let
p = cabalProject.appendModule {inherit compiler-nix-name;};
in
p.shell // (profillingShell p))
nixpkgs.haskell-nix.compiler;
# formatter used by nix fmt
formatter = nixpkgs.alejandra;
}
);
nixConfig = {
extra-substituters = [
"https://cache.iog.io"
];
extra-trusted-public-keys = [
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
];
allow-import-from-derivation = true;
};
}