How to have libgtk-4-media-gstreamer on nixos

There’s a package `libgtk-4-media-gstreamer``that is available for debian and I want to install it. However, there’s nothing on NixOS Search and I really don’t know where to start looking for.

Looking at Debian file listing for the package, that is just part of regular the gtk4 package in Nixpkgs:

$ nix-locate libmedia-gstreamer.so
gtk4.out                                         50,712 x /nix/store/73y2phag01l0qbzsn0a5rhk0d1vhxgkh-gtk4-4.8.2/lib/gtk-4.0/4.0.0/media/libmedia-gstreamer.so

Just note that to actually play media, you will also need GStreamer plug-ins. In Nixpkgs, this is achieved by wrapping the executable programs of the project you want to package with extra environment variables.

1 Like

back to my hanabi installation

And based on your advice, i think the extra environment variables you mentioned is GST_PLUGIN_SYSTEM_PATH_1_0 which will be available when I have gst_all_1.gstreamer in my environment.systemPackages

I kinda understand that I need to add something like this in my hanabi installation in order to wrap it:

preFixup = ''
  wrapGAppsHook ??? --prefix GST_PLUGIN_SYSTEM_PATH_1_0: ???
'';

However, I can’t really wrap my head around it (no pun intended) and I feel like I’m doing something else completely different or completely wrong.

No. You cannot install libraries using Nix profiles like environment.systemPackages, see I installed a library but my compiler is not finding it. Why?

Individual programs need to be wrapped to set the environment variables when they are launched.

Unfortunately, GNOME Shell extensions are not executable programs so they cannot be wrapped, unless the component that requires the wrapping is split into a separate executable file. Fortunately, this appears the case with Hanabi:

renderer.js would need to be wrapped.

That is makeWrapper/wrapProgram syntax. wrapGAppsHook takes no arguments and it is run automatically in fixupOutputPhase if you add it to nativeBuildInputs. You should not call it manually, if you want to pass extra arguments, you can add them to gappsWrapperArgs.

If you need a finer control, you can set dontWrapGApps = true and use wrapGApp, which accepts list of paths to wrap, and other extra arguments to pass to makeWrapper along with the contents of gappsWrapperArgs variable set by the setup hook.

Either way, you would not need to explicitly pass the value of GST_PLUGIN_SYSTEM_PATH_1_0. GStreamer setup hook will populate it from the packages put to buildInputs, and then wrapGAppsHook will pick it up.

I think, in your case it would result in something like the following:

nativeBuildInputs = [
  wrapGAppsHook4
];

buildInputs = [
  gst_all_1.gstreamer
  gst_all_1.gst-plugins-base
  gst_all_1.gst-plugins-good
  ## maybe some other plug-ins based on the file formats the program supports
];

# The programs to wrap are in non-standard location, we will wrap them manually.
dontWrapGApps = true;

postFixup = ''
  wrapGApp "$out/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/renderer/renderer.js"
'';
1 Like

this is hanabi.nix for now

{pkgs, stdenv, fetchFromGitHub }:
{
  hanabi = stdenv.mkDerivation rec {
    pname = "org.gnome.shell.extensions.hanabi-extension";
    version = "";
    dontBuild = false;
    nativeBuildInputs = with pkgs; [
      meson
      ninja
      glib
      nodejs
      wrapGAppsHook4
    ];

    buildInputs = with pkgs; [
    gst_all_1.gstreamer
    # Video/Audio data composition framework tools like "gst-inspect", "gst-launch" ...
    gst_all_1.gstreamer
    # Common plugins like "filesrc" to combine within e.g. gst-launch
    gst_all_1.gst-plugins-base
    # Specialized plugins separated by quality
    gst_all_1.gst-plugins-good
    gst_all_1.gst-plugins-bad
    gst_all_1.gst-plugins-ugly
    # Plugins to reuse ffmpeg to play almost every video format
    gst_all_1.gst-libav
    # Support the Video Audio (Hardware) Acceleration API
    gst_all_1.gst-vaapi
    ];
    dontWrapGApps = true;

    postFixup = ''
      wrapGApp "$out/share/glib-2.0/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/renderer/renderer.js"
    '';
    
    postPatch = ''
      patchShebangs build-aux/meson-postinstall.sh 
    '';

    postInstall = ''
      mv "$out/share/glib-2.0/schemas" "$out/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/schemas"
    '';

    src = fetchFromGitHub {
      owner = "jeffshee";
      repo = "gnome-ext-hanabi";
      rev = "f7f2231188d67bed828d0fdf978ace872da2d216";
      sha256 = "sha256-IkQtg0fddCnEy2yGKtH5ZOdbuclJLkCqBjO2pSeUk9I=";
    };
  };
}

when do a nixos-rebuild switch:

Builder called die: Cannot wrap '/nix/store/65bxkyqc3ygh3gqbyddwsk8k0j0h58nk-org.gnome.shell.extensions.hanabi-extension-/share/glib-2.0/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/renderer/renderer.js' because it is not an executable file
Backtrace:
10 assertExecutable /nix/store/yfpp3w9bs2ps8qbi9wpfdlflwbwcbz8v-make-binary-wrapper-hook/nix-support/setup-hook
63 wrapProgramBinary /nix/store/yfpp3w9bs2ps8qbi9wpfdlflwbwcbz8v-make-binary-wrapper-hook/nix-support/setup-hook
58 wrapProgram /nix/store/yfpp3w9bs2ps8qbi9wpfdlflwbwcbz8v-make-binary-wrapper-hook/nix-support/setup-hook
42 wrapGApp /nix/store/iljcqgyqicwjlpmd1kwlblj22w60n6px-wrap-gapps-hook/nix-support/setup-hook
114 _callImplicitHook /nix/store/wr08yanv2bjrphhi5aai12hf2qz5kvic-stdenv-linux/setup
131 _eval /nix/store/wr08yanv2bjrphhi5aai12hf2qz5kvic-stdenv-linux/setup
74 runHook /nix/store/wr08yanv2bjrphhi5aai12hf2qz5kvic-stdenv-linux/setup
1446 fixupPhase /nix/store/wr08yanv2bjrphhi5aai12hf2qz5kvic-stdenv-linux/setup
1559 runPhase /nix/store/wr08yanv2bjrphhi5aai12hf2qz5kvic-stdenv-linux/setup
1600 genericBuild /nix/store/wr08yanv2bjrphhi5aai12hf2qz5kvic-stdenv-linux/setup
4 main /nix/store/v6x3cs394jgqfbi0a42pam708flxaphh-default-builder.sh

error: builder for '/nix/store/fjgmsjzlv69xly89ll8yy88az0y6xhdz-org.gnome.shell.extensions.hanabi-extension-.drv' failed with exit code 1

It’s weird how the renderer.js is not an executable file although i went on and check in /nix/store and the renderer is definitely an executable file

-r-xr-xr-x    1 root     root         20489 Dec 31  1969 renderer.js

Sorry, I had a copy-paste typo in the path to the renderer.js, it should not contain /glib-2.0.

1 Like

oh i didn’t even noticed it, sorry

final answer:
don’t know why but apparently gjs is also needed for it to run
so i added it in buildInputs and now it’s working brilliantly.

{pkgs, stdenv, fetchFromGitHub }:
{
  hanabi = stdenv.mkDerivation rec {
    pname = "org.gnome.shell.extensions.hanabi-extension";
    version = "";
    dontBuild = false;
    nativeBuildInputs = with pkgs; [
      meson
      ninja
      glib
      nodejs
      wrapGAppsHook4
    ];

    buildInputs = with pkgs; [
    # Video/Audio data composition framework tools like "gst-inspect", "gst-launch" ...
    gst_all_1.gstreamer
    # Common plugins like "filesrc" to combine within e.g. gst-launch
    gst_all_1.gst-plugins-base
    # Specialized plugins separated by quality
    gst_all_1.gst-plugins-good
    gst_all_1.gst-plugins-bad
    gst_all_1.gst-plugins-ugly
    # Plugins to reuse ffmpeg to play almost every video format
    gst_all_1.gst-libav
    # Support the Video Audio (Hardware) Acceleration API
    gst_all_1.gst-vaapi
    gjs
    ];
    dontWrapGApps = true;
    
    postPatch = ''
      patchShebangs build-aux/meson-postinstall.sh 
    '';

    postInstall = ''
      mv "$out/share/glib-2.0/schemas" "$out/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/schemas"
    '';

    postFixup = ''
      wrapGApp "$out/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/renderer/renderer.js"
    '';


    src = fetchFromGitHub {
      owner = "jeffshee";
      repo = "gnome-ext-hanabi";
      rev = "f7f2231188d67bed828d0fdf978ace872da2d216";
      sha256 = "sha256-IkQtg0fddCnEy2yGKtH5ZOdbuclJLkCqBjO2pSeUk9I=";
    };
  };
}

Yeah, gjs is the interpreter used to run renderer.js:

You need it to add it to buildInputs so that patchShebangAuto setup hook can pick it up.

Final question
the extension doesn’t seen to be utilizing clappersink, i tried putting clapper inside buildInputs and nativeBuildInputs respectively but they just don’t seem to be working

They seem to be using gstreamer-rs which is the second best and I’m trying it out
nope, gstreamer-rs doesn’t help at all

I would expect clapper in buildInputs to be sufficient. What do you mean they don’t seem to be working? Are there any messages in the journal?

I dont see any specific messages in the journalctl but the resource used is too much, comparing to how it should be

my journalctl is filled with all the errors that looks like from when i was trying to do dumb things with hanabi, and doing journalctl | grep took way too long

alr here it is

Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) Gjs-Console-Message: 21:24:30.799: using GtkMediaFile for video output
Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) (gjs:3684): Gjs-Console-DEBUG: 21:24:30.791: filepath = /etc/nixos/gnome-ext/background.mp4
Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) (gjs:3684): Gjs-Console-DEBUG: 21:24:30.791: codepath = /run/current-system/sw/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io
Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) (gjs:3684): Gtk-WARNING **: 21:24:30.779: Theme parser error: gtk.css:7804:21-28: Expected a valid color.
Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) (gjs:3684): Gtk-WARNING **: 21:24:30.779: Theme parser error: gtk.css:7798:21-28: Expected a valid color.
Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) (gjs:3684): Gtk-WARNING **: 21:24:30.779: Theme parser error: gtk.css:7780:21-28: Expected a valid color.
Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) (gjs:3684): Gtk-WARNING **: 21:24:30.779: Theme parser error: gtk.css:7775:21-28: Expected a valid color.
Dec 31 21:24:30 Windows11 .gnome-shell-wr[2795]: Hanabi: (renderer) (gjs:3684): Gtk-DEBUG: 21:24:30.772: Connecting to session manager
-- Boot e93ba60c71464d7d87f49bcd9f63d068 --
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) Gjs-Console-Message: 20:58:41.898: using GtkMediaFile for video output
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) (gjs:3710): Gjs-Console-DEBUG: 20:58:41.890: filepath = /etc/nixos/gnome-ext/background.mp4
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) (gjs:3710): Gjs-Console-DEBUG: 20:58:41.890: codepath = /run/current-system/sw/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) (gjs:3710): Gtk-WARNING **: 20:58:41.877: Theme parser error: gtk.css:7804:21-28: Expected a valid color.
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) (gjs:3710): Gtk-WARNING **: 20:58:41.877: Theme parser error: gtk.css:7798:21-28: Expected a valid color.
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) (gjs:3710): Gtk-WARNING **: 20:58:41.877: Theme parser error: gtk.css:7780:21-28: Expected a valid color.
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) (gjs:3710): Gtk-WARNING **: 20:58:41.877: Theme parser error: gtk.css:7775:21-28: Expected a valid color.
Dec 31 20:58:41 Windows11 .gnome-shell-wr[2806]: Hanabi: (renderer) (gjs:3710): Gtk-DEBUG: 20:58:41.870: Connecting to session manager
-- Boot ad13b5792afb433bba8a71833b0f4f39 --
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) Gjs-Console-Message: 20:56:55.485: using GtkMediaFile for video output
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Object St.Label (0x5dd2210), has been already disposed — impossible to access it. This might be caused by the object having been destroyed from C code using something such as destroy(), di>
                                                 == Stack trace for context 0x2128710 ==
                                                 #0        21eba88 i   file:///run/current-system/sw/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/panelMenu.js:101 (39ae8c551a10 @ 210)
                                                 #1   7ffca003a800 b   resource:///org/gnome/gjs/modules/core/_signals.js:130 (248d172956f0 @ 126)
                                                 #2   7ffca003a8e0 b   resource:///org/gnome/gjs/modules/core/_signals.js:119 (248d17295600 @ 286)
                                                 #3   7ffca003a9c0 b   resource:///org/gnome/gjs/modules/core/overrides/Gio.js:152 (248d1728a4c0 @ 39)
                                                 #4        21eb9f8 i   resource:///org/gnome/shell/ui/init.js:21 (248d17270ba0 @ 48)
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:5239): Gjs-Console-DEBUG: 20:56:55.479: filepath = /etc/nixos/gnome-ext/background.mp4
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:5239): Gjs-Console-DEBUG: 20:56:55.478: codepath = /run/current-system/sw/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:5239): Gtk-WARNING **: 20:56:55.468: Theme parser error: gtk.css:7804:21-28: Expected a valid color.
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:5239): Gtk-WARNING **: 20:56:55.468: Theme parser error: gtk.css:7798:21-28: Expected a valid color.
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:5239): Gtk-WARNING **: 20:56:55.468: Theme parser error: gtk.css:7780:21-28: Expected a valid color.
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:5239): Gtk-WARNING **: 20:56:55.468: Theme parser error: gtk.css:7775:21-28: Expected a valid color.
Dec 31 20:56:55 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:5239): Gtk-DEBUG: 20:56:55.462: Connecting to session manager
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) Gjs-Console-Message: 20:19:52.087: using GtkMediaFile for video output
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:3556): Gjs-Console-DEBUG: 20:19:52.080: filepath = /etc/nixos/gnome-ext/background.mp4
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:3556): Gjs-Console-DEBUG: 20:19:52.080: codepath = /run/current-system/sw/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:3556): Gtk-WARNING **: 20:19:52.067: Theme parser error: gtk.css:7804:21-28: Expected a valid color.
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:3556): Gtk-WARNING **: 20:19:52.067: Theme parser error: gtk.css:7798:21-28: Expected a valid color.
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:3556): Gtk-WARNING **: 20:19:52.067: Theme parser error: gtk.css:7780:21-28: Expected a valid color.
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:3556): Gtk-WARNING **: 20:19:52.067: Theme parser error: gtk.css:7775:21-28: Expected a valid color.
Dec 31 20:19:52 Windows11 .gnome-shell-wr[2679]: Hanabi: (renderer) (gjs:3556): Gtk-DEBUG: 20:19:52.061: Connecting to session manager

it’s using GtkMediaFile no matter what, even when i disable the force GtkMediaFile option in the preference and do a reboot

i also don’t think that the renderer doesn’t read the schema since i’ve linked it like your recommendation and commented out the mv part

adding some more in the nativeBuildInputs and buildInputs seems to solve the problem

{pkgs, stdenv, fetchFromGitHub }:
{
  hanabi = stdenv.mkDerivation rec {
    pname = "gnome-ext-hanabi";
    version = "";
    dontBuild = false;
    nativeBuildInputs = with pkgs; [
      meson
      ninja
      glib
      nodejs
      wrapGAppsHook4
      appstream-glib
      gobject-introspection
#      makeWrapper
#      pkg-config
      shared-mime-info
    ];

    buildInputs = with pkgs; [
    # Video/Audio data composition framework tools like "gst-inspect", "gst-launch" ...
    gst_all_1.gstreamer
    # Common plugins like "filesrc" to combine within e.g. gst-launch
    gst_all_1.gst-plugins-base
    # Specialized plugins separated by quality
    gst_all_1.gst-plugins-good
    gst_all_1.gst-plugins-bad
    gst_all_1.gst-plugins-ugly
    # Plugins to reuse ffmpeg to play almost every video format
    gst_all_1.gst-libav
    # Support the Video Audio (Hardware) Acceleration API
    gst_all_1.gst-vaapi
#    gst_all_1.gst-plugins-rs
    clapper
    gjs
    gtk4
    glib
#    libadwaita
#    libGL
#    libsoup
    wayland
    wayland-protocols
    ];
    dontWrapGApps = true;

#    installPhase = ''
#      cp -r $out/share/gsettings-schemas/gnome-extension-hanabi-/glib-2.0 $out/share/glib-2.0
#    '';
    
    postPatch = ''
      patchShebangs build-aux/meson-postinstall.sh 
    '';

#    postInstall = ''
#      mv "$out/share/glib-2.0/schemas" "$out/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/schemas"
#    '';

    postFixup = ''
      wrapGApp "$out/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/renderer/renderer.js"
      ln -s "$out/share/gsettings-schemas/gnome-ext-hanabi-/glib-2.0/schemas" "$out/share/gnome-shell/extensions/hanabi-extension@jeffshee.github.io/schemas"

    '';


    src = fetchFromGitHub {
      owner = "jeffshee";
      repo = "gnome-ext-hanabi";
      rev = "f7f2231188d67bed828d0fdf978ace872da2d216";
      sha256 = "sha256-IkQtg0fddCnEy2yGKtH5ZOdbuclJLkCqBjO2pSeUk9I=";
    };
  };
}
#git ls-remote https://github.com/jeffshee/gnome-ext-hanabi for rev