1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 fetchpatch2,
7 cython_0,
8 zfs,
9}:
10
11buildPythonPackage rec {
12 pname = "py-libzfs";
13 version = "24.04.0";
14 format = "setuptools";
15
16 src = fetchFromGitHub {
17 owner = "truenas";
18 repo = "py-libzfs";
19 rev = "TS-${version}";
20 hash = "sha256-Uiu0RNE06++iNWUNcKpbZvreT2D7/EqHlFZJXKe3F4A=";
21 };
22
23 patches = [
24 (fetchpatch2 {
25 url = "https://github.com/truenas/py-libzfs/commit/b5ffe1f1d6097df6e2f5cc6dd3c968872ec60804.patch";
26 hash = "sha256-6r5hQ/o7c4vq4Tfh0l1WbeK3AuPvi+1wzkwkIn1qEes=";
27 })
28 # Upstream has open PR. Debian uses the patch.
29 # https://github.com/truenas/py-libzfs/pull/277
30 (fetchpatch2 {
31 url = "https://salsa.debian.org/python-team/packages/py-libzfs/-/raw/debian/0.0+git20240510.5ae7d5e-1/debian/patches/fix-compilation-on-gcc-14.patch";
32 hash = "sha256-KLxRx2k1LQGtmzMqJe9b84ApOnIXn8ZeBZun5BAxEjc=";
33 })
34 ];
35
36 build-system = [ cython_0 ];
37 buildInputs = [ zfs ];
38
39 # Passing CFLAGS in configureFlags does not work, see https://github.com/truenas/py-libzfs/issues/107
40 postPatch = lib.optionalString stdenv.hostPlatform.isLinux ''
41 substituteInPlace configure \
42 --replace-fail \
43 'CFLAGS="-DCYTHON_FALLTHROUGH"' \
44 'CFLAGS="-DCYTHON_FALLTHROUGH -I${zfs.dev}/include/libzfs -I${zfs.dev}/include/libspl"' \
45 --replace-fail 'zof=false' 'zof=true'
46 '';
47
48 pythonImportsCheck = [ "libzfs" ];
49
50 meta = with lib; {
51 description = "Python libzfs bindings";
52 homepage = "https://github.com/truenas/py-libzfs";
53 license = licenses.bsd2;
54 maintainers = with maintainers; [ chuangzhu ];
55 # The project also supports macOS (OpenZFS on OSX, O3X), FreeBSD and OpenSolaris
56 # I don't have a machine to test out, thus only packaged for Linux
57 platforms = platforms.linux;
58 };
59}