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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
{ stdenv, autoconf, automake, makeWrapper, pkgconfig, libtool, which, git
, boost, python, pythonPackages, libxml2, zlib
# Optional Dependencies
, snappy ? null, leveldb ? null, yasm ? null, fcgi ? null, expat ? null
, curl ? null, fuse ? null, accelio ? null, libibverbs ? null, librdmacm ? null
, libedit ? null, libatomic_ops ? null, kinetic-cpp-client ? null
, rocksdb ? null, libs3 ? null
# Mallocs
, jemalloc ? null, gperftools ? null
# Crypto Dependencies
, cryptopp ? null
, nss ? null, nspr ? null
# Linux Only Dependencies
, linuxHeaders, libuuid, udev, keyutils, libaio ? null, libxfs ? null
, zfs ? null
# Version specific arguments
, version, src, patches ? [], buildInputs ? []
, ...
}:
# We must have one crypto library
assert cryptopp != null || (nss != null && nspr != null);
with stdenv;
with stdenv.lib;
let
mkFlag = trueStr: falseStr: cond: name: val:
if cond == null then null else
"--${if cond != false then trueStr else falseStr}${name}"
+ "${if val != null && cond != false then "=${val}" else ""}";
mkEnable = mkFlag "enable-" "disable-";
mkWith = mkFlag "with-" "without-";
mkOther = mkFlag "" "" true;
shouldUsePkg = pkg_: let pkg = (builtins.tryEval pkg_).value;
in if lib.any (x: x == system) (pkg.meta.platforms or [])
then pkg else null;
optSnappy = shouldUsePkg snappy;
optLeveldb = shouldUsePkg leveldb;
optYasm = shouldUsePkg yasm;
optFcgi = shouldUsePkg fcgi;
optExpat = shouldUsePkg expat;
optCurl = shouldUsePkg curl;
optFuse = shouldUsePkg fuse;
optAccelio = shouldUsePkg accelio;
optLibibverbs = shouldUsePkg libibverbs;
optLibrdmacm = shouldUsePkg librdmacm;
optLibedit = shouldUsePkg libedit;
optLibatomic_ops = shouldUsePkg libatomic_ops;
optKinetic-cpp-client = shouldUsePkg kinetic-cpp-client;
optRocksdb = shouldUsePkg rocksdb;
optLibs3 = if versionAtLeast version "10.0.0" then null else shouldUsePkg libs3;
optJemalloc = shouldUsePkg jemalloc;
optGperftools = shouldUsePkg gperftools;
optCryptopp = shouldUsePkg cryptopp;
optNss = shouldUsePkg nss;
optNspr = shouldUsePkg nspr;
optLibaio = shouldUsePkg libaio;
optLibxfs = shouldUsePkg libxfs;
optZfs = shouldUsePkg zfs;
hasServer = optSnappy != null && optLeveldb != null;
hasMon = hasServer;
hasMds = hasServer;
hasOsd = hasServer;
hasRadosgw = optFcgi != null && optExpat != null && optCurl != null && optLibedit != null;
hasXio = (stdenv.isLinux || stdenv.isFreeBSD) &&
versionAtLeast version "10.0.0" &&
optAccelio != null && optLibibverbs != null && optLibrdmacm != null;
hasRocksdb = versionAtLeast version "9.0.0" && optRocksdb != null;
# TODO: Reenable when kinetic support is fixed
#hasKinetic = versionAtLeast version "9.0.0" && optKinetic-cpp-client != null;
hasKinetic = false;
# Malloc implementation (can be jemalloc, tcmalloc or null)
malloc = if optJemalloc != null then optJemalloc else optGperftools;
# We prefer nss over cryptopp
cryptoStr = if optNss != null && optNspr != null then "nss" else
if optCryptopp != null then "cryptopp" else "none";
cryptoLibsMap = {
nss = [ optNss optNspr ];
cryptopp = [ optCryptopp ];
none = [ ];
};
wrapArgs = "--set PYTHONPATH \"$(toPythonPath $lib)\""
+ " --prefix PYTHONPATH : \"$(toPythonPath ${python.modules.readline})\""
+ " --prefix PYTHONPATH : \"$(toPythonPath ${pythonPackages.flask})\""
+ " --set PATH \"$out/bin\"";
in
stdenv.mkDerivation {
name="ceph-${version}";
inherit src;
patches = patches ++ [
./0001-Makefile-env-Don-t-force-sbin.patch
];
nativeBuildInputs = [ autoconf automake makeWrapper pkgconfig libtool which git ]
++ optionals (versionAtLeast version "9.0.2") [
pythonPackages.setuptools pythonPackages.argparse
];
buildInputs = buildInputs ++ cryptoLibsMap.${cryptoStr} ++ [
boost python libxml2 optYasm optLibatomic_ops optLibs3 malloc pythonPackages.flask zlib
] ++ optional (versionAtLeast version "9.0.0") [
pythonPackages.sphinx # Used for docs
] ++ optional stdenv.isLinux [
linuxHeaders libuuid udev keyutils optLibaio optLibxfs optZfs
] ++ optional hasServer [
optSnappy optLeveldb
] ++ optional hasRadosgw [
optFcgi optExpat optCurl optFuse optLibedit
] ++ optional hasXio [
optAccelio optLibibverbs optLibrdmacm
] ++ optional hasRocksdb [
optRocksdb
] ++ optional hasKinetic [
optKinetic-cpp-client
];
postPatch = ''
# Fix zfs pkgconfig detection
sed -i 's,\[zfs\],\[libzfs\],g' configure.ac
# Fix seagate kinetic linking
sed -i 's,libcrypto.a,-lcrypto,g' src/os/Makefile.am
'' + optionalString (versionAtLeast version "9.0.0") ''
# Fix gmock
patchShebangs src/gmock
'';
preConfigure = ''
# Ceph expects the arch command to be usable during configure
# for detecting the assembly type
mkdir -p mybin
echo "#${stdenv.shell} -e" >> mybin/arch
echo "uname -m" >> mybin/arch
chmod +x mybin/arch
PATH="$PATH:$(pwd)/mybin"
./autogen.sh
# Fix the python site-packages install directory
sed -i "s,\(PYTHON\(\|_EXEC\)_PREFIX=\).*,\1'$lib',g" configure
# Fix the PYTHONPATH for installing ceph-detect-init to $out
mkdir -p "$(toPythonPath $out)"
export PYTHONPATH="$(toPythonPath $out):$PYTHONPATH"
'';
configureFlags = [
(mkOther "exec_prefix" "\${out}")
(mkOther "sysconfdir" "/etc")
(mkOther "localstatedir" "/var")
(mkOther "libdir" "\${lib}/lib")
(mkOther "includedir" "\${lib}/include")
(mkWith true "rbd" null)
(mkWith true "cephfs" null)
(mkWith hasRadosgw "radosgw" null)
(mkWith true "radosstriper" null)
(mkWith hasServer "mon" null)
(mkWith hasServer "osd" null)
(mkWith hasServer "mds" null)
(mkEnable true "client" null)
(mkEnable hasServer "server" null)
(mkWith (cryptoStr == "cryptopp") "cryptopp" null)
(mkWith (cryptoStr == "nss") "nss" null)
(mkEnable false "root-make-check" null)
(mkWith false "profiler" null)
(mkWith false "debug" null)
(mkEnable false "coverage" null)
(mkWith (optFuse != null) "fuse" null)
(mkWith (malloc == optJemalloc) "jemalloc" null)
(mkWith (malloc == optGperftools) "tcmalloc" null)
(mkEnable false "pgrefdebugging" null)
(mkEnable false "cephfs-java" null)
(mkEnable hasXio "xio" null)
(mkWith (optLibatomic_ops != null) "libatomic-ops" null)
(mkWith true "ocf" null)
(mkWith hasKinetic "kinetic" null)
(mkWith hasRocksdb "librocksdb" null)
(mkWith false "librocksdb-static" null)
] ++ optional stdenv.isLinux [
(mkWith (optLibaio != null) "libaio" null)
(mkWith (optLibxfs != null) "libxfs" null)
(mkWith (optZfs != null) "libzfs" null)
] ++ optional (versionAtLeast version "9.0.1") [
(mkWith false "tcmalloc-minimal" null)
(mkWith false "valgrind" null)
] ++ optional (versionAtLeast version "9.0.2") [
(mkWith true "man-pages" null)
(mkWith true "systemd-libexec-dir" "\${TMPDIR}")
] ++ optional (versionOlder version "10.0.0") [
(mkWith (optLibs3 != null) "system-libs3" null)
(mkWith true "rest-bench" null)
];
preBuild = optionalString (versionAtLeast version "9.0.0") ''
(cd src/gmock; make -j $NIX_BUILD_CORES)
'';
installFlags = [ "sysconfdir=\${out}/etc" ];
outputs = [ "out" "lib" ];
postInstall = ''
# Wrap all of the python scripts
wrapProgram $out/bin/ceph ${wrapArgs}
wrapProgram $out/bin/ceph-brag ${wrapArgs}
wrapProgram $out/bin/ceph-rest-api ${wrapArgs}
wrapProgram $out/sbin/ceph-create-keys ${wrapArgs}
wrapProgram $out/sbin/ceph-disk ${wrapArgs}
# Bring in lib as a native build input
mkdir -p $out/nix-support
echo "$lib" > $out/nix-support/propagated-native-build-inputs
# Fix the python library loading
find $lib/lib -name \*.pyc -or -name \*.pyd -exec rm {} \;
for PY in $(find $lib/lib -name \*.py); do
LIBS="$(sed -n "s/.*find_library('\([^)]*\)').*/\1/p" "$PY")"
# Delete any calls to find_library
sed -i '/find_library/d' "$PY"
# Fix each find_library call
for LIB in $LIBS; do
REALLIB="$lib/lib/lib$LIB.so"
sed -i "s,\(lib$LIB = CDLL(\).*,\1'$REALLIB'),g" "$PY"
done
# Reapply compilation optimizations
NAME=$(basename -s .py "$PY")
rm -f "$PY"{c,o}
pushd "$(dirname $PY)"
python -c "import $NAME"
python -O -c "import $NAME"
popd
test -f "$PY"c
test -f "$PY"o
done
'';
enableParallelBuilding = true;
meta = {
homepage = http://ceph.com/;
description = "Distributed storage system";
license = licenses.lgpl21;
maintainers = with maintainers; [ ak wkennington ];
platforms = with platforms; unix;
};
passthru.version = version;
}
|