Setting XDG_DATA_DIRS in desktop snaps

tl;dr - desktop helpers don’t seem to setup XDG_DATA_DIRS correctly. May only be of interest to @kenvandine :smiley:

Over the weekend I took a look at snapping a funky desktop elementary OS presentation application called Spice-Up. The application makes nice presentations, and as with most elementary OS apps, is written in vala.

I click “New presentation”:

I get this in the console:

[FATAL 18:33:48.997449] file /root/build_spice-up/parts/spice-up/src/src/Services/FileManager.vala: line 100: uncaught error: Failed to create file '/home/alan/(null)/Untitled Presentation 1.spice.1B7C7Y': No such file or directory (g-file-error-quark, 4)

Note: “(null)” is due to it not being able to figure out my “Documents” directory name.

I had to do a few nasty things to get the required elementary libraries required to get the snap working, lets gloss over that bit in this thread ;). The issue I have is that the application uses the vala get_user_special_dir to obtain the localised “Documents” directory, in which to create the presentation. This fails (details below) which uncovered a bug in the application which doesn’t do the right thing when the XDG_DATA_DIRS aren’t setup right.

I’m sure they’ll fix that, but the more pressing thing for me is that the directories aren’t setup in the first place.

XDG_DATA_DIRS=/home/alan/snap/spice-up/x1/.local/share:/home/alan/snap/spice-up/x1:/snap/spice-up/x1/usr/share:/usr/share/ubuntu:/usr/share/gnome:/home/alan/.local/share/flatpak/exports/share:/var/lib/flatpak/exports/share:/usr/local/share:/usr/share:/var/lib/snapd/desktop

As far as I can tell, the location this points to should contain user-dirs.dirs and user-dirs.locale but they don’t. On my non-snap home directory those files are in ~/.config as expected. But when the snap is run, it doesn’t see that directory (the home plug blocks hidden directories) and the .dirs files don’t exist inside the $SNAP_USER_DATA environment.

Should the desktop helpers set these up?

Here’s my yaml. Only run this in cleanbuild - it adds PPAs, you don’t want that.

name: spice-up
version: '1.0.0'
summary: Create simple and beautiful presentations on the Linux desktop
description: |
  Spice-up is a modern and intuitive desktop presentation app based
  upon SpiceOfDesign's presentation concept. Built from the ground up
  for elementary OS, it gives you everything you need to create simple
  and beautiful presentations.

grade: stable
confinement: devmode

apps:
  spice-up:
    command: desktop-launch $SNAP/bin/com.github.philip-scott.spice-up
    plugs:
      - x11
      - unity7
      - home
      - gsettings
      - pulseaudio
      - opengl
      - network

parts:
  elementary:
    plugin: nil
    prepare: |
      add-apt-repository -y ppa:elementary-os/stable
      add-apt-repository -y ppa:elementary-os/os-patches
      echo "Package: *" > /etc/apt/preferences.d/elementary-stable
      echo "Pin: release o=LP-PPA-elementary-os-stable" >> /etc/apt/preferences.d/elementary-stable
      echo "Pin-Priority: 1000" >> /etc/apt/preferences.d/elementary-stable
      echo "Package: *" > /etc/apt/preferences.d/elementary-patches
      echo "Pin: release o=LP-PPA-elementary-os-os-patches" >> /etc/apt/preferences.d/elementary-patches
      echo "Pin-Priority: 1000" >> /etc/apt/preferences.d/elementary-patches
      apt update
      apt dist-upgrade -y
  spice-up:
    after: [elementary, desktop-gtk3]
    plugin: cmake
    source: https://github.com/Philip-Scott/Spice-up.git
    source-tag: '1.0.0'
    build-packages:
      - build-essential
      - gettext
      - libgee-0.8-dev
      - libgtk-3-dev
      - valac
      - libgranite-dev
      - libjson-glib-dev
      - libgudev-1.0-dev
      - libevdev-dev
    organize:
      share/glib-2.0: usr/share/glib-2.0
1 Like

If you test this in an xorg session, I suspect it would work. XDG_DATA_DIRS isn’t set in the wayland session. There is a branch of snapd that ensures this gets set, which has been merged. I think that will be included in the next snapd release.

@kenvandine I am in a full bodied xorg session on 16.04. None of your new fangled wayland here!

@popey do you have /etc/X11/Xsession.d/65snappy ?

@popey, at I think I missed your original point. So the issue isn’t a problem with $XDG_DATA_DIRS, but it’s accessing files needed. I need to dig in a little bit more to understand why get_user_special_dir might not do the right thing there.

None of your new fangled wayland here!

@popey, did you miss off the suffix “gerroff my lawn”?

1 Like

I think this should be handled in the helper. We need to run xdg-user-dirs-update, but that fails to find /etc/xdg/user-dirs.defaults. I’ll look into how we can fix that.

2 Likes

:smiley:

(for the humour impaired, this was a joke and not in any way a sleight on the wayland protocol or any implementation thereof, your honour)

2 Likes

Do you need a bug tracking this? Is there anything anyone can do to help or is this on you? :slight_smile:

I’m working on it already, but yes please file a bug on github for it.

I’ve submitted a PR for this, which I’ve tested with spice-up and it now creates new presentations. I think it could be better if we could set those XDG_XXX_DIRs to something from the host’s home, but I haven’t seen a way to get that yet.

2 Likes

Hello, I suppose this patch didn’t set XDG_DATA_DIRS to $SNAP/share? Currently the XDG_DATA_DIRS still uses host’s value AFAICT

UPDATE: The variables does properly set by $SNAP/bin/desktop-launch