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

Don't add paths to XDG_DATA_DIRS before /run/current-system/sw/share #282076

Closed
Freed-Wu opened this issue Jan 19, 2024 · 6 comments
Closed

Don't add paths to XDG_DATA_DIRS before /run/current-system/sw/share #282076

Freed-Wu opened this issue Jan 19, 2024 · 6 comments
Labels
2.status: wontfix We cannot or will not fix this issue

Comments

@Freed-Wu
Copy link
Contributor

Freed-Wu commented Jan 19, 2024

Actual Behavior

In [1]: from platformdirs import site_data_dir
In [2]: site_data_dir()
'/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share'
❯ perl -p -e's/:/\n/g' <<< $XDG_DATA_DIRS
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share
/nix/store/gfp30ph6l28vz62ggcl7j2b5sp22j1hy-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0
/nix/store/8yicinmsnqmlkgvmzh468bi0bsap0fix-gtk+3-3.24.39/share/gsettings-schemas/gtk+3-3.24.39
/nix/store/srry3z6y26hvdr46v13sl0i20n9nkvic-libgnomekbd-3.28.1/share/gsettings-schemas/libgnomekbd-3.28.1
/nix/store/fv3hq3i74vqx20lni9lzr84h4qnvys3v-colord-1.4.6/share/gsettings-schemas/colord-1.4.6
/nix/store/yjjcyrvm46j7q7z50fnl1wnrbh86fkid-libgweather-4.4.0/share/gsettings-schemas/libgweather-4.4.0
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1
/run/current-system/sw/share
/nix/store/46g6vlqrxd80v4mz7hlvvhibbhyym8v9-gnome-mimeapps/share
/nix/store/s2z7sf8vs420i0l8c45brgpmv49kh38q-desktops/share
/home/wzy/.nix-profile/share
/nix/profile/share
/home/wzy/.local/state/nix/profile/share
/etc/profiles/per-user/wzy/share
/nix/var/nix/profiles/default/share
/run/current-system/sw/share
/nix/store/xfb4mv7zabj9wwfqy21yxmvkxbnnvrbz-gnome-shell-45.3/share/gsettings-schemas/gnome-shell-45.3
/nix/store/q5bflv6km2d30f3hsz63ggmn7plyql7l-gnome-shell-extensions-45.2/share/gsettings-schemas/gnome-shell-extensions-45.2
/nix/store/wcfb9jx6v9dj2k625qd0ki0n33jbrbjr-gnome-session-45.0/share
/nix/store/gfp30ph6l28vz62ggcl7j2b5sp22j1hy-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0
/nix/store/8yicinmsnqmlkgvmzh468bi0bsap0fix-gtk+3-3.24.39/share/gsettings-schemas/gtk+3-3.24.39
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1
/nix/store/wcfb9jx6v9dj2k625qd0ki0n33jbrbjr-gnome-session-45.0/share/gsettings-schemas/gnome-session-45.0
/nix/store/xfb4mv7zabj9wwfqy21yxmvkxbnnvrbz-gnome-shell-45.3/share

Expected Behavior

In [1]: from platformdirs import site_data_dir
In [2]: site_data_dir()
'/run/current-system/sw/share'
❯ perl -p -e's/:/\n/g' <<< $XDG_DATA_DIRS
/run/current-system/sw/share
/nix/store/46g6vlqrxd80v4mz7hlvvhibbhyym8v9-gnome-mimeapps/share
/nix/store/s2z7sf8vs420i0l8c45brgpmv49kh38q-desktops/share
/home/wzy/.nix-profile/share
/nix/profile/share
/home/wzy/.local/state/nix/profile/share
/etc/profiles/per-user/wzy/share
/nix/var/nix/profiles/default/share
/run/current-system/sw/share
/nix/store/xfb4mv7zabj9wwfqy21yxmvkxbnnvrbz-gnome-shell-45.3/share/gsettings-schemas/gnome-shell-45.3
/nix/store/q5bflv6km2d30f3hsz63ggmn7plyql7l-gnome-shell-extensions-45.2/share/gsettings-schemas/gnome-shell-extensions-45.2
/nix/store/wcfb9jx6v9dj2k625qd0ki0n33jbrbjr-gnome-session-45.0/share
/nix/store/gfp30ph6l28vz62ggcl7j2b5sp22j1hy-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0
/nix/store/8yicinmsnqmlkgvmzh468bi0bsap0fix-gtk+3-3.24.39/share/gsettings-schemas/gtk+3-3.24.39
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1
/nix/store/wcfb9jx6v9dj2k625qd0ki0n33jbrbjr-gnome-session-45.0/share/gsettings-schemas/gnome-session-45.0
/nix/store/xfb4mv7zabj9wwfqy21yxmvkxbnnvrbz-gnome-shell-45.3/share
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share
/nix/store/gfp30ph6l28vz62ggcl7j2b5sp22j1hy-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0
/nix/store/8yicinmsnqmlkgvmzh468bi0bsap0fix-gtk+3-3.24.39/share/gsettings-schemas/gtk+3-3.24.39
/nix/store/srry3z6y26hvdr46v13sl0i20n9nkvic-libgnomekbd-3.28.1/share/gsettings-schemas/libgnomekbd-3.28.1
/nix/store/fv3hq3i74vqx20lni9lzr84h4qnvys3v-colord-1.4.6/share/gsettings-schemas/colord-1.4.6
/nix/store/yjjcyrvm46j7q7z50fnl1wnrbh86fkid-libgweather-4.4.0/share/gsettings-schemas/libgweather-4.4.0
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1

Technical details

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

  • system: "x86_64-linux"
  • host os: Linux 6.7.0, NixOS, 24.05 (Uakari), 24.05pre572380.842d9d80cfd4
  • multi-user?: yes
  • sandbox: yes
  • version: nix-env (Nix) 2.18.1
  • channels(wzy): "json-c-0.16, librime-1.8.5"
  • channels(root): "nixos"
  • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos
@Freed-Wu
Copy link
Contributor Author

I think all code like

export XDG_DATA_DIRS=${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}:$XDG_DATA_DIRS

should be changed to

export XDG_DATA_DIRS=$XDG_DATA_DIRS:${gsettings-desktop-schemas}/share/gsettings-schemas/${gsettings-desktop-schemas.name}

to avoid this bug.

@MatthewCash
Copy link
Contributor

While the first entry in $XDG_DATA_DIRS is supposed to be the most "important", it seems naive for platformdirs to only consider the first one. I think the library supports returning the entire list, so it would probably be best to retrieve and try all entries in your application.

@Freed-Wu
Copy link
Contributor Author

Why we don't make all /nix/stores are after /run/current-system/sw/share? That is

❯ perl -p -e's/:/\n/g' <<< $XDG_DATA_DIRS
# All paths not prefixed `/nix/store`
/run/current-system/sw/share
/home/wzy/.nix-profile/share
/nix/profile/share
/home/wzy/.local/state/nix/profile/share
/etc/profiles/per-user/wzy/share
/nix/var/nix/profiles/default/share
/run/current-system/sw/share
# All paths prefixed `/nix/store`
/nix/store/46g6vlqrxd80v4mz7hlvvhibbhyym8v9-gnome-mimeapps/share
/nix/store/s2z7sf8vs420i0l8c45brgpmv49kh38q-desktops/share
/nix/store/xfb4mv7zabj9wwfqy21yxmvkxbnnvrbz-gnome-shell-45.3/share/gsettings-schemas/gnome-shell-45.3
/nix/store/q5bflv6km2d30f3hsz63ggmn7plyql7l-gnome-shell-extensions-45.2/share/gsettings-schemas/gnome-shell-extensions-45.2
/nix/store/wcfb9jx6v9dj2k625qd0ki0n33jbrbjr-gnome-session-45.0/share
/nix/store/gfp30ph6l28vz62ggcl7j2b5sp22j1hy-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0
/nix/store/8yicinmsnqmlkgvmzh468bi0bsap0fix-gtk+3-3.24.39/share/gsettings-schemas/gtk+3-3.24.39
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1
/nix/store/wcfb9jx6v9dj2k625qd0ki0n33jbrbjr-gnome-session-45.0/share/gsettings-schemas/gnome-session-45.0
/nix/store/xfb4mv7zabj9wwfqy21yxmvkxbnnvrbz-gnome-shell-45.3/share
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share
/nix/store/gfp30ph6l28vz62ggcl7j2b5sp22j1hy-gsettings-desktop-schemas-45.0/share/gsettings-schemas/gsettings-desktop-schemas-45.0
/nix/store/8yicinmsnqmlkgvmzh468bi0bsap0fix-gtk+3-3.24.39/share/gsettings-schemas/gtk+3-3.24.39
/nix/store/srry3z6y26hvdr46v13sl0i20n9nkvic-libgnomekbd-3.28.1/share/gsettings-schemas/libgnomekbd-3.28.1
/nix/store/fv3hq3i74vqx20lni9lzr84h4qnvys3v-colord-1.4.6/share/gsettings-schemas/colord-1.4.6
/nix/store/yjjcyrvm46j7q7z50fnl1wnrbh86fkid-libgweather-4.4.0/share/gsettings-schemas/libgweather-4.4.0
/nix/store/0d8y8z780dpn9lnn3gw6bmyax1hf5x9f-gnome-settings-daemon-45.1/share/gsettings-schemas/gnome-settings-daemon-45.1

In different languages, there are different libraries to support XDG. At least we do some change to make all /nix/store/* to be the last of XDG_DATA_DIRS can support all libraries without changing their code.

@jtojnar jtojnar added the 2.status: wontfix We cannot or will not fix this issue label Jan 27, 2024
@jtojnar
Copy link
Member

jtojnar commented Jan 27, 2024

Yeah, I think platformdirs.site_data_dir returning a single path makes no sense with regards to XDG basedir specification:

There is a set of preference ordered base directories relative to which data files should be searched. This set of directories is defined by the environment variable $XDG_DATA_DIRS.

The reason why wrappers prefix derivation’s own paths to environment variables is to make the derivations more hermetic. If global paths took precedence, apps would load possibly inconsistent global data.

@jtojnar jtojnar closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2024
@Freed-Wu
Copy link
Contributor Author

Hey, the maintainers of platformdirs @gaborbernat, @ofek, How can we get global path /run/current-system/sw/share by platformdirs.site_data_dir without changing XDG_DATA_DIRS?

@jtojnar
Copy link
Member

jtojnar commented Jan 28, 2024

Looking at the platformdirs API, you can pass multipath=True kwarg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: wontfix We cannot or will not fix this issue
Projects
None yet
Development

No branches or pull requests

3 participants