https://guix.gnu.org/feeds/blog/xfce.atomGNU Guix — Blog — Xfcefeed author nameGNU Guixhttps://guix.gnu.org/themes/initial/img/icon.png2024-03-20T10:58:00Zhttps://guix.gnu.org/blog/2019/running-a-guix-xfce-desktop-on-centos-7//Running a Guix Xfce Desktop on CentOS 7Marius Bakke2019-11-17T19:00:00Z2019-11-17T19:00:00Z This tutorial will show how to run a fully fledged Xfce desktop environment
installed with Guix on top of an existing GNU/Linux distribution. This guide
uses CentOS 7 as the base operating system and assumes that Xorg is already
configured and running on VT2 under a different user account. We will borrow Xorg and xinit from the host distribution and run Guix Xfce on
virtual terminal 4 as user alice . No system-wide configuration files need to
be touched (apart from the Guix install), but we do make a couple of changes
for convenience. From scratch to…<p>This tutorial will show how to run a fully fledged Xfce desktop environment
installed with Guix on top of an existing GNU/Linux distribution. This guide
uses CentOS 7 as the base operating system and assumes that Xorg is already
configured and running on VT2 under a different user account.</p><p>We will borrow Xorg and <code>xinit</code> from the host distribution and run Guix Xfce on
virtual terminal 4 as user <code>alice</code>. No system-wide configuration files need to
be touched (apart from the Guix install), but we do make a couple of changes
for convenience.</p><h4>From scratch to Xfce</h4><p>If Guix is not already installed, go grab the
<a href="https://git.savannah.gnu.org/cgit/guix.git/plain/etc/guix-install.sh">installation script</a>
and run it as <code>sudo bash guix-install.sh</code>.</p><p>The script creates <code>/gnu/store/</code> and <code>/var/guix/</code> and configures a system service
for <code>guix-daemon</code>. By default the daemon runs from the <code>root</code> users Guix; we
won't be using the root account in this guide, so let's start by making the
guix-daemon service refer to our local user <code>alice</code> instead.</p><pre><code class="language-sh">sudo sed -i 's/root/alice/' /etc/systemd/system/guix-daemon.service</code></pre><p>Now every time Alice runs 'guix pull', the daemon gets updated too. If you
installed Guix just now, make sure to run <code>guix pull</code> before proceeding further.</p><p>Next we'll add some lines to Alices <code>.bash_profile</code> to set up PATH and related
variables:</p><p><code>~/.bash_profile</code>:</p><pre><code class="language-sh">GUIX_PROFILE="${HOME}/.guix-profile"
[[ -L "${GUIX_PROFILE}" ]] && . "${GUIX_PROFILE}/etc/profile"
export PATH="${HOME}/.config/guix/current/bin:${PATH}"
export INFOPATH="${HOME}/.config/guix/current/share/info:${INFOPATH}"
export MANPATH="${HOME}/.guix-profile/share/man:/usr/share/man"
export XDG_CONFIG_DIRS="${HOME}/.desktop-profile/etc/xdg:${HOME}/.guix-profile/etc/xdg"
export XDG_DATA_DIRS="${HOME}/.desktop-profile/share:${HOME}/.guix-profile/share"</code></pre><p>This will look familiar if you have used Guix on a foreign distribution before.
The <code>XDG_</code> variables tell desktop environments where to look for installed
programs and things like autostart files: we want minimal interference from the
host system, so we "hard code" them to refer to just our Guix profiles.</p><p>We will install Xfce and related programs to a
<a href="https://guix.gnu.org/cookbook/en/html_node/Guix-Profiles-in-Practice.html">separate Guix profile</a>
that can be updated and rolled back independently of the main user profile.
That allows us to distinguish between "stable desktop environment" and "end user
packages". To keep things manageable, we create a <em>manifest</em> for the desktop
profile that can be kept in version control, and which allows us to reproduce
the exact same environment in the future (even on a different computer!).</p><p><code>~/desktop-manifest.scm</code>:</p><pre><code class="language-scheme">(specifications->manifest
'("xfce" "xfce4-session" "xfconf" "xfce4-battery-plugin"
"pulseaudio" "xfce4-volumed-pulse" "xfce4-notifyd"
;; Helpful graphical programs.
"mousepad" "orage"
;; System configuration utilities.
"xbacklight" "pavucontrol" "stow"
;; For HTTPS access.
"nss-certs"
;; These utilities are provided by the host, but we want the Guix versions
;; because they are likely better integrated and up to date.
"fontconfig" "bash-completion" "gnupg" "man-db" "git"))</code></pre><p>Create the initial profile generation:</p><pre><code class="language-sh">guix package -p ~/.desktop-profile -m ~/desktop-manifest.scm</code></pre><p>That installs a union of all packages listed in the manifest to
<code>~/.desktop-profile</code>, and creates a script we will use to "activate" it later.
To update this profile, simply invoke the same command again after running
<code>guix pull</code> or modifying the manifest.</p><p>Before Xfce can be started, we need to create a configuration file for the X
server to ensure the host executable is used, and we will tell it to to stay
on virtual terminal 4. We also create a <code>.xinitrc</code> script that automatically
starts Xfce every time <code>xinit</code> is invoked.</p><p><code>~/.xserverrc</code>:</p><pre><code class="language-sh">exec /usr/bin/Xorg -novtswitch -nolisten tcp "$@" vt$XDG_VTNR</code></pre><p><code>~/.xinitrc</code>:</p><pre><code class="language-sh">#!/bin/sh
# Get the default xinit configuration for CentOS.
. /etc/X11/xinit/xinitrc-common
exec startxfce4</code></pre><p><code>.xinitrc</code> needs to be executable:</p><pre><code class="language-sh">chmod +x ~/.xinitrc</code></pre><p>Now let's activate the desktop profile and start the X server, using ":1" as
<code>DISPLAY</code> (remember that we have another X server running on VT2, occupying the
default ":0" display).</p><pre><code class="language-sh">GUIX_PROFILE=~/.desktop-profile
source ~/.desktop-profile/etc/profile
xinit -- :1</code></pre><p>Cool, we're in Xfce! Let's open a terminal and install a browser & some fonts:</p><pre><code class="language-sh">guix install icecat font-liberation font-dejavu</code></pre><p>To make the newly installed fonts available right away we need to invoke <code>fc-cache</code>:</p><pre><code class="language-sh">fc-cache -rv</code></pre><p>Finally, we'll configure the shell to source scripts installed by Guix so that
bash completions and similar work, by adding these lines at the end of <code>.bashrc</code>:</p><p><code>~/.bashrc</code>:</p><pre><code class="language-sh"># Source the Guix shell configuration directories, for vte.sh and bash completions.
GUIX_PROFILES=("${HOME}/.desktop-profile"
"${HOME}/.guix-profile"
"${HOME}/.config/guix/current")
for profile in "${GUIX_PROFILES[@]}"; do
for dir in "${profile}/etc/bash_completion.d" "${profile}/etc/profile.d"; do
if [[ -d "${dir}" ]]; then
for f in "${dir}"/*; do
. $f
done
fi
done
done</code></pre><p>Phew! It took some work, but by now you should have a working Xfce desktop
environment, with bash completions and all. If you are content with starting
it manually, skip to "final tweaks" below. Otherwise, read on.</p><p>(If you do not have a working desktop after following these steps, please email
<code>guix-devel@gnu.org</code> so we can adjust the tutorial!)</p><h4>Starting Xfce automatically on boot</h4><p>We can configure our login shell to run <code>xinit</code> every time we log in to VT4 by
adding these lines at the end of <code>~/.bash_profile</code>:</p><pre><code class="language-sh"># Start Xorg on display :1 when logged in to VT4, unless DISPLAY is already set.
if [[ -z "${DISPLAY}" && "${XDG_VTNR}" == 4 ]]; then
GUIX_PROFILE="${HOME}/.desktop-profile"
source "${HOME}/.desktop-profile/etc/profile"
exec xinit -- :1
fi</code></pre><p>To avoid the need for typing username and password at the console, instruct the
<code>getty</code> service for TTY4 to automatically log in user 'alice':</p><p><code>/etc/systemd/system/getty@tty4.service.d/override.conf</code>:</p><pre><code>[Unit]
After=graphical.target
[Service]
# Delay for a few seconds, to ensure the Xorg server on VT2 starts first.
ExecStartPre=/bin/sleep 3
ExecStart=
ExecStart=-/sbin/agetty --autologin alice --noclear %I $TERM
Restart=on-success</code></pre><p>Now just switching to VT4 will start Xfce! To do this when the system boots,
simply enable the <code>getty@tty4</code> service:</p><pre><code class="language-sh">sudo systemctl enable getty@tty4.service</code></pre><h2>Final tweaks</h2><p>Some issues were found during usage of the Xfce environment. Launching programs
from the file manager failed because <code>gio-launch-desktop</code> was unavailable, and
xfce4-terminal complained that the shell function <code>__vte_prompt_command</code> was not
found.</p><p>These problems will be fixed in Guix eventually, but for now we'll work around
them by adding the <code>glib:bin</code> and <code>vte</code> packages to our manifest:</p><p><code>~/desktop-manifest.scm</code>:</p><pre><code class="language-scheme">(specifications->manifest
'("xfce" "xfce4-session" "xfconf" "xfce4-battery-plugin"
...
"glib:bin" ;for 'gio-launch-desktop'
"vte")) ;for vte.sh, required by xfce4-terminal</code></pre><p>We also found that closing the lid would not send the system to sleep, even
though <code>xfce4-power-manager --dump</code> showed no problems. To work around it,
we told systemd to ignore any "inhibitors" and take care of lid handling itself:</p><p><code>/etc/systemd/logind.conf</code>:</p><pre><code>HandleLidSwitch=suspend
LidSwitchIgnoreInhibited=yes</code></pre><p>Additionally it is
<a href="https://guix.gnu.org/manual/en/html_node/Application-Setup.html#Name-Service-Switch-1">strongly recommended</a>
to enable the <em>name service cache daemon</em> if not already running. On CentOS
this can be done by:</p><pre><code class="language-sh">sudo yum install nscd</code></pre><h4>Bonus section: Installing programs with a custom build of Qt</h4><p>One additional issue was that Qt programs did not work due to the
<a href="https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/packages/qt.scm?id=5544f1e3ea9a98f7d277b7ac76734b84b03df7f6#n445">stock CentOS kernel being too old</a>.
Specifically it lacks the <code>renameat2()</code> system call. Luckily Qt can be configured
not to use it. A <a href="https://issues.guix.gnu.org/issue/38210">patch has been submitted</a> to
Guix, but since we are in a hurry, we will add a procedure to our manifest so
we can use Qt programs (here <code>wpa-supplicant-gui</code>) until the Guix fix is merged:</p><p><code>~/.desktop-manifest.scm</code>:</p><pre><code class="language-scheme">(use-modules (guix packages)
(guix utils)
(gnu)
(gnu packages admin)
(gnu packages qt))
(define qtbase/fixed
(package/inherit
qtbase
(arguments
(substitute-keyword-arguments (package-arguments qtbase)
((#:phases phases)
`(modify-phases ,phases
(add-after 'unpack 'disable-renameat2
(lambda _
;; Mimic the '-no-feature-renameat2' configure flag.
(substitute* "src/corelib/configure.json"
(("config\\.linux && tests\\.renameat2")
"false"))
#t))))))))
(define with-fixed-qt
;; This procedure recursively rewrites any references to 'qtbase'
;; with our patched version.
(package-input-rewriting `((,qtbase . ,qtbase/fixed))))
(packages->manifest
(append (list (with-fixed-qt wpa-supplicant-gui))
(map specification->package
'("xfce" "xfce4-session" "xfconf" "xfce4-battery-plugin"
...))))</code></pre><p>...and now <code>wpa_gui</code> works after installing the new manifest!</p><h4>Acknowledgements</h4><p>Special thanks to <a href="https://www.osac.no/">Ocean Space Acoustics AS</a> for sponsoring this work.</p><h4>About GNU Guix</h4><p><a href="https://www.gnu.org/software/guix">GNU Guix</a> is a transactional package
manager and an advanced distribution of the GNU system that <a href="https://www.gnu.org/distros/free-system-distribution-guidelines.html">respects
user
freedom</a>.
Guix can be used on top of any system running the kernel Linux, or it
can be used as a standalone operating system distribution for i686,
x86_64, ARMv7, and AArch64 machines.</p><p>In addition to standard package management features, Guix supports
transactional upgrades and roll-backs, unprivileged package management,
per-user profiles, and garbage collection. When used as a standalone
GNU/Linux distribution, Guix offers a declarative, stateless approach to
operating system configuration management. Guix is highly customizable
and hackable through <a href="https://www.gnu.org/software/guile">Guile</a>
programming interfaces and extensions to the
<a href="http://schemers.org">Scheme</a> language.</p>