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

Provide a way to customize the xdg-user-dirs #33282

Closed
tiramiseb opened this issue Jan 1, 2018 · 15 comments · Fixed by #67389
Closed

Provide a way to customize the xdg-user-dirs #33282

tiramiseb opened this issue Jan 1, 2018 · 15 comments · Fixed by #67389

Comments

@tiramiseb
Copy link
Contributor

The xdg-user-dirs package contains a file named etc/xdg/user-dirs.defaults.

A module allowing to customize this file would be great.

@jtojnar
Copy link
Contributor

jtojnar commented Jan 1, 2018

GNOME users, at least, already have ~/.config/user-dirs.dirs generated in their profile by the GNOME module. That would override the XDG module.

@tiramiseb
Copy link
Contributor Author

The xdg-user-dirs-update command, executed in the GNOME session script you are referring to, reads the user-dirs.defaults file, translates it if needed and places it in ~/.config/user-dirs.dirs. Yes, this is exactly what I am talking about.

If etc/xdg/user-dirs.defaults can be customized, then the GNOME session script would copy the customized one.

@lasandell
Copy link
Contributor

This looks like a duplicate of #16200.

The environment variable $XDG_CONFIG_DIRS determines the search paths for user-dirs.defaults. This is currently defined as a profile-relative path variable. For this to work, I think it would also need to define /etc/xdg as a profile non-relative path so that a module could produce the user-dirs.defaults file in that path.

@dasj19
Copy link
Contributor

dasj19 commented Aug 21, 2019

I'm also interested in a way to customize xdg-user-dirs

@jtojnar
Copy link
Contributor

jtojnar commented Aug 21, 2019

There is little need for dedicated options, you can just use

{
  environment.etc."xdg/user-dirs.defaults".text = ''
    DESKTOP=Desktop
    DOCUMENTS=Documents
    DOWNLOAD=Downloads
    MUSIC=Music
    PICTURES=Pictures
    PUBLICSHARE=Public
    TEMPLATES=Templates
    VIDEOS=Videos
  '';
}

in your configuration.nix.

@dasj19
Copy link
Contributor

dasj19 commented Aug 22, 2019

@jtojnar It does not work...
What I have tried so far in a VM:

  • removing the user homedir + nixos-rebuild switch --upgrade
  • changing environment.etc."xdg/user-dirs.conf".text to environment.etc."xdg/user-dirs.dirs".text + removing the user homedir + nixos-rebuild switch --upgrade
  • changing environment.etc."xdg/user-dirs.conf".text to environment.etc."xdg/user-dirs.default".text + removing the user homedir + nixos-rebuild switch --upgrade

I am using Gnome as a DE and the following user-dirs structure:

environment.etc."xdg/user-dirs.conf".text = ''
    XDG_DESKTOP_DIR="$HOME/system/desktop"
    XDG_DOWNLOAD_DIR="$HOME/downloads"
    XDG_TEMPLATES_DIR="$HOME/system/templates"
    XDG_PUBLICSHARE_DIR="$HOME/system/public"
    XDG_DOCUMENTS_DIR="$HOME/documents"
    XDG_MUSIC_DIR="$HOME/media/music"
    XDG_PICTURES_DIR="$HOME/media/photos"
    XDG_VIDEOS_DIR="$HOME/media/video"
  '';

@jtojnar
Copy link
Contributor

jtojnar commented Aug 22, 2019

nixos-rebuild switch --upgrade will not be enough. xdg-user-dirs relies on /etc/xdg/autostart to run so you need to re-login for it to be triggered.

@dasj19
Copy link
Contributor

dasj19 commented Aug 22, 2019

I did reboot the VM after every nixos-rebuild switch --upgrade and then logged in as the unpriviledged user

@jtojnar
Copy link
Contributor

jtojnar commented Aug 22, 2019

Hmm, apparently, it should have been user-dirs.defaults, not user-dirs.default or user-dirs.conf.

@dasj19
Copy link
Contributor

dasj19 commented Aug 24, 2019

@jtojnar ... sorry for the delay...
But I just tried with only this configuration.nix


{ config, pkgs, ... }:

{

  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
    ];

  # Use the GRUB 2 boot loader.
  boot.loader.grub.enable = true;
  boot.loader.grub.version = 2;

  # Define on which hard drive you want to install Grub.
  boot.loader.grub.device = "/dev/sda"; # or "nodev" for efi only

  networking.hostName = "nixos"; # Define your hostname.

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.layout = "es";

  # Set your time zone.
  time.timeZone = "Europe/Copenhagen";


  environment.etc."xdg/user-dirs.defaults".text = ''
    XDG_DESKTOP_DIR="$HOME/system/desktop"
    XDG_DOWNLOAD_DIR="$HOME/downloads"
    XDG_TEMPLATES_DIR="$HOME/system/templates"
    XDG_PUBLICSHARE_DIR="$HOME/system/public"
    XDG_DOCUMENTS_DIR="$HOME/documents"
    XDG_MUSIC_DIR="$HOME/media/music"
    XDG_PICTURES_DIR="$HOME/media/photos"
    XDG_VIDEOS_DIR="$HOME/media/video"
  '';

  # Enable the GNOME Desktop Environment.
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome3.enable = true;
}

And it does not use the user-dirs I configure above

@jtojnar
Copy link
Contributor

jtojnar commented Aug 24, 2019

Okay, there are several issues here:

  1. As Provide a way to customize the xdg-user-dirs #33282 (comment) correctly points out, XDG_CONFIG_DIRS is profile-relative variable and since it is set, /etc/xdg will not be used as per the spec:

If $XDG_CONFIG_DIRS is either not set or empty, a value equal to /etc/xdg should be used.

  1. We could add (pkgs.writeTextFile { name = "user-dirs.defaults"; text = "…"; destination = "/etc/xdg/user-dirs.defaults"; }) to environment.systemPackages which would add it to XDG_CONFIG_DIRS but that will conflict with the file from the preset file from the xdg-user-dirs package installed by gnome3 module.

  2. Okay, I have came up with the following abomination to add to your configuration.nix:

  imports = [
    ({lib, pkgs, ...}: {
      environment.systemPackages = lib.mkBefore [
        (pkgs.writeTextFile {
          name = "user-dirs.defaults";
          text = ''
            XDG_DESKTOP_DIR=system/desktop
            XDG_DOWNLOAD_DIR=downloads
            XDG_TEMPLATES_DIR=system/templates
            XDG_PUBLICSHARE_DIR=system/public
            XDG_DOCUMENTS_DIR=documents
            XDG_MUSIC_DIR=media/music
            XDG_PICTURES_DIR=media/photos
            XDG_VIDEOS_DIR=media/video
          '';
          destination = "/etc/xdg/user-dirs.defaults";
        })
      ];
    })
  ];

But again, it does not work. Turns out we are prefixing the XDG_CONFIG_DIRS with presets when running xdg-user-dirs-update. So we need to patch as well.

With the patch and the horrendous snippet, I can confirm the expected directories were created.

We should try to find out how to make the environment variable contain /etc/xdg before all the profile-related stuff so that the simple solution works.

jtojnar added a commit to jtojnar/nixpkgs that referenced this issue Aug 24, 2019
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
Copy link
Contributor

jtojnar commented Aug 24, 2019

#67389 now contains full fix enabling us to use environment.etc."xdg/user-dirs.defaults".text as suggested in #33282 (comment).

@dasj19
Copy link
Contributor

dasj19 commented Aug 24, 2019

Awesome @jtojnnar .... I just built from your branch https://github.com/jtojnar/nixpkgs/tree/xdg-user-dirs and works like a charm.
Thanks a lot, I owe you one

The config I'm currently using after the developments in #67389 is...

  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
  '';

@cx405
Copy link

cx405 commented Mar 17, 2023

@jtojnar @tiramiseb you probably want to reopen this, because functionality implemented here is currently broken.

Please see: #221604

@jtojnar
Copy link
Contributor

jtojnar commented Mar 24, 2023

As mentioned in the other issue, there is a prerequisite of environment.systemPackage = [ pkgs.xdg-user-dirs ] and having something that runs autostart entries (which DEs like GNOME or Plasma do out of the box).

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

Successfully merging a pull request may close this issue.

6 participants