How to easily develop GTK apps already on nixpkgs?

Hello,

I want to contribute to: GitHub - ErikReider/SwayNotificationCenter: A simple GTK based notification daemon for SwayWM
I am already using the nixpkg present here: https://github.com/NixOS/nixpkgs/blob/d4b5a67bbe9ef750bd2fdffd4cad400dd5553af8/pkgs/applications/misc/swaynotificationcenter/default.nix

The program runs great using the nixpkg; I want to add a new feature to it and currently my workflow has been:

  1. Create a default.nix in the root of the project
with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "env";
  nativeBuildInputs = [
    bash-completion
    # cmake # currently conflicts with meson
    fish
    glib
    gobject-introspection
    meson
    ninja
    pkg-config
    python3
    scdoc
    vala
    wrapGAppsHook
  ];

  buildInputs = [
    dbus
    dbus-glib
    gdk-pixbuf
    glib
    gtk-layer-shell
    gtk3
    json-glib
    libgee
    libhandy
    libpulseaudio
    librsvg
    # systemd # ends with broken permission
  ];
}

I basically copy-pasted the inputs from the nixpkgs already present.

  1. I do nix-shell in the root which gives me all the tools I need
  2. I build the program:
meson build
ninja -C build
meson install -C build

The install tries to put things in /usr/local so it fails.

  1. I try to run the program, but encounter an error:
$ ./build/src/swaync
GLib-GIO-ERROR **: 08:30:34.620: Settings schema 'org.erikreider.swaync' is not installed

Tracked the error down to this line:

self_settings = new Settings ("org.erikreider.swaync");

Since I am on nixos and cannot install things the normal way, here are my questions:

  1. If something is already present on nixpkg, is there an easy way to have a nix-shell quickly setup?
  2. In the case above, how do I run the thing without installing the gsetting? Is there some trick I am missing here?

I had success with setting a local prefix like --prefix="${PWD}/out" in the meson setup command. Then installing and running the application from there.

Edit: wait, nvm, I don’t think I actually dealt with gsettings before.

1 Like

Good tip, now the installation works with meson :smiley:

I still have no ideea how to deal with the gsettings thing; Now the schema is installed in the ./out folder, but it still gives the same error since the schema isn’t loaded in gsettings.

Haven’t tried, but maybe you can specify the path using an environment variable (GTK_PATH looks promising). Here is a list of all of them for GTK3 as well as some other things that might be useful when debugging: Gtk – 3.0: Running GTK Applications

If that doesn’t help, using strace, possibly together with gdb might help in figuring out where Settings is looking for things and how that path might be influenced. Ultimately, you could look into the GTK sources, but this can be a huge rabbit hole depending on how many layers of indirection they have so I usually try to get a good idea using strace at first.

The documentation for GNOME platform is in the Nixpkgs manual, including the description of requirements for GSettings.

Normally, the projects’ executables are wrapped to set relevant environment variables when packaged in Nixpkgs but that will not happen when trying to run a project unpackaged.

GTK_PATH is not relevant for settings, that is handled by GLib not GTK. The proper variable to set is XDG_DATA_DIRS.

With this, you can add $PWD/out/share to XDG_DATA_DIRS after the project is installed.

However, you should not need to install meson apps to run them. Meson has a devenv subcommand which allows running most project’s executables out of the build directory. Just make sure to call gnome.compile_schemas() function in the Meson build files. And if some other environment variables are needed, you can include them with meson.add_devenv().

2 Likes

If you want to use a derivation from Nixpkgs or any package set, you can just pass the set’s path as an argument to nix-shell. Plus -A followed by the attribute path of the derivation you want to use for shell:

nix-shell /path/to/nixpkgs -A swaynotificationcenter