nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitLab,
5 rustPlatform,
6 meson,
7 ninja,
8 python3,
9 pkg-config,
10 rustc,
11 cargo,
12 cargo-c,
13 lld,
14 nasm,
15 cmake,
16 gstreamer,
17 gst-plugins-base,
18 gst-plugins-bad,
19 gtk4,
20 cairo,
21 csound,
22 dav1d,
23 libsodium,
24 libwebp,
25 openssl,
26 pango,
27 gst-plugins-good,
28 nix-update-script,
29 # specifies a limited subset of plugins to build (the default `null` means all plugins supported on the stdenv platform)
30 plugins ? null,
31 withGtkPlugins ? true,
32 # Checks meson.is_cross_build(), so even canExecute isn't enough.
33 enableDocumentation ? stdenv.hostPlatform == stdenv.buildPlatform && plugins == null,
34 hotdoc,
35 apple-sdk_gstreamer,
36}:
37
38let
39 # populated from meson_options.txt (manually for now, but that might change in the future)
40 validPlugins = {
41 # audio
42 audiofx = [ ];
43 claxon = [ ];
44 csound = [ csound ];
45 lewton = [ ];
46 spotify = [ ];
47
48 # generic
49 file = [ ];
50 sodium = [ libsodium ];
51 threadshare = [ ];
52
53 # mux
54 flavors = [ ];
55 fmp4 = [ ];
56 mp4 = [ ];
57
58 # net
59 aws = [ openssl ];
60 hlssink3 = [ ];
61 ndi = [ ];
62 onvif = [ pango ];
63 raptorq = [ ];
64 reqwest = [ openssl ];
65 rtp = [ ];
66 webrtc = [
67 gst-plugins-bad
68 openssl
69 ];
70 webrtchttp = [
71 gst-plugins-bad
72 openssl
73 ];
74
75 # text
76 textahead = [ ];
77 json = [ ];
78 regex = [ ];
79 textwrap = [ ];
80
81 # utils
82 fallbackswitch = [ gtk4 ];
83 livesync = [ gtk4 ];
84 togglerecord = [ gtk4 ];
85 tracers = [ ];
86 uriplaylistbin = [ ];
87
88 # video
89 cdg = [ ];
90 closedcaption = [ pango ];
91 dav1d = [ dav1d ];
92 ffv1 = [ ];
93 gif = [ ];
94 gtk4 = [ gtk4 ];
95 hsv = [ ];
96 png = [ ];
97 rav1e = [ ];
98 videofx = [ cairo ];
99 webp = [ libwebp ];
100 };
101
102 selectedPlugins =
103 if plugins != null then
104 lib.unique (lib.sort lib.lessThan plugins)
105 else
106 lib.subtractLists (
107 [
108 "csound" # tests have weird failure on x86, does not currently work on arm or darwin
109 "livesync" # tests have suspicious intermittent failure, see https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/357
110 ]
111 ++ lib.optionals stdenv.hostPlatform.isAarch64 [
112 "raptorq" # pointer alignment failure in tests on aarch64
113 ]
114 ++ lib.optionals stdenv.hostPlatform.isDarwin [
115 "reqwest" # tests hang on darwin
116 "threadshare" # tests cannot bind to localhost on darwin
117 "uriplaylistbin" # thread reqwest-internal-sync-runtime attempred to create a NULL object (in test_cache)
118 "webp" # not supported on darwin (upstream crate issue)
119 ]
120 ++ lib.optionals (!gst-plugins-base.glEnabled || !withGtkPlugins) [
121 # these require gstreamer-gl
122 "gtk4"
123 "livesync"
124 "fallbackswitch"
125 "togglerecord"
126 ]
127 ) (lib.attrNames validPlugins);
128
129 invalidPlugins = lib.subtractLists (lib.attrNames validPlugins) selectedPlugins;
130in
131assert lib.assertMsg (invalidPlugins == [ ])
132 "Invalid gst-plugins-rs plugin${
133 lib.optionalString (lib.length invalidPlugins > 1) "s"
134 }: ${lib.concatStringsSep ", " invalidPlugins}";
135
136stdenv.mkDerivation (finalAttrs: {
137 pname = "gst-plugins-rs";
138 version = "0.14.4";
139
140 outputs = [
141 "out"
142 "dev"
143 ];
144
145 src = fetchFromGitLab {
146 domain = "gitlab.freedesktop.org";
147 owner = "gstreamer";
148 repo = "gst-plugins-rs";
149 rev = finalAttrs.version;
150 hash = "sha256-MZyYHMq6gFJkVxlrmeXUjOmRYsQBHj0848cnF+7mtbU=";
151 };
152
153 cargoDeps = rustPlatform.fetchCargoVendor {
154 inherit (finalAttrs) src;
155 name = "gst-plugins-rs-${finalAttrs.version}";
156 hash = "sha256-T+fdu+Oe07Uf1YoRGYl2DMb1QgdSZVLwcOqH4bBNGXU=";
157 };
158
159 strictDeps = true;
160
161 nativeBuildInputs = [
162 rustPlatform.cargoSetupHook
163 meson
164 ninja
165 python3
166 python3.pkgs.tomli
167 pkg-config
168 rustc
169 cargo
170 cargo-c
171 nasm
172 ]
173 # aws-lc-rs has no pregenerated bindings for exotic platforms
174 # https://aws.github.io/aws-lc-rs/platform_support.html
175 ++ lib.optionals (!(stdenv.hostPlatform.isx86 || stdenv.hostPlatform.isAarch64)) [
176 cmake
177 rustPlatform.bindgenHook
178 ]
179 ++ lib.optionals stdenv.hostPlatform.isDarwin [
180 lld
181 ]
182 ++ lib.optionals enableDocumentation [
183 hotdoc
184 ];
185
186 env = lib.optionalAttrs stdenv.hostPlatform.isDarwin { NIX_CFLAGS_LINK = "-fuse-ld=lld"; };
187
188 buildInputs = [
189 gstreamer
190 gst-plugins-base
191 ]
192 ++ lib.optionals stdenv.hostPlatform.isDarwin [
193 apple-sdk_gstreamer
194 ]
195 ++ lib.concatMap (plugin: lib.getAttr plugin validPlugins) selectedPlugins;
196
197 checkInputs = [
198 gst-plugins-good
199 gst-plugins-bad
200 ];
201
202 mesonFlags = (map (plugin: lib.mesonEnable plugin true) selectedPlugins) ++ [
203 (lib.mesonOption "sodium-source" "system")
204 (lib.mesonEnable "tests" finalAttrs.finalPackage.doCheck)
205 (lib.mesonEnable "doc" enableDocumentation)
206 ];
207
208 # turn off all auto plugins since we use a list of plugins we generate
209 mesonAutoFeatures = "disabled";
210
211 doCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
212
213 # csound lib dir must be manually specified for it to build
214 preConfigure = ''
215 export CARGO_BUILD_JOBS=$NIX_BUILD_CORES
216
217 patchShebangs dependencies.py
218 ''
219 + lib.optionalString (lib.elem "csound" selectedPlugins) ''
220 export CSOUND_LIB_DIR=${lib.getLib csound}/lib
221 '';
222
223 mesonCheckFlags = [ "--verbose" ];
224
225 preCheck = ''
226 # Fontconfig error: No writable cache directories
227 export XDG_CACHE_HOME=$(mktemp -d)
228 '';
229
230 postInstall = ''
231 install -Dm444 -t ''${!outputDev}/lib/pkgconfig gst*.pc
232 '';
233
234 doInstallCheck =
235 (lib.elem "webp" selectedPlugins) && !stdenv.hostPlatform.isStatic && stdenv.hostPlatform.isElf;
236 installCheckPhase = ''
237 runHook preInstallCheck
238 readelf -a $out/lib/gstreamer-1.0/libgstrswebp.so | grep -F 'Shared library: [libwebpdemux.so'
239 runHook postInstallCheck
240 '';
241
242 passthru = {
243 updateScript = nix-update-script {
244 # use numbered releases rather than gstreamer-* releases
245 # this matches upstream's recommendation: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/issues/470#note_2202772
246 extraArgs = [
247 "--version-regex"
248 "([0-9.]+)"
249 ];
250 };
251 };
252
253 meta = {
254 description = "GStreamer plugins written in Rust";
255 mainProgram = "gst-webrtc-signalling-server";
256 homepage = "https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs";
257 license = with lib.licenses; [
258 mpl20
259 asl20
260 mit
261 lgpl21Plus
262 ];
263 platforms = lib.platforms.unix;
264 maintainers = [ ];
265 };
266})