-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Populate $XDG_DATA_DIRS
with appropriate folder from Nix profile
#8985
Conversation
On non-NixOS systems, the default `nix` install does not populate the `$XDG_DATA_DIRS`. This populates it and enables things like bash-completion and `.desktop` file detection for `nix` profile installed packages. Signed-off-by: Ana Hobden <operator@hoverbear.org>
$XDG_DATA_DIRS
with appropriate folder from Nix profile
Triaged in Nix team meeting:
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-09-22-nix-team-meeting-minutes-88/33343/1 |
Note that in my own fix I also needed to extend the fpath for zsh: https://gitlab.com/nexxiot-labs/nix-bootstrap/-/blob/main/src/install.sh#L96-126 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it a bit more, the direction of this change seems perfectly fine to me. We may have went a bit astray in the triage discussion:
-
@edolstra How Nix deploys its own completions is somewhat of an orthogonal question here.
This PR is aiming to deploy things provided by packages, and opens one possibility for Nix to plug itself in the same way.
-
@roberth How packages expose environments is also orthogonal.
While offering a minimal (or even no dedicated) interface in Nix to coordinate with however Nixpkgs developers want it to work would be good, it doesn't matter right here. Software builds put things into their
share
output directory, profiles merge those together, so exposing those where one would expect them is appropriate. -
My own concern about Nix being too heavyweight on package management and that I find profiles somewhat awkward is also unrelated to this change.
Profiles exist,
nix profile
is still experimental so we can still change some of that, the goal to have some imperative interface to declarative configurations seems not to be contested by anyone (and @bobvanderlinden and @iFreilicht have ideas on how to actually implement that which I would subscribe to), and the problems I see are not in the outward interface of wiring up environment variables.
This PR appears to me like a strict improvement, especially because it solves an obvious end-user problem and opens up more options to solve deeper technical issues, and does not preclude making decisions in the future.
100% agree. This PR solves a huge pain that actually made me not use Nix for any GUI programs at all on my Linux installs, because this basic integration is broken. I was not aware of this PR but support its merge wholeheartedly. Will happily test it on my own Manjaro and Parabola installations later today. |
Discussed in Nix team meeting:
|
Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Thanks! This will be a productivity boost for all Nix on non-NixOS users! 🚀 |
Follow-up to NixOS#8985
So, I've tested this now, and while it seems to not require a re-installation as I initially assumed, the change does have an undesirable side-effect on my machine:
Open a new terminal:
And while the reference to I'll have to find out why this is happening exactly. This might very well be something about my local setup, but either way, it's suboptimal (and unexpected) that this can happen at all. Shell is zsh. |
Wait, how does |
Follow-up to NixOS#8985
The [POSIX test manpage](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html) as well as the [fish test manpage](https://fishshell.com/docs/current/cmds/test.html#operators-for-text-strings) specify that `-z` will be "True if the length of string string is zero; otherwise, false." The `-n` was likely a mixup and not caught during testing of NixOS#8985 due to a lack of missing conflicting entries in `XDG_DATA_DIRS`.
Ah, I added this line to my user's
Either way, the issue I found was real and I already fixed it, so I'll open a PR for that shortly. |
The [POSIX test manpage](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html) as well as the [fish test manpage](https://fishshell.com/docs/current/cmds/test.html#operators-for-text-strings) specify that `-z` will be "True if the length of string string is zero; otherwise, false." The `-n` was likely a mixup and not caught during testing of #8985 due to a lack of missing conflicting entries in `XDG_DATA_DIRS`.
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/nix-installer-workgroup/21495/27 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-11-06-nix-team-meeting-minutes-101/35247/1 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: |
Motivation
On non-NixOS systems, the default
nix
install does not populate the$XDG_DATA_DIRS
.This populates it and enables things like bash-completion and
.desktop
file detection fornix
profile installed packages.With this PR:
nix r<tab>
andnix build .#pro<tab>
, ornix profile add nixpkgs#ripgrep
thenrg -<tab>
should show the expected output.nix profile install nixpkgs#firefox
should result in firefox appearing in the user's Desktop environment menus via the.desktop
file. (This may require a relog in some environments)This PR sets
XDG_DATA_DIRS
appropriately in currently supported shells, ensuring to include the spec-defined defaults should the variable not exist.This variable is a
PATH
style variable which is:
separated, with a spec defined default of/usr/local/share:/usr/share
.I do not believe the implementation in this PR risks clobbering existing system settings or breaking things for users. We add the
nix
provided directories to the end of theXDG_DATA_DIRS
, making them the lowest priority, meaning we won't break anything already existing on the user's system. We ensure the spec-defined default is set, meaning we won't break the system if the value is unset. Nix already manipulates thePATH
variable and this PR manipulatesXDG_DATA_DIRS
in roughly the same way.Testing:
I have tested this on:
nix
repo's installer test suite (vianix --extra-experimental-features 'nix-command flakes' run .#hydraJobs.installTests.x86_64-linux -L -j 8
)If you'd like to test, you can add the line yourself to the file
/nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
, or build the appropriategithub:nixpkgs/nix#hydraJobs.binaryTarball.$SYSTEM
output and try it on a VM.Doing that should result in new shells being able to complete
nix r<tab>
like so:Or
nix build github:nixos/nix#hydraJobs.<tab>
(you may need to be patient here -- takes a sec to do the network):You can also test
.desktop
files:ana@ephemeral-ubuntu:~$ nix profile install nixpkgs#xfce.thunar
Reload your DE (eg, relog) and observe:
Context
Previously, #2443 suggested this change, however it was years ago and initially intermingled with another
man
related change (not present here). In #2443 (comment) @edolstra offered some insight into why this was not merged, it was focused on theMANPATH
related changes.In NixOS/nixpkgs#78822, this issue was once again surfaced and referenced #2443 (comment).
In DeterminateSystems/nix-installer#614, it was suggested that this be done in order to allow users to do something like
nix profile install nixpkgs#blender
and see blender in their desktop environment's menus.In DeterminateSystems/nix-installer#486, it was suggested that this be done in order to enable shell completion on an installed Nix.
In #6098, someone mentioned a gotcha around setting this value such that you don't overwrite the XDG spec defined defaults. (Spec here: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
In #4453 someone requested this feature as well, offering an alternative of doing this only inside of a
nix shell
, but that was a more complicated solution.Despite the PR from several years ago not being merged, I believe it's worth revisiting the discussion in light of the numerous related issues as well as rather substantial potential benefits it can bring to users.
Priorities
Add 👍 to pull requests you find important.