Skip to content

Instantly share code, notes, and snippets.

@peanutbutterandcrackers
Last active August 12, 2023 15:20
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save peanutbutterandcrackers/844c211a91137c19607ae75b59fa116f to your computer and use it in GitHub Desktop.
Save peanutbutterandcrackers/844c211a91137c19607ae75b59fa116f to your computer and use it in GitHub Desktop.
Guix Desktop-Environment Integration Guide

Guix Desktop-Environment Integration:

A guide to better DE-Integration for the GNU Guix Package Manager.

This has been tried and tested (successfully) in the following desktop environments:

  • GNOME (Debian 10.2 'Buster')
  • MATE, XFCE, KDE (Linux Mint 19 'Tara')
  • Cinnammon (Linux Mint 19.1 'Tessa')
  • Pantheon (Elementary OS 5.0 'Juno')

For all the amazing benifits of GNU Guix, one thing it still lacks is proper integration with the desktop environment of the host system (foreign distros). A GUI program installed using GUIX is not available from the GUI menus of the host system (unlike Flatpak). However, with the following steps, one can integrate Guix-installed-applications with the desktop environment in a pretty decent manner:

  1. Create a new file - guix.sh - in /etc/profile.d, containing the following lines (will require root privileges):
export GUIX_PROFILE="$HOME/.guix-profile"
export GUIX_LOCPATH="$GUIX_PROFILE/lib/locale"
export PATH="$HOME/.config/guix/current/bin${PATH:+:}$PATH"
eval `guix package --search-paths=prefix 2> /dev/null`

# set XDG_DATA_DIRS to include Guix installations
export XDG_DATA_DIRS="$GUIX_PROFILE/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"

(or simply copy the guix.sh file below - with further conditional checks - into your /etc/profile.d)

  1. Log out and log back in to see the GUI applications (openshot, aegisub, etc.) in your GUI menus.

Explanation:

  • /etc/profile, is an init file that is executed by all login-shells on a GNU/Linux system. In most modern distros, /etc/profile also reads files ending in .sh residing inside /etc/profile.d. Hence, the file /etc/profile.d/guix.sh; the commands contained therein are executed while logging in to a user-session.
  • The first two lines are just plain-old guix-recommended, basic stuffs. They set the GUIX_PROFILE, and GUIX_LOCPATH environment variables for the user currently logging in.
  • guix package --search-path returns all the environment variables that should be set in order for the programs installed using guix to run properly. Among the other things, it also exports the PATH variable. However, it does not include $HOME/.config/guix/current/bin (which contains the latest version of guix obtained via a guix pull). Hence the 3rd line. This causes the latest guix to run in the subsequent calls to guix in the session.
  • The last line returns a list of all environment variables required to be set for the guix-installed programs to function properly, first. The list is then eval-ed and thus the environment is established: all set and ready for guix-installed packages to function properly.
  • The line that exports the XDG_DATA_DIR is the most important one, that does the DE-integration.

Limitations:

  • While uninstalling an application (guix remove openshot) did remove the application from the menus; subsequent installation and --roll-backs had no effect on the menu whatsoever.

Further Steps:

  • Perhaps triggers could be set in motion after every guix transaction (if the user has opt-ed in for it during installation or via some other configuration) that would take care of the menu, etc. updates?
# _GUIX_PROFILE: `guix pull` profile
_GUIX_PROFILE="$HOME/.config/guix/current"
[ -L $_GUIX_PROFILE ] && export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
# GUIX_PROFILE: User's default profile
GUIX_PROFILE="$HOME/.guix-profile"
[ -L $GUIX_PROFILE ] || return
GUIX_LOCPATH="$GUIX_PROFILE/lib/locale"
export GUIX_PROFILE GUIX_LOCPATH
eval `guix package --search-paths=prefix 2> /dev/null`
# set XDG_DATA_DIRS to include Guix installations
export XDG_DATA_DIRS="$GUIX_PROFILE/share${XDG_DATA_DIRS:+:}$XDG_DATA_DIRS"
@FOSSdilettante
Copy link

I'm using Triskel 10 with KDE, and it doesn't seem to work still. In the profile.d folder there is also a "zzz-guix.sh" file with the following code:

# Explicitly initialize XDG base directory variables to ease compatibility
# with Guix System: see <https://issues.guix.gnu.org/56050#3>.
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export XDG_DATA_DIRS="${XDG_DATA_DIRS:-/usr/local/share/:/usr/share/}"
export XDG_CONFIG_DIRS="${XDG_CONFIG_DIRS:-/etc/xdg}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
# no default for XDG_RUNTIME_DIR (depends on foreign distro for semantics)

# _GUIX_PROFILE: `guix pull` profile
_GUIX_PROFILE="$HOME/.config/guix/current"
export PATH="$_GUIX_PROFILE/bin${PATH:+:}$PATH"
# Export INFOPATH so that the updated info pages can be found
# and read by both /usr/bin/info and/or $GUIX_PROFILE/bin/info
# When INFOPATH is unset, add a trailing colon so that Emacs
# searches 'Info-default-directory-list'.
export INFOPATH="$_GUIX_PROFILE/share/info:$INFOPATH"

# GUIX_PROFILE: User's default profile
# Prefer the one from 'guix home' if it exists.
GUIX_PROFILE="$HOME/.guix-home/profile"
[ -L $GUIX_PROFILE ] || GUIX_PROFILE="$HOME/.guix-profile"
[ -L $GUIX_PROFILE ] || return
GUIX_LOCPATH="$GUIX_PROFILE/lib/locale"
export GUIX_LOCPATH

[ -f "$GUIX_PROFILE/etc/profile" ] && . "$GUIX_PROFILE/etc/profile"

Do you think this is doing anything to disrupt guix.sh, or maybe I'm doing something else wrong? I've gotten it working on Triskel before, but I can't for the life of me remember what I did.

@peanutbutterandcrackers
Copy link
Author

@FOSSdilettante

Hello there,

First, trisquel (and all debian based distros that supply guix via apt should now have the guix.sh file (these changes were merged upstream). So that's normal. But I don't see why the file is named zzz-guix.sh. I thought it was supposed to guix.sh.

I had a similar issue with Trisquel. But I was using MATE. On Trisquel 9, I believe. It was an issue with XDG_DATA_DIRS which is what the explicit XDG_DATA_DIRS set in the code that you posted. So it isn't really clear to me what is failing here. But I would suggest adding an explicit source /etc/profile.d/zzz-guix.sh in your $HOME/.profile. Perhaps that should help. Using env | grep XDG or env | grep GUIX should also provide some clue as to whether the file is being sourced or not.

All the very best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment