1{
2 stdenv,
3 fetchgit,
4 lib,
5 meson,
6 ninja,
7 pkg-config,
8 makeFontsConf,
9 openssl,
10 libdrm,
11 libevent,
12 libyaml,
13 gst_all_1,
14 gtest,
15 graphviz,
16 doxygen,
17 python3,
18 python3Packages,
19 udev,
20 libpisp,
21 withTracing ? lib.meta.availableOn stdenv.hostPlatform lttng-ust,
22 lttng-ust, # withTracing
23 withQcam ? false,
24 qt6, # withQcam
25 libtiff, # withQcam
26}:
27
28stdenv.mkDerivation rec {
29 pname = "libcamera";
30 version = "0.5.1";
31
32 src = fetchgit {
33 url = "https://git.libcamera.org/libcamera/libcamera.git";
34 rev = "v${version}";
35 hash = "sha256-JV5sa/jiqubcenSeYC4jlB/RgGJt3o1HTIyy7U4Ljlg=";
36 };
37
38 outputs = [
39 "out"
40 "dev"
41 ];
42
43 postPatch = ''
44 patchShebangs src/py/ utils/
45 '';
46
47 # libcamera signs the IPA module libraries at install time, but they are then
48 # modified by stripping and RPATH fixup. Therefore, we need to generate the
49 # signatures again ourselves. For reproducibility, we use a static private key.
50 #
51 # If this is not done, libcamera will still try to load them, but it will
52 # isolate them in separate processes, which can cause crashes for IPA modules
53 # that are not designed for this (notably ipa_rpi.so).
54 preBuild = ''
55 ninja src/ipa-priv-key.pem
56 install -D ${./ipa-priv-key.pem} src/ipa-priv-key.pem
57 '';
58
59 postFixup = ''
60 ../src/ipa/ipa-sign-install.sh src/ipa-priv-key.pem $out/lib/libcamera/ipa_*.so
61 '';
62
63 strictDeps = true;
64
65 buildInputs = [
66 # IPA and signing
67 openssl
68
69 # gstreamer integration
70 gst_all_1.gstreamer
71 gst_all_1.gst-plugins-base
72
73 # cam integration
74 libevent
75 libdrm
76
77 # hotplugging
78 udev
79
80 # pycamera
81 python3Packages.pybind11
82
83 # yamlparser
84 libyaml
85
86 gtest
87 ]
88 ++ lib.optionals stdenv.hostPlatform.isAarch [ libpisp ]
89 ++ lib.optionals withTracing [ lttng-ust ]
90 ++ lib.optionals withQcam [
91 libtiff
92 qt6.qtbase
93 qt6.qttools
94 ];
95
96 nativeBuildInputs = [
97 meson
98 ninja
99 pkg-config
100 python3
101 python3Packages.jinja2
102 python3Packages.pyyaml
103 python3Packages.ply
104 python3Packages.sphinx
105 graphviz
106 doxygen
107 openssl
108 ]
109 ++ lib.optional withQcam qt6.wrapQtAppsHook;
110
111 mesonFlags = [
112 "-Dv4l2=true"
113 (lib.mesonEnable "tracing" withTracing)
114 (lib.mesonEnable "qcam" withQcam)
115 "-Dlc-compliance=disabled" # tries unconditionally to download gtest when enabled
116 # Avoid blanket -Werror to evade build failures on less
117 # tested compilers.
118 "-Dwerror=false"
119 # Documentation breaks binary compatibility.
120 # Given that upstream also provides public documentation,
121 # we can disable it here.
122 "-Ddocumentation=disabled"
123 ];
124
125 # Fixes error on a deprecated declaration
126 env.NIX_CFLAGS_COMPILE = "-Wno-error=deprecated-declarations";
127
128 # Silence fontconfig warnings about missing config
129 FONTCONFIG_FILE = makeFontsConf { fontDirectories = [ ]; };
130
131 meta = with lib; {
132 description = "Open source camera stack and framework for Linux, Android, and ChromeOS";
133 homepage = "https://libcamera.org";
134 changelog = "https://git.libcamera.org/libcamera/libcamera.git/tag/?h=${src.rev}";
135 license = licenses.lgpl2Plus;
136 maintainers = with maintainers; [ citadelcore ];
137 platforms = platforms.linux;
138 badPlatforms = [
139 # Mandatory shared libraries.
140 lib.systems.inspect.platformPatterns.isStatic
141 ];
142 };
143}