How to set the bookmarks in Nautilus?

The file is ~/.config/gtk-3.0/bookmarks and according to Gtk.Settings /etc/xdg/gtk-3.0/bookmarks should be the system-wide path. But it doesn’t work.

1 Like

I do not see any mention of bookmarks being considered settings.

Checking the source code, Nautilus only looks at the GTK 3 bookmark file inside XDG_CONFIG_HOME/~/.config. Plus the legacy one in the home directory:

GTK itself does the same:

Oh, got it, thanks! So Nautilus just uses the GTK setting directory for bookmark but doesn’t use the system-wide path.

1 Like

I’ve opened an issue for nautilus: System-wide configuration of bookmarks not possible (#3640) · Issues · GNOME / Files · GitLab

1 Like

Example of setting user-specific bookmarks, if it doesn’t have to be system-wide:

  home-manager.users.you = {
    xdg.configFile."gtk-3.0/bookmarks".force = true;
    xdg.configFile."gtk-3.0/bookmarks".text = ''
      file:///home/you/Documents Documents
      ...
    '';
  };

The force is an alternative to setting home-manager.backupFileExtension (which comes with its own set of issues).

FYI there’s an HM option for this. Snippet from my config:

{
  gtk.gtk3 = {
    bookmarks = [
      "file://${config.xdg.userDirs.documents}"
      "file://${config.xdg.userDirs.download}"
      "file://${config.services.syncthing.settings.folders."sync".path}"
      "file://${config.varden.flakeDir}"
    ];
  };
}
1 Like

Cool! – I noticed you need to declare home-manager.backupFileExtension and set gtk.enable = true for that to work.

The xdg variables would be nice to have. Can you share how you make config available in the module? I get an error of either config or config.xdg.userDirs to be missing.

The xdg variables would be nice to have. Can you share how you make config available in the module? I get an error of either config or config.xdg.userDirs to be missing.

Set { config, ... }: at the top of the file.

That says, userDirs is missing in config.xdg.

       error: attribute 'userDirs' missing
       at /nix/store/6lszb6wa8v067n3f0aazbsqdk3mlyz4d-source/home/peter/default.nix:40:19:
           39|       gtk3.bookmarks = [
           40|         "file://${config.xdg.userDirs.documents}"
             |                   ^
           41|         "file://${config.xdg.userDirs.music}"

Do you have something else configured that exposes the userDirs attribute? In your flake setup maybe?

I think I know what the problem is. Your config should look something like this (note the { config, ... }:):

{
  home-manager = {
    backupFileExtension = "backup";
    users.peter = { config, ... }: {
      gtk.gtk3.bookmarks = [
        "file://${config.xdg.userDirs.documents}"
        "file://${config.xdg.userDirs.music}"
      ];
    };
  };
}
1 Like

Great, thank you! That works!! :1st_place_medal: :trophy:

There’s only a single issue left: The generated paths are in English. I use a different locale and GNOME renamed the directories accordingly. :worried:

The global user-dirs defaults file explains that the names are translated. That happens at login, as explained in /run/current-system/sw/etc/xdg/user-dirs.conf. Nautilus doesn’t transparently handle this behavior, apparently.

$ cat /run/current-system/sw/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
...

Do you happen to know how to get the translated version of the paths, which correspond to the current locale?