23 , withIntrospection ? stdenv.hostPlatform == stdenv.buildPlatform
24 , gobject-introspection
25 , _experimental-update-script-combinators
26 , common-updater-scripts
31 stdenv.mkDerivation rec {
35 outputs = [ "out" "dev" ] ++ lib.optionals withIntrospection [
40 url = "mirror://gnome/sources/${pname}/${lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
41 sha256 = "a69IqdOlb9E7v7ufH3Z1myQLcKH6Ig/SOEdNZqkm+Yw=";
44 cargoDeps = rustPlatform.fetchCargoTarball {
46 name = "${pname}-${version}";
47 hash = "sha256-nRmOB9Jo+mmB0+wXrQvoII4e0ucV7bNCDeuk6CbcPdk=";
48 # TODO: move this to fetchCargoTarball
54 depsBuildBuild = [ pkg-config ];
61 python3Packages.docutils
63 rustPlatform.cargoSetupHook
64 ] ++ lib.optionals withIntrospection [
74 ] ++ lib.optionals withIntrospection [
76 ] ++ lib.optionals stdenv.isDarwin [
82 propagatedBuildInputs = [
89 (lib.enableFeature withIntrospection "introspection")
91 # Vapi does not build on MacOS.
92 # https://github.com/NixOS/nixpkgs/pull/117081#issuecomment-827782004
93 (lib.enableFeature (withIntrospection && !stdenv.isDarwin) "vala")
95 "--enable-always-build-tests"
96 ] ++ lib.optional stdenv.isDarwin "--disable-Bsymbolic"
97 ++ lib.optional (stdenv.buildPlatform != stdenv.hostPlatform) "RUST_TARGET=${rust.toRustTarget stdenv.hostPlatform}";
99 doCheck = false; # all tests fail on libtool-generated rsvg-convert not being able to find coreutils
101 # It wants to add loaders and update the loaders.cache in gdk-pixbuf
102 # Patching the Makefiles to it creates rsvg specific loaders and the
103 # relevant loader.cache here.
104 # The loaders.cache can be used by setting GDK_PIXBUF_MODULE_FILE to
105 # point to this file in a wrapper.
107 GDK_PIXBUF=$out/lib/gdk-pixbuf-2.0/2.10.0
108 mkdir -p $GDK_PIXBUF/loaders
109 sed -e "s#gdk_pixbuf_moduledir = .*#gdk_pixbuf_moduledir = $GDK_PIXBUF/loaders#" \
110 -i gdk-pixbuf-loader/Makefile
111 sed -e "s#gdk_pixbuf_cache_file = .*#gdk_pixbuf_cache_file = $GDK_PIXBUF/loaders.cache#" \
112 -i gdk-pixbuf-loader/Makefile
113 sed -e "s#\$(GDK_PIXBUF_QUERYLOADERS)#GDK_PIXBUF_MODULEDIR=$GDK_PIXBUF/loaders \$(GDK_PIXBUF_QUERYLOADERS)#" \
114 -i gdk-pixbuf-loader/Makefile
116 # Fix thumbnailer path
117 sed -e "s#@bindir@\(/gdk-pixbuf-thumbnailer\)#${gdk-pixbuf}/bin\1#g" \
118 -i gdk-pixbuf-loader/librsvg.thumbnailer.in
120 # 'error: linker `cc` not found' when cross-compiling
121 export RUSTFLAGS="-Clinker=$CC"
124 # Not generated when cross compiling.
125 postInstall = lib.optionalString (stdenv.hostPlatform == stdenv.buildPlatform) ''
126 # Merge gdkpixbuf and librsvg loaders
127 cat ${lib.getLib gdk-pixbuf}/lib/gdk-pixbuf-2.0/2.10.0/loaders.cache $GDK_PIXBUF/loaders.cache > $GDK_PIXBUF/loaders.cache.tmp
128 mv $GDK_PIXBUF/loaders.cache.tmp $GDK_PIXBUF/loaders.cache
131 postFixup = lib.optionalString withIntrospection ''
132 # Cannot be in postInstall, otherwise _multioutDocs hook in preFixup will move right back.
133 moveToOutput "share/doc" "$devdoc"
139 updateSource = gnome.updateScript {
140 packageName = "librsvg";
148 PATH=${lib.makeBinPath [
149 common-updater-scripts
153 # update-source-version does not allow updating to the same version so we need to clear it temporarily.
154 # Get the current version so that we can restore it later.
155 latestVersion=$(nix-instantiate --eval -A librsvg.version | jq --raw-output)
156 # Clear the version. Provide hash so that we do not need to do pointless TOFU.
157 # Needs to be a fake SRI hash that is non-zero, since u-s-v uses zero as a placeholder.
158 # Also cannot be here verbatim or u-s-v would be confused what to replace.
159 update-source-version librsvg 0 "sha256-${lib.fixedWidthString 44 "B" "="}" --source-key=cargoDeps > /dev/null
160 update-source-version librsvg "$latestVersion" --source-key=cargoDeps > /dev/null
163 # Experimental feature: do not copy!
164 supportedFeatures = [ "silent" ];
167 _experimental-update-script-combinators.sequence [
174 description = "A small library to render SVG images to Cairo surfaces";
175 homepage = "https://wiki.gnome.org/Projects/LibRsvg";
176 license = licenses.lgpl2Plus;
177 maintainers = teams.gnome.members;
178 mainProgram = "rsvg-convert";
179 platforms = platforms.unix;