1{
2 lib,
3 stdenv,
4 fetchurl,
5 bash-completion,
6 pkg-config,
7 perl,
8 buildPythonBindings ? false,
9 buildOcamlBindings ? false,
10 ocamlPackages,
11 python3,
12 libxml2,
13 fuse,
14 fuse3,
15 gnutls,
16 autoreconfHook,
17}:
18
19lib.throwIf (buildOcamlBindings && !lib.versionAtLeast ocamlPackages.ocaml.version "4.05")
20 "OCaml binding are not available for OCaml < 4.05"
21
22 stdenv.mkDerivation
23 rec {
24 pname = "libnbd";
25 version = "1.22.1";
26
27 src = fetchurl {
28 url = "https://download.libguestfs.org/libnbd/${lib.versions.majorMinor version}-stable/${pname}-${version}.tar.gz";
29 hash = "sha256-9oVJrU2YcXGnKaDf8SoHKGtG7vpH5355/DKIiYrchHI=";
30 };
31
32 nativeBuildInputs = [
33 bash-completion
34 pkg-config
35 perl
36 autoreconfHook
37 ]
38 ++ lib.optionals buildPythonBindings [ python3 ]
39 ++ lib.optionals buildOcamlBindings (
40 with ocamlPackages;
41 [
42 findlib
43 ocaml
44 ]
45 );
46
47 buildInputs = [
48 fuse
49 fuse3
50 gnutls
51 libxml2
52 ];
53
54 postPatch = lib.optionalString buildOcamlBindings ''
55 substituteInPlace ocaml/Makefile.am \
56 --replace-fail '$(DESTDIR)$(OCAMLLIB)' '$(out)/lib/ocaml/${ocamlPackages.ocaml.version}/site-lib'
57 '';
58
59 configureFlags = lib.optionals buildPythonBindings [
60 "--with-python-installdir=${placeholder "out"}/${python3.sitePackages}"
61 ];
62
63 installFlags = [ "bashcompdir=$(out)/share/bash-completion/completions" ];
64
65 postInstall = lib.optionalString buildPythonBindings ''
66 LIBNBD_PYTHON_METADATA='${placeholder "out"}/${python3.sitePackages}/nbd-${version}.dist-info/METADATA'
67 install -Dm644 -T ${./libnbd-metadata} $LIBNBD_PYTHON_METADATA
68 substituteAllInPlace $LIBNBD_PYTHON_METADATA
69 '';
70
71 meta = with lib; {
72 homepage = "https://gitlab.com/nbdkit/libnbd";
73 description = "Network Block Device client library in userspace";
74 longDescription = ''
75 NBD — Network Block Device — is a protocol for accessing Block Devices
76 (hard disks and disk-like things) over a Network. This is the NBD client
77 library in userspace, a simple library for writing NBD clients.
78
79 The key features are:
80 - Synchronous API for ease of use.
81 - Asynchronous API for writing non-blocking, multithreaded clients. You
82 can mix both APIs freely.
83 - High performance.
84 - Minimal dependencies for the basic library.
85 - Well-documented, stable API.
86 - Bindings in several programming languages.
87 - Shell (nbdsh) for command line and scripting.
88 '';
89 license = with licenses; lgpl21Plus;
90 maintainers = with maintainers; [
91 humancalico
92 ];
93 platforms = with platforms; linux;
94 };
95 }
96# TODO: package the 1.6-stable version too
97# TODO: git version needs ocaml
98# TODO: bindings for go