-
Notifications
You must be signed in to change notification settings - Fork 721
/
haskell.nix
182 lines (171 loc) · 7.53 KB
/
haskell.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
############################################################################
# Builds Haskell packages with Haskell.nix
############################################################################
{ pkgs
, lib
, stdenv
, haskell-nix
, buildPackages
# GHC attribute name
, compiler
# Enable profiling
, profiling ? false
# Link with -eventlog
, eventlog ? false
# Enable asserts for given packages
, assertedPackages ? []
# Version info, to be passed when not building from a git work tree
, gitrev ? null
, libsodium ? pkgs.libsodium
}:
let
src = haskell-nix.haskellLib.cleanGit {
name = "cardano-node-src";
src = ../.;
};
# It is important this matches in both calls to cabalProject or `cabal configure`
# will run twice.
cabalProjectLocal = ''
allow-newer: terminfo:base
'';
projectPackages = lib.attrNames (haskell-nix.haskellLib.selectProjectPackages
(haskell-nix.cabalProject {
inherit src cabalProjectLocal;
compiler-nix-name = compiler;
}));
# This creates the Haskell package set.
# https://input-output-hk.github.io/haskell.nix/user-guide/projects/
pkgSet = haskell-nix.cabalProject ({
inherit src cabalProjectLocal;
compiler-nix-name = compiler;
modules = [
# Allow reinstallation of Win32
({ pkgs, ... }: lib.mkIf pkgs.stdenv.hostPlatform.isWindows {
nonReinstallablePkgs =
[ "rts" "ghc-heap" "ghc-prim" "integer-gmp" "integer-simple" "base"
"deepseq" "array" "ghc-boot-th" "pretty" "template-haskell"
# ghcjs custom packages
"ghcjs-prim" "ghcjs-th"
"ghc-boot"
"ghc" "array" "binary" "bytestring" "containers"
"filepath" "ghc-boot" "ghc-compact" "ghc-prim"
# "ghci" "haskeline"
"hpc"
"mtl" "parsec" "text" "transformers"
"xhtml"
# "stm" "terminfo"
];
})
{
# Needed for the CLI tests.
# Coreutils because we need 'paste'.
packages.cardano-cli.components.tests.cardano-cli-test.build-tools =
lib.mkForce [buildPackages.jq buildPackages.coreutils buildPackages.shellcheck];
packages.cardano-cli.components.tests.cardano-cli-golden.build-tools =
lib.mkForce [buildPackages.jq buildPackages.coreutils buildPackages.shellcheck];
}
{
# make sure that libsodium DLLs are available for windows binaries:
packages = lib.genAttrs projectPackages (name: {
postInstall = lib.optionalString stdenv.hostPlatform.isWindows ''
if [ -d $out/bin ]; then
${setLibSodium}
fi
'';
});
}
{
# Stamp executables with the git revision and add shell completion
packages = lib.genAttrs ["cardano-node" "cardano-cli"] (name: {
components.exes.${name}.postInstall = ''
${lib.optionalString stdenv.hostPlatform.isWindows setLibSodium}
${setGitRev}
'' + lib.optionalString (!stdenv.hostPlatform.isWindows) ''
BASH_COMPLETIONS=$out/share/bash-completion/completions
ZSH_COMPLETIONS=$out/share/zsh/site-functions
mkdir -p $BASH_COMPLETIONS $ZSH_COMPLETIONS
$out/bin/${name} --bash-completion-script ${name} > $BASH_COMPLETIONS/${name}
$out/bin/${name} --zsh-completion-script ${name} > $ZSH_COMPLETIONS/_${name}
'';
});
}
({ pkgs, config, ... }: {
# Packages we wish to ignore version bounds of.
# This is similar to jailbreakCabal, however it
# does not require any messing with cabal files.
packages.katip.doExactConfig = true;
# split data output for ekg to reduce closure size
packages.ekg.components.library.enableSeparateDataOutput = true;
# cardano-cli-test depends on cardano-cli
packages.cardano-cli.preCheck = "export CARDANO_CLI=${config.hsPkgs.cardano-cli.components.exes.cardano-cli}/bin/cardano-cli${pkgs.stdenv.hostPlatform.extensions.executable}";
packages.cardano-node-chairman.components.tests.chairman-tests.build-tools =
lib.mkForce [
config.hsPkgs.cardano-node.components.exes.cardano-node
config.hsPkgs.cardano-cli.components.exes.cardano-cli
config.hsPkgs.cardano-node-chairman.components.exes.cardano-node-chairman];
# cardano-node-chairman depends on cardano-node and cardano-cli
packages.cardano-node-chairman.preCheck = "
export CARDANO_CLI=${config.hsPkgs.cardano-cli.components.exes.cardano-cli}/bin/cardano-cli${pkgs.stdenv.hostPlatform.extensions.executable}
export CARDANO_NODE=${config.hsPkgs.cardano-node.components.exes.cardano-node}/bin/cardano-node${pkgs.stdenv.hostPlatform.extensions.executable}
export CARDANO_NODE_CHAIRMAN=${config.hsPkgs.cardano-node-chairman.components.exes.cardano-node-chairman}/bin/cardano-node-chairman${pkgs.stdenv.hostPlatform.extensions.executable}
export CARDANO_NODE_SRC=${src}
";
})
{
packages = lib.genAttrs projectPackages
(name: { configureFlags = [ "--ghc-option=-Werror" ]; });
}
(lib.optionalAttrs eventlog {
packages = lib.genAttrs ["cardano-node"]
(name: { configureFlags = [ "--ghc-option=-eventlog" ]; });
})
(lib.optionalAttrs profiling {
enableLibraryProfiling = true;
packages.cardano-node.components.exes.cardano-node.enableExecutableProfiling = true;
})
{
packages = lib.genAttrs assertedPackages
(name: { flags.asserts = true; });
}
({ pkgs, ... }: lib.mkIf pkgs.stdenv.hostPlatform.isLinux {
# systemd can't be statically linked
packages.cardano-config.flags.systemd = !pkgs.stdenv.hostPlatform.isMusl;
packages.cardano-node.flags.systemd = !pkgs.stdenv.hostPlatform.isMusl;
})
# Musl libc fully static build
(lib.optionalAttrs stdenv.hostPlatform.isMusl (let
# Module options which adds GHC flags and libraries for a fully static build
fullyStaticOptions = {
enableShared = false;
enableStatic = true;
};
in
{
packages = lib.genAttrs projectPackages (name: fullyStaticOptions);
# Haddock not working and not needed for cross builds
doHaddock = false;
}
))
({ pkgs, ... }: lib.mkIf (pkgs.stdenv.hostPlatform != pkgs.stdenv.buildPlatform) {
# Remove hsc2hs build-tool dependencies (suitable version will be available as part of the ghc derivation)
packages.Win32.components.library.build-tools = lib.mkForce [];
packages.terminal-size.components.library.build-tools = lib.mkForce [];
packages.network.components.library.build-tools = lib.mkForce [];
})
];
# TODO add flags to packages (like cs-ledger) so we can turn off tests that will
# not build for windows on a per package bases (rather than using --disable-tests).
# configureArgs = lib.optionalString stdenv.hostPlatform.isWindows "--disable-tests";
});
# setGitRev is a postInstall script to stamp executables with
# version info. It uses the "gitrev" argument, if set. Otherwise,
# the revision is sourced from the local git work tree.
setGitRev = ''${haskellBuildUtils}/bin/set-git-rev "${gitrev'}" $out/bin/*'';
# package with libsodium:
setLibSodium = "ln -s ${libsodium}/bin/libsodium-23.dll $out/bin/libsodium-23.dll";
gitrev' = if (gitrev == null)
then buildPackages.commonLib.commitIdFromGitRepoOrZero ../.git
else gitrev;
haskellBuildUtils = buildPackages.haskellBuildUtils.package;
in
pkgSet