lol
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 fetchpatch,
6 fetchpatch2,
7 fetchurl,
8 cmake,
9 ninja,
10 ffmpeg-headless,
11 zlib,
12 testers,
13 validatePkgConfig,
14 nix-update-script,
15 withExamples ? true,
16 withTools ? true,
17}:
18
19stdenv.mkDerivation (finalAttrs: {
20 pname = "chromaprint";
21 version = "1.5.1";
22
23 src = fetchFromGitHub {
24 owner = "acoustid";
25 repo = "chromaprint";
26 tag = "v${finalAttrs.version}";
27 hash = "sha256-bFplHaqXYvGbl8E8b/HUNFO4X+B/HPZjGTmuVFPjS3g=";
28 };
29
30 patches = [
31 # Use FFmpeg 5.x
32 # https://github.com/acoustid/chromaprint/pull/120
33 (fetchpatch {
34 url = "https://github.com/acoustid/chromaprint/commit/8ccad6937177b1b92e40ab8f4447ea27bac009a7.patch";
35 hash = "sha256-yO2iWmU9s2p0uJfwIdmk3jZ5HXBIQZ/NyOqG+Y5EHdg=";
36 excludes = [ "package/build.sh" ];
37 })
38 # ffmpeg5 fix for issue #122
39 # https://github.com/acoustid/chromaprint/pull/125
40 (fetchpatch {
41 url = "https://github.com/acoustid/chromaprint/commit/aa67c95b9e486884a6d3ee8b0c91207d8c2b0551.patch";
42 hash = "sha256-dLY8FBzBqJehAofE924ayZK0HA/aKiuFhEFxL7dg6rY=";
43 })
44 # Fix for FFmpeg 7
45 (fetchpatch2 {
46 url = "https://gitlab.archlinux.org/archlinux/packaging/packages/chromaprint/-/raw/74ae4c7faea2114f2d70a57755f714e348476d28/ffmpeg-7.patch";
47 hash = "sha256-io+dzhDNlz+2hWhNfsyePKLQjiUvSzbv10lHVKumTEk=";
48 })
49 ];
50
51 nativeBuildInputs = [
52 cmake
53 ninja
54 validatePkgConfig
55 ];
56
57 buildInputs = [
58 ffmpeg-headless
59 ]
60 ++ lib.optionals stdenv.hostPlatform.isDarwin [
61 zlib
62 ];
63
64 # with trivialautovarinit enabled can produce an empty .pc file
65 hardeningDisable = [ "trivialautovarinit" ];
66
67 cmakeFlags = [
68 (lib.cmakeBool "BUILD_EXAMPLES" withExamples)
69 (lib.cmakeBool "BUILD_TOOLS" withTools)
70 ];
71
72 passthru = {
73 updateScript = nix-update-script { };
74 tests.pkg-config = testers.testMetaPkgConfig finalAttrs.finalPackage;
75 };
76
77 doCheck = true;
78 checkPhase =
79 let
80 exampleAudio = fetchurl {
81 name = "Dvorak_Symphony_9_1.mp3";
82 url = "https://archive.org/download/Dvorak_Symphony_9/01.Adagio-Allegro_Molto.mp3";
83 hash = "sha256-I+Ve3/OpL+3Joc928F8M21LhCH2eQfRtaJVx9mNOLW0=";
84 meta.license = lib.licenses.publicDomain;
85 };
86
87 # sha256 because actual output of fpcalc is quite long
88 expectedHash = "c47ae40e02caf798ff5ab4d91ff00cfdca8f6786c581662436941d3e000c9aac";
89 in
90 ''
91 runHook preCheck
92 tests/all_tests
93 ${lib.optionalString withTools "diff -u <(src/cmd/fpcalc ${exampleAudio} | sha256sum | cut -c-64) <(echo '${expectedHash}')"}
94 runHook postCheck
95 '';
96
97 meta = {
98 changelog = "https://github.com/acoustid/chromaprint/releases/tag/v${finalAttrs.version}";
99 homepage = "https://acoustid.org/chromaprint";
100 description = "AcoustID audio fingerprinting library";
101 license = lib.licenses.lgpl21Plus;
102 platforms = lib.platforms.unix;
103 pkgConfigModules = [ "libchromaprint" ];
104 }
105 // lib.attrsets.optionalAttrs withTools {
106 mainProgram = "fpcalc";
107 };
108})