Allow changing xdg-user-dirs with environment.etc#67389
Allow changing xdg-user-dirs with environment.etc#67389jtojnar merged 2 commits intoNixOS:masterfrom
Conversation
XDG_CONFIG_DIRS should contain directories ordered by priority so if we want users to be able to customize the defaults, we need to move the shipped values to the end.
Previously, we were only adding profile-relative paths to XDG_CONFIG_DIRS variable. That required very ugly hacks like NixOS#33282 (comment) to be able to configure XDG stuff. Now, we are prepending the variable with /etc/xdg, allowing us to simply use `environment.etc."xdg/…"` options.
| PAGER = mkDefault "less -R"; | ||
| EDITOR = mkDefault "nano"; | ||
| XCURSOR_PATH = [ "$HOME/.icons" ]; | ||
| XDG_CONFIG_DIRS = [ "/etc/xdg" ]; # needs to be before profile-relative paths to allow changes through environment.etc |
There was a problem hiding this comment.
Perhaps explain the why as in the directories are ordered by priority.
There was a problem hiding this comment.
Does not the need to be first already imply the precedence relation? If you come up with a clearer comment, feel free to change it.
|
I don't know if this brings a side-effect to gnome... but I noticed that the bookmarks in nautilus (in the left sidebar in the screenshot) dissappeared. It used to be a bookmark to documents, downloads, pictures, music and video folders... |
|
Good eye. It appears that the generated file is wrong. $ cat ~/.config/user-dirs.dirs
# This file is written by xdg-user-dirs-update
# If you want to change or add directories, just edit the line you're
# interested in. All local changes will be retained on the next run.
# Format is XDG_xxx_DIR="$HOME/yyy", where yyy is a shell-escaped
# homedir-relative path, or XDG_xxx_DIR="/yyy", where /yyy is an
# absolute path. No other format is supported.
#
XDG_XDG_DESKTOP_DIR_DIR="$HOME/system/desktop"
XDG_XDG_DOWNLOAD_DIR_DIR="$HOME/downloads"
XDG_XDG_TEMPLATES_DIR_DIR="$HOME/system/templates"
XDG_XDG_PUBLICSHARE_DIR_DIR="$HOME/system/public"
XDG_XDG_DOCUMENTS_DIR_DIR="$HOME/documents"
XDG_XDG_MUSIC_DIR_DIR="$HOME/media/music"
XDG_XDG_PICTURES_DIR_DIR="$HOME/media/photos"
XDG_XDG_VIDEOS_DIR_DIR="$HOME/media/video"Looking at the preset reveals where the problem is: $ cat $(nix-build -A xdg-user-dirs)/etc/xdg/user-dirs.defaults
# Default settings for user directories
#
# The values are relative pathnames from the home directory and
# will be translated on a per-path-element basis into the users locale
DESKTOP=Desktop
DOWNLOAD=Downloads
TEMPLATES=Templates
PUBLICSHARE=Public
DOCUMENTS=Documents
MUSIC=Music
PICTURES=Pictures
VIDEOS=Videos
# Another alternative is:
#MUSIC=Documents/Music
#PICTURES=Documents/Pictures
#VIDEOS=Documents/Videos |
|
Yes.. it can be fixed is using the following instead: |
|
I also tested with localization in place.. and that works too.. the directories get translated into the current interface language |
|
this may have been merged prematurely. A nixos-rebuild fails unless i revert 4842683 |
|
Hi @nrdxp. Could you open a bug showing us the output in nixos-rebuild showing the failure and what nixpkgs revision you are building off? And relevant parts of the configuration.nix would be helpful as well. |
|
I just rebased a few moments ago to see if the issue was still happening. Here is the output rev:bfcab9807440410715c0167b408b22faf39b8f9b Sorry @worldofpeace, should have done that from the start. I can't seem to find anything in my configuration that changes anything. I will continue to fiddle with it, and if I find the cause I'll file a bug or pr if I can fix it. edit: never mind, I haven't had time to look at this until now but it looks like I declared XDG_CONFIG_DIRS myself in one of my sessionVariables. I have them defined in multiple places so I didn't notice right away. So sorry for the false positive. |
|
@nrdxp Thanks for responding. |
|
@nrdxp Could you run the following commands and compare output: $ nixos-option -I nixos-config=/etc/nixos/configuration.nix environment.profileRelativeEnvVars
Value:
{ GTK_PATH = [ "/lib/gtk-2.0" "/lib/gtk-3.0" ]; INFOPATH = [ "/info" "/share/info" ]; KDEDIRS = [ "" ]; LIBEXEC_PATH = [ "/lib/libexec" ]; MOZ_PLUGIN_PATH = [ "/lib/mozilla/plugins" ]; PATH = [ "/bin" ]; QTWEBKIT_PLUGIN_PATH = [ "/lib/mozilla/plugins/" ]; QT_PLUGIN_PATH = [ "/lib/qt4/plugins" "/lib/kde4/plugins" ]; STRIGI_PLUGIN_PATH = [ "/lib/strigi/" ]; TERMINFO_DIRS = [ "/share/terminfo" ]; XCURSOR_PATH = [ "/share/icons" ]; XDG_CONFIG_DIRS = [ "/etc/xdg" ]; XDG_DATA_DIRS = [ "/share" ]; }
Default:
Example:
{ MANPATH = <CODE>; PATH = <CODE>; }
Description:
"Attribute set of environment variable. Each attribute maps to a list\nof relative paths. Each relative path is appended to the each profile\nof <option>environment.profiles</option> to form the content of the\ncorresponding environment variable.\n"
Declared by:
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/shells-environment.nix"
Defined by:
"/home/jtojnar/Projects/nixpkgs/nixos/modules/programs/environment.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/terminfo.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/xdg/icons.nix"
$ nixos-option -I nixos-config=/etc/nixos/configuration.nix environment.variables
Value:
{ EDITOR = "nano"; GIO_EXTRA_MODULES = "/nix/store/zhg3wxraigg0641shcwjlylhalbly2f2-glib-networking-2.60.3/lib/gio/modules:/nix/store/18mwsrq6jibxxialf4gnc8rci8v8vry5-gvfs-1.40.2/lib/gio/modules:/nix/store/096bc8rx25hf08ra16xny5vkyli21958-dconf-0.32.0-lib/lib/gio/modules"; GNOME_SESSION_DEBUG = ""; GTK3_MODULES = "/nix/store/s394svl2s5hqwzgkh1dx238xinfa4fwl-plotinus-0.2.0/lib/libplotinus.so"; LANG = "en_US.UTF-8"; LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; NAUTILUS_EXTENSION_DIR = "/nix/store/qqp8a7pmf0xk5pbn93cfj5n7gkd55di2-system-path/lib/nautilus/extensions-3.0"; NIXPKGS_CONFIG = "/etc/nix/nixpkgs-config.nix"; NIX_DEBUG_INFO_DIRS = "/run/current-system/sw/lib/debug"; NIX_GSETTINGS_OVERRIDES_DIR = "/nix/store/aj6sb1k03div0xkysi1dlgjjvvz6iqfv-nixos-gsettings-desktop-schemas/share/gsettings-schemas/nixos-gsettings-overrides/glib-2.0/schemas"; NIX_PATH = "nixpkgs=/home/jtojnar/Projects/nixpkgs"; PAGER = "less -R"; SSH_ASKPASS = "/nix/store/g0z7jv97qz46y4nq2f9lkw70dfmc3s1b-x11-ssh-askpass-1.2.4.1/libexec/x11-ssh-askpass"; TZDIR = "/etc/zoneinfo"; XCURSOR_PATH = "$HOME/.icons"; XDG_CONFIG_DIRS = "/etc/xdg"; XDG_DATA_DIRS = "/nix/store/91r5ws722rq6kvn3hqqlwl323cmsgh2r-gnome-mimeapps/share:/nix/store/s394svl2s5hqwzgkh1dx238xinfa4fwl-plotinus-0.2.0/share/gsettings-schemas/plotinus-0.2.0"; XDG_DESKTOP_PORTAL_PATH = "/nix/store/jvl72xd955hlp6pr6yyrbxs34slaa490-xdg-desktop-portal-gtk-1.4.0/share/xdg-desktop-portal/portals"; }
Default:
{ }
Example:
{ EDITOR = "nvim"; VISUAL = "nvim"; }
Description:
"A set of environment variables used in the global environment.\nThese variables will be set on shell initialisation (e.g. in /etc/profile).\nThe value of each variable can be either a string or a list of\nstrings. The latter is concatenated, interspersed with colon\ncharacters.\n"
Declared by:
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/shells-environment.nix"
Defined by:
"/home/jtojnar/Projects/nixpkgs/nixos/modules/services/x11/desktop-managers/gnome3.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/services/desktops/gnome3/glib-networking.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/services/desktops/gvfs.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/programs/ssh.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/programs/plotinus.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/programs/environment.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/programs/dconf.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/shells-environment.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/xdg/portal.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/debug-info.nix"
$ nixos-option -I nixos-config=/etc/nixos/configuration.nix environment.sessionVariables
Value:
{ LANG = "en_US.UTF-8"; LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive"; NIX_PATH = "nixpkgs=/home/jtojnar/Projects/nixpkgs"; TZDIR = "/etc/zoneinfo"; }
Default:
{ }
Example:
Description:
"A set of environment variables used in the global environment.\nThese variables will be set by PAM.\nThe value of each variable can be either a string or a list of\nstrings. The latter is concatenated, interspersed with colon\ncharacters.\n"
Declared by:
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/system-environment.nix"
Defined by:
"/home/jtojnar/Projects/nixpkgs/nixos/modules/services/misc/nix-daemon.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/hardware/opengl.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/networking.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/locale.nix"
"/home/jtojnar/Projects/nixpkgs/nixos/modules/config/i18n.nix"
|


Motivation
Now you will be able to include the following to your
configuration.nixto change the default directories:Closes #33282
Elaboration
See #33282 (comment) for evolution