1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 pytestCheckHook,
6 fetchFromGitLab,
7 fetchpatch,
8 replaceVars,
9 bubblewrap,
10 exiftool,
11 ffmpeg,
12 setuptools,
13 wrapGAppsHook3,
14 gdk-pixbuf,
15 gobject-introspection,
16 librsvg,
17 poppler_gi,
18 mutagen,
19 pygobject3,
20 pycairo,
21 dolphinIntegration ? false,
22 kdePackages,
23}:
24
25buildPythonPackage rec {
26 pname = "mat2";
27 version = "0.13.5";
28 pyproject = true;
29
30 src = fetchFromGitLab {
31 domain = "0xacab.org";
32 owner = "jvoisin";
33 repo = "mat2";
34 tag = version;
35 hash = "sha256-ivFgH/88DBucZRaO/OMsLlwJCjv/VQXb6AiKWhZ8XH0=";
36 };
37
38 patches = [
39 (fetchpatch {
40 name = "exiftool-13.25-compat.patch";
41 url = "https://0xacab.org/jvoisin/mat2/-/commit/473903b70e1b269a6110242a9c098a10c18554e2.patch";
42 hash = "sha256-vxxjAFwiTDlcTT3ZlfhOG4rlzBJS+LhLoA++8y2hEok=";
43 })
44 (fetchpatch {
45 name = "fix-test-on-python313.patch";
46 url = "https://0xacab.org/jvoisin/mat2/-/commit/f07344444d6d2f04a1f93e2954f4910b194bee0c.patch";
47 hash = "sha256-y756sKkjGO11A2lrRsXAwWgupOZ00u0cDypvkbsiNbY=";
48 })
49 (fetchpatch {
50 name = "fix-test-on-python312.patch";
51 url = "https://0xacab.org/jvoisin/mat2/-/commit/7a8ea224bc327b8ee929379d577c74968ea1c352.patch";
52 hash = "sha256-pPiYhoql5WhjhLKvd6y3OnvxORSbXIGCsZMc7UH3i1Q=";
53 })
54 # hardcode paths to some binaries
55 (replaceVars ./paths.patch {
56 exiftool = lib.getExe exiftool;
57 ffmpeg = lib.getExe ffmpeg;
58 kdialog = if dolphinIntegration then lib.getExe kdePackages.kdialog else null;
59 # replaced in postPatch
60 mat2 = null;
61 mat2svg = null;
62 })
63 # the executable shouldn't be called .mat2-wrapped
64 ./executable-name.patch
65 # hardcode path to mat2 executable
66 ./tests.patch
67 ]
68 ++ lib.optionals (stdenv.hostPlatform.isLinux) [
69 (replaceVars ./bubblewrap-path.patch {
70 bwrap = lib.getExe bubblewrap;
71 })
72 ];
73
74 postPatch = ''
75 substituteInPlace dolphin/mat2.desktop \
76 --replace "@mat2@" "$out/bin/mat2" \
77 --replace "@mat2svg@" "$out/share/icons/hicolor/scalable/apps/mat2.svg"
78 '';
79
80 build-system = [ setuptools ];
81
82 nativeBuildInputs = [
83 gobject-introspection
84 wrapGAppsHook3
85 ];
86
87 buildInputs = [
88 gdk-pixbuf
89 librsvg
90 poppler_gi
91 ];
92
93 dependencies = [
94 mutagen
95 pygobject3
96 pycairo
97 ];
98
99 postInstall = ''
100 install -Dm 444 data/mat2.svg -t "$out/share/icons/hicolor/scalable/apps"
101 install -Dm 444 doc/mat2.1 -t "$out/share/man/man1"
102 ''
103 + lib.optionalString dolphinIntegration ''
104 install -Dm 444 dolphin/mat2.desktop -t "$out/share/kservices5/ServiceMenus"
105 '';
106
107 nativeCheckInputs = [ pytestCheckHook ];
108
109 meta = with lib; {
110 description = "Handy tool to trash your metadata";
111 homepage = "https://0xacab.org/jvoisin/mat2";
112 changelog = "https://0xacab.org/jvoisin/mat2/-/blob/${version}/CHANGELOG.md";
113 license = licenses.lgpl3Plus;
114 mainProgram = "mat2";
115 maintainers = with maintainers; [ dotlambda ];
116 };
117}