Closed natto1784 closed 3 years ago
Hi @natto1784, interesting use case! It looks like the plugin isn't able to find the Discord socket due to mismatching $TMPDIR
environment variables between the host and Nix build environments.
Both nix-shell
and nix develop
seem to actually set their own $TMPDIR
values:
$ nix develop nixpkgs#neovim
bash-4.4$ echo $TMPDIR
/tmp/nix-shell.IgP5Pt
The probable reason Rich Presence still works in nix-shell
for you is that the $TMPDIR
value that nix-shell
sets coincidentally matches the value in your host machine. For example, in macOS the $TMPDIR
is not /tmp
but some other path in /var/folders/...
, so nix-shell
would most likely fail to connect to Discord in that case.
It looks like there's a couple changes to be made in order to support Rich Presence in Nix build environments:
$IN_NIX_SHELL
seems apt?)$TMPDIR
value from within the Nix shellI'll need to do some digging to determine the best approach (especially the second bullet point). If you already have an idea and would like to contribute let me know :) Otherwise I'll get back to you sometime today/tomorrow once I've added support for this!
Looks like $TMPDIR in nix-shell falls back to $XDG_RUNTIME_DIR (which has the discord-ipc-0) if $TMPDIR is empty. That is the reason it worked with nix-shell for me. Will look more into how nix develop
handles these variables.
Just checked and confirmed that putting XDG_RUNTIME_DIR before TMP, TMPDIR and TEMP here works fine (in nixOS) because XDG_RUNTIME_DIR is sustained in the nix develop
environment
https://github.com/andweeb/presence.nvim/blob/f4c1e227be0a0c863c2de201155401950eda572e/lua/presence/init.lua#L295-L300
Hmm I seee.. unfortunately that wouldn't work in macOS as $XDG_RUNTIME_DIR
isn't defined :'/ Is that set in most Linux distros?
pretty sure that if $XDG_RUNTIME_DIR
isn't defined on macOS it will skip it and move on to the next var because of the if
statement below it but there should be a better method
Right, it's just that only $TMPDIR
is set on macOS (all others aren't) so there would still be issues there, but maybe support for Nix shells in macOS shouldn't block a hotfix for you, especially considering it's an easy enough change to just switch the order.
I can investigate a more comprehensive/cross-platform solution later :) I'll push the change in a little bit after running some smoke tests!
Just pushed @natto1784, hopefully you're able to get Rich Presence in Nix now :) Feel free to reopen if you still have issues after updating your plugin!
ty :)
This is a bit of an old issue, but I was struggling with getting this plugin to work inside a nix develop
shell on macos, and in case someone finds this issue later looking for a solution, what I did was add a TMPDIR=$TMPDIR
after the -c
flag in nix develop
invocation, so that it gets set to the value from outside of the shell. I have a wrapper command for it in my dotfiles here
When using
nix develop
withnix
(flakes), it can't connect to discord and gives the errorENOENT
. Otherwise, it works fine. This might be related to hownix develop
actually works because it works fine with the vanillanix-shell
.