Skip to content

Nix shell environment should append to $XDG_DATA_DIRS default value if the variable is not defined #6098

@TotallyNotChase

Description

@TotallyNotChase

Is your feature request related to a problem? Please describe.
According to the spec $XDG_DATA_DIRS defaults to /usr/local/share:/usr/share if it's not explicitly set. So consider a barebones config'd system where $XDG_DATA_DIRS is not set. Most apps still work just fine since they just use the default. But whenever I do nix-shell, it tries to append the nix store specific data dir to the non existent $XDG_DATA_DIRS variable - so now $XDG_DATA_DIRS gets set to a value that just contains the nix store path and not the default path.

This means that when I start up a gtk app from my own system that is not included within the nix derivation, I get errors like "GSETTINGS schemas are not installed". I realize that I could just include every single dependency in the nix derivation to fix this. But I'd rather prefer using what I already have on my system.

Example:-
I'm on an arch linux machine with minimal config. $XDG_DATA_DIRS is not defined in my environment. But I do have all the schemas needed in /usr/share/. So VSCode works fine here. However, after I do nix-shell with a minimal shell.nix-

{ pkgs ? import <nixpkgs> {} }:
  pkgs.mkShell {
    nativeBuildInputs = [ ];
}

I notice that $XDG_DATA_DIRS is now set to /nix/store/<hash>-patchelf-0.14.3/share. I fire up VSCode and it just dies whenever it needs to access GSETTINGS schemas.

Describe the solution you'd like
Prior to appending paths to $XDG_DATA_DIRS, if the variable is not defined already, it should be set to /usr/local/share:/usr/share first.

Describe alternatives you've considered
I could add gtk dependencies and wrapGAppHook to the nix shell. Or, more likely, I could define $XDG_DATA_DIRS to its default value explicitly. So that nix appends to that default value, preserving both the nix store path and the system path.

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions