blob: 0ccc96ce1885a8316af1a0a27e1c7264446be65b [file] [log] [blame]
Serge Bazanski9848e7e2021-09-10 22:30:56 +00001{ lib, stdenv, runCommand, fetchurl
2, ensureNewerSourcesHook
3, cmake, pkg-config
4, which, git
5, boost
6, libxml2, zlib, lz4
7, openldap, lttng-ust
8, babeltrace, gperf
9, gtest
10, cunit, snappy
11, makeWrapper
12, leveldb, oathToolkit
13, libnl, libcap_ng
14, rdkafka
15, nixosTests
16, cryptsetup
17, sqlite
18, lua
19, icu
20, bzip2
21, doxygen
22, graphviz
23, fmt
24, python3
25
26# Optional Dependencies
27, yasm ? null, fcgi ? null, expat ? null
28, curl ? null, fuse ? null
29, libedit ? null, libatomic_ops ? null
30, libs3 ? null
31
32# Mallocs
33, jemalloc ? null, gperftools ? null
34
35# Crypto Dependencies
36, cryptopp ? null
37, nss ? null, nspr ? null
38
39# Linux Only Dependencies
40, linuxHeaders, util-linux, libuuid, udev, keyutils, rdma-core, rabbitmq-c
41, libaio ? null, libxfs ? null, zfs ? null, liburing ? null
42, ...
43}:
44
45# We must have one crypto library
46assert cryptopp != null || (nss != null && nspr != null);
47
48let
49 shouldUsePkg = pkg: if pkg != null && pkg.meta.available then pkg else null;
50
51 optYasm = shouldUsePkg yasm;
52 optFcgi = shouldUsePkg fcgi;
53 optExpat = shouldUsePkg expat;
54 optCurl = shouldUsePkg curl;
55 optFuse = shouldUsePkg fuse;
56 optLibedit = shouldUsePkg libedit;
57 optLibatomic_ops = shouldUsePkg libatomic_ops;
58 optLibs3 = shouldUsePkg libs3;
59
60 optJemalloc = shouldUsePkg jemalloc;
61 optGperftools = shouldUsePkg gperftools;
62
63 optCryptopp = shouldUsePkg cryptopp;
64 optNss = shouldUsePkg nss;
65 optNspr = shouldUsePkg nspr;
66
67 optLibaio = shouldUsePkg libaio;
68 optLibxfs = shouldUsePkg libxfs;
69 optZfs = shouldUsePkg zfs;
70
71 hasRadosgw = optFcgi != null && optExpat != null && optCurl != null && optLibedit != null;
72
73
74 # Malloc implementation (can be jemalloc, tcmalloc or null)
75 malloc = if optJemalloc != null then optJemalloc else optGperftools;
76
77 # We prefer nss over cryptopp
78 cryptoStr = if optNss != null && optNspr != null then "nss" else
79 if optCryptopp != null then "cryptopp" else "none";
80
81 cryptoLibsMap = {
82 nss = [ optNss optNspr ];
83 cryptopp = [ optCryptopp ];
84 none = [ ];
85 };
86
87 getMeta = description: with lib; {
88 homepage = "https://ceph.com/";
89 inherit description;
90 license = with licenses; [ lgpl21 gpl2 bsd3 mit publicDomain ];
91 maintainers = with maintainers; [ adev ak johanot krav ];
92 platforms = [ "x86_64-linux" "aarch64-linux" ];
93 };
94
95 ceph-common = python.pkgs.buildPythonPackage rec{
96 pname = "ceph-common";
97 inherit src version;
98
99 sourceRoot = "ceph-${version}/src/python-common";
100
101 checkInputs = [ python.pkgs.pytest ];
102 propagatedBuildInputs = with python.pkgs; [ pyyaml six ];
103
104 meta = getMeta "Ceph common module for code shared by manager modules";
105 };
106
107 python = python3.override {
108 packageOverrides = self: super: {
109 # scipy > 1.3 breaks diskprediction_local, leading to mgr hang on startup
110 # Bump once these issues are resolved:
111 # https://tracker.ceph.com/issues/42764 https://tracker.ceph.com/issues/45147
112 scipy = super.scipy.overridePythonAttrs (oldAttrs: rec {
113 version = "1.3.3";
114 src = oldAttrs.src.override {
115 inherit version;
116 sha256 = "02iqb7ws7fw5fd1a83hx705pzrw1imj7z0bphjsl4bfvw254xgv4";
117 };
118 doCheck = false;
119 });
120 };
121 };
122
123 ceph-python-env = python.withPackages (ps: [
124 ps.sphinx
125 ps.flask
126 ps.cython
127 ps.setuptools
128 ps.virtualenv
129 # Libraries needed by the python tools
130 ps.Mako
131 ceph-common
132 ps.cherrypy
133 ps.cmd2
134 ps.colorama
135 ps.python-dateutil
136 ps.jsonpatch
137 ps.pecan
138 ps.prettytable
139 ps.pyopenssl
140 ps.pyjwt
141 ps.webob
142 ps.bcrypt
143 ps.scipy
144 ps.six
145 ps.pyyaml
146 ]);
147 sitePackages = ceph-python-env.python.sitePackages;
148
149 version = "16.2.4";
150 src = fetchurl {
151 url = "http://download.ceph.com/tarballs/ceph-${version}.tar.gz";
152 sha256 = "sha256-J6FVK7feNN8cGO5BSDlfRGACAzchmRUSWR+a4ZgeWy0=";
153 };
154in rec {
155 ceph = stdenv.mkDerivation {
156 pname = "ceph";
157 inherit src version;
158
159 patches = [
160 ./0000-fix-SPDK-build-env.patch
161 ];
162
163 nativeBuildInputs = [
164 cmake
165 pkg-config which git python.pkgs.wrapPython makeWrapper
166 python.pkgs.python # for the toPythonPath function
167 (ensureNewerSourcesHook { year = "1980"; })
168 python
169 fmt
170 # for building docs/man-pages presumably
171 doxygen
172 graphviz
173 ];
174
175 buildInputs = cryptoLibsMap.${cryptoStr} ++ [
176 boost ceph-python-env libxml2 optYasm optLibatomic_ops optLibs3
177 malloc zlib openldap lttng-ust babeltrace gperf gtest cunit
178 snappy lz4 oathToolkit leveldb libnl libcap_ng rdkafka
179 cryptsetup sqlite lua icu bzip2
180 ] ++ lib.optionals stdenv.isLinux [
181 linuxHeaders util-linux libuuid udev keyutils liburing optLibaio optLibxfs optZfs
182 # ceph 14
183 rdma-core rabbitmq-c
184 ] ++ lib.optionals hasRadosgw [
185 optFcgi optExpat optCurl optFuse optLibedit
186 ];
187
188 pythonPath = [ ceph-python-env "${placeholder "out"}/${ceph-python-env.sitePackages}" ];
189
190 preConfigure =''
191 substituteInPlace src/common/module.c --replace "/sbin/modinfo" "modinfo"
192 substituteInPlace src/common/module.c --replace "/sbin/modprobe" "modprobe"
193 substituteInPlace src/common/module.c --replace "/bin/grep" "grep"
194
195 # for pybind/rgw to find internal dep
196 export LD_LIBRARY_PATH="$PWD/build/lib''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
197 # install target needs to be in PYTHONPATH for "*.pth support" check to succeed
198 # set PYTHONPATH, so the build system doesn't silently skip installing ceph-volume and others
199 export PYTHONPATH=${ceph-python-env}/${sitePackages}:$lib/${sitePackages}:$out/${sitePackages}
200 patchShebangs src/script src/spdk src/test src/tools
201 '';
202
203 cmakeFlags = [
204 "-DWITH_SYSTEM_ROCKSDB=OFF" # breaks Bluestore
205 "-DCMAKE_INSTALL_DATADIR=${placeholder "lib"}/lib"
206
207 "-DWITH_SYSTEM_BOOST=ON"
208 "-DWITH_SYSTEM_GTEST=ON"
209 "-DMGR_PYTHON_VERSION=${ceph-python-env.python.pythonVersion}"
210 "-DWITH_SYSTEMD=OFF"
211 "-DWITH_TESTS=OFF"
212 "-DWITH_CEPHFS_SHELL=ON"
213 # TODO breaks with sandbox, tries to download stuff with npm
214 "-DWITH_MGR_DASHBOARD_FRONTEND=OFF"
215 # WITH_XFS has been set default ON from Ceph 16, keeping it optional in nixpkgs for now
216 ''-DWITH_XFS=${if optLibxfs != null then "ON" else "OFF"}''
217 ] ++ lib.optional stdenv.isLinux "-DWITH_SYSTEM_LIBURING=ON";
218
219 postFixup = ''
220 wrapPythonPrograms
221 wrapProgram $out/bin/ceph-mgr --prefix PYTHONPATH ":" "$(toPythonPath ${placeholder "out"}):$(toPythonPath ${ceph-python-env})"
222
223 # Test that ceph-volume exists since the build system has a tendency to
224 # silently drop it with misconfigurations.
225 test -f $out/bin/ceph-volume
226 '';
227
228 outputs = [ "out" "lib" "dev" "doc" "man" ];
229
230 doCheck = false; # uses pip to install things from the internet
231
232 # Takes 7+h to build with 2 cores.
233 requiredSystemFeatures = [ "big-parallel" ];
234
235 meta = getMeta "Distributed storage system";
236
237 passthru.version = version;
238 passthru.tests = { inherit (nixosTests) ceph-single-node ceph-multi-node ceph-single-node-bluestore; };
239 };
240
241 ceph-client = runCommand "ceph-client-${version}" {
242 meta = getMeta "Tools needed to mount Ceph's RADOS Block Devices";
243 } ''
244 mkdir -p $out/{bin,etc,${sitePackages},share/bash-completion/completions}
245 cp -r ${ceph}/bin/{ceph,.ceph-wrapped,rados,rbd,rbdmap} $out/bin
246 cp -r ${ceph}/bin/ceph-{authtool,conf,dencoder,rbdnamer,syn} $out/bin
247 cp -r ${ceph}/bin/rbd-replay* $out/bin
248 cp -r ${ceph}/${sitePackages} $out/${sitePackages}
249 cp -r ${ceph}/etc/bash_completion.d $out/share/bash-completion/completions
250 # wrapPythonPrograms modifies .ceph-wrapped, so lets just update its paths
251 substituteInPlace $out/bin/ceph --replace ${ceph} $out
252 substituteInPlace $out/bin/.ceph-wrapped --replace ${ceph} $out
253 '';
254}