From d3e3cc12259e4f8f5145ae8a0dc19bae5d11a11b Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Thu, 27 Feb 2020 09:48:36 -0600 Subject: [PATCH] nixos/plasma5: Fix activation script when XDG_CONFIG_HOME is unset Fixes #80713 --- .../services/x11/desktop-managers/plasma5.nix | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/x11/desktop-managers/plasma5.nix b/nixos/modules/services/x11/desktop-managers/plasma5.nix index f3bf9268b29..60ef0159ff1 100644 --- a/nixos/modules/services/x11/desktop-managers/plasma5.nix +++ b/nixos/modules/services/x11/desktop-managers/plasma5.nix @@ -52,6 +52,8 @@ let ''; activationScript = '' + ${set_XDG_CONFIG_HOME} + # The KDE icon cache is supposed to update itself automatically, but it uses # the timestamp on the icon theme directory as a trigger. This doesn't work # on NixOS because the timestamp never changes. As a workaround, delete the @@ -62,7 +64,7 @@ let # xdg-desktop-settings generates this empty file but # it makes kbuildsyscoca5 fail silently. To fix this # remove that menu if it exists. - rm -fv ''${XDG_CONFIG_HOME:?}/menus/applications-merged/xdg-desktop-menu-dummy.menu + rm -fv ''${XDG_CONFIG_HOME}/menus/applications-merged/xdg-desktop-menu-dummy.menu # Qt writes a weird ‘libraryPath’ line to # ~/.config/Trolltech.conf that causes the KDE plugin @@ -71,7 +73,7 @@ let # disastrous, so here we nuke references to the Nix store # in Trolltech.conf. A better solution would be to stop # Qt from doing this wackiness in the first place. - trolltech_conf="''${XDG_CONFIG_HOME:?}/Trolltech.conf" + trolltech_conf="''${XDG_CONFIG_HOME}/Trolltech.conf" if [ -e "$trolltech_conf" ]; then ${sed} -i "$trolltech_conf" -e '/nix\\store\|nix\/store/ d' fi @@ -84,10 +86,20 @@ let ${pkgs.libsForQt5.kservice}/bin/kbuildsycoca5 ''; + set_XDG_CONFIG_HOME = '' + # Set the default XDG_CONFIG_HOME if it is unset. + # Per the XDG Base Directory Specification: + # https://specifications.freedesktop.org/basedir-spec/latest + # 1. Never export this variable! If it is unset, then child processes are + # expected to set the default themselves. + # 2. Contaminate / if $HOME is unset; do not check if $HOME is set. + XDG_CONFIG_HOME=''${XDG_CONFIG_HOME:-$HOME/.config} + ''; + startplasma = '' - export XDG_CONFIG_HOME="''${XDG_CONFIG_HOME:-$HOME/.config}" - mkdir -p "''${XDG_CONFIG_HOME:?}" + ${set_XDG_CONFIG_HOME} + mkdir -p "''${XDG_CONFIG_HOME}" '' + optionalString pulseaudio.enable '' @@ -100,10 +112,10 @@ let ${activationScript} # Create default configurations if Plasma has never been started. - kdeglobals="''${XDG_CONFIG_HOME:?}/kdeglobals" + kdeglobals="''${XDG_CONFIG_HOME}/kdeglobals" if ! [ -f "$kdeglobals" ] then - kcminputrc="''${XDG_CONFIG_HOME:?}/kcminputrc" + kcminputrc="''${XDG_CONFIG_HOME}/kcminputrc" if ! [ -f "$kcminputrc" ] then cat ${kcminputrc} >"$kcminputrc" @@ -115,7 +127,7 @@ let cat ${gtkrc2} >"$gtkrc2" fi - gtk3_settings="''${XDG_CONFIG_HOME:?}/gtk-3.0/settings.ini" + gtk3_settings="''${XDG_CONFIG_HOME}/gtk-3.0/settings.ini" if ! [ -f "$gtk3_settings" ] then mkdir -p "$(dirname "$gtk3_settings")"