Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow changing xdg-user-dirs with environment.etc #67389

Merged
merged 2 commits into from Aug 24, 2019

Conversation

jtojnar
Copy link
Contributor

@jtojnar jtojnar commented Aug 24, 2019

Motivation

Now you will be able to include the following to your configuration.nix to change the default directories:

{
  environment.etc."xdg/user-dirs.defaults".text = ''
    DESKTOP=system/desktop
    DOWNLOAD=downloads
    TEMPLATES=system/templates
    PUBLICSHARE=system/public
    DOCUMENTS=documents
    MUSIC=media/music
    PICTURES=media/photos
    VIDEOS=media/video
  '';
}

Closes #33282

Elaboration

See #33282 (comment) for evolution

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.
@jtojnar jtojnar changed the title xdg-user-dirs: deprioritize shipped configs Allow changing xdg-user-dirs with environment.etc Aug 24, 2019
@@ -21,6 +21,7 @@ in
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps explain the why as in the directories are ordered by priority.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@worldofpeace
Copy link
Contributor

Screenshot from 2019-08-24 11 49 43

Definitely appears to work as expected.

@dasj19
Copy link
Contributor

dasj19 commented Aug 24, 2019

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...

@jtojnar
Copy link
Contributor Author

jtojnar commented Aug 24, 2019

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

@jtojnar
Copy link
Contributor Author

jtojnar commented Aug 24, 2019

With the updated config, everything is as it should be:

Screenshot from 2019-08-24 18-54-57

It is weird that the wrong defaults file still created the directories, though.

@dasj19
Copy link
Contributor

dasj19 commented Aug 24, 2019

Yes.. it can be fixed is using the following instead:

  environment.etc."xdg/user-dirs.defaults".text = ''
    DESKTOP=system/desktop
    DOWNLOAD=downloads
    TEMPLATES=system/templates
    PUBLICSHARE=system/public
    DOCUMENTS=documents
    MUSIC=media/music
    PICTURES=media/photos
    VIDEOS=media/video
  '';

@dasj19
Copy link
Contributor

dasj19 commented Aug 24, 2019

I also tested with localization in place.. and that works too.. the directories get translated into the current interface language

@jtojnar jtojnar merged commit d90aa7d into NixOS:master Aug 24, 2019
@jtojnar jtojnar deleted the xdg-user-dirs branch August 24, 2019 17:22
@nrdxp
Copy link
Contributor

nrdxp commented Aug 25, 2019

this may have been merged prematurely. A nixos-rebuild fails unless i revert 4842683

@worldofpeace
Copy link
Contributor

worldofpeace commented Aug 25, 2019

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.

@nrdxp
Copy link
Contributor

nrdxp commented Aug 26, 2019

I just rebased a few moments ago to see if the issue was still happening. Here is the output

rev:bfcab9807440410715c0167b408b22faf39b8f9b
error: The unique option `environment.variables.XDG_CONFIG_DIRS' is defined multiple times, in:
-<nixpkgs>/nixos/modules/programs/environment.nix
-<nixpkgs>/nixos/modules/config/shells-environment.nix.

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.

@worldofpeace
Copy link
Contributor

@nrdxp Thanks for responding.

@jtojnar
Copy link
Contributor Author

jtojnar commented Aug 26, 2019

@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"

nrdxp added a commit to nrdxp/nixos that referenced this pull request Aug 29, 2019
as of NixOS/nixpkgs#67389, this is declared
directly in nixpkgs.
@dasj19 dasj19 mentioned this pull request Apr 27, 2021
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to customize the xdg-user-dirs
4 participants