The xdg-user-dirs package contains a file named etc/xdg/user-dirs.defaults.
A module allowing to customize this file would be great.
GNOME users, at least, already have ~/.config/user-dirs.dirs generated in their profile by the GNOME module. That would override the XDG module.
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.
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.
I'm also interested in a way to customize xdg-user-dirs
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.
@jtojnar It does not work...
What I have tried so far in a VM:
nixos-rebuild switch --upgradeenvironment.etc."xdg/user-dirs.conf".text to environment.etc."xdg/user-dirs.dirs".text + removing the user homedir + nixos-rebuild switch --upgradeenvironment.etc."xdg/user-dirs.conf".text to environment.etc."xdg/user-dirs.default".text + removing the user homedir + nixos-rebuild switch --upgradeI 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"
'';
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.
I did reboot the VM after every nixos-rebuild switch --upgrade and then logged in as the unpriviledged user
Hmm, apparently, it should have been user-dirs.defaults, not user-dirs.default or user-dirs.conf.
@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
Okay, there are several issues here:
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_DIRSis either not set or empty, a value equal to /etc/xdg should be used.
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.
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.
https://github.com/NixOS/nixpkgs/pull/67389 now contains full fix enabling us to use environment.etc."xdg/user-dirs.defaults".text as suggested in https://github.com/NixOS/nixpkgs/issues/33282#issuecomment-523572259.
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
'';
Most helpful comment
https://github.com/NixOS/nixpkgs/pull/67389 now contains full fix enabling us to use
environment.etc."xdg/user-dirs.defaults".textas suggested in https://github.com/NixOS/nixpkgs/issues/33282#issuecomment-523572259.