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

feat: global install #1791

Closed

Conversation

jameswalmsley
Copy link
Member

Resurrected my global-install PR again to work with the latest rolling release.

This ensures that bin/lvim defines all of the LUNARVIM_x_DIR variables correctly.

Also when running as lvim (instead of nvim) we should guarantee that stdpath('data') etc do not give paths to the user standard neovim installation.

Copy link
Collaborator

@kylo252 kylo252 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'm not set on yet, should we call it LUNARVIM_ROOT_DIR instead?

utils/bin/lvim Outdated
#!/bin/sh
#!/bin/bash
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please be aware that macOS is stuck with an ancient bash v3.xx.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I'll convert it to pure POSIX shell at the end of the PR.. just wanted to scratch up the idea quickly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's probably because the default shell is ZSH

utils/bin/lvim Outdated
Comment on lines 27 to 21
#
# When runnins as lvim the neovim process MUST never refer to the standard user config:
# Anything that uses stdpath('data'), stdpath('cache') etc will get:
#
# LUNARVIM_x_DIR/nvim
#
export XDG_CONFIG_HOME=${LUNARVIM_CONFIG_DIR}
export XDG_DATA_HOME="${LUNARVIM_RUNTIME_DIR}"
export XDG_CACHE_HOME="${LUNARVIM_CACHE_DIR}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, are you sure this actually works tho?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I used this technique before LunarVim had the bootstrap in the configuration to remove and add folders from the runtimepath. Using just this, I was able to completely decouple a global install from the user's neovim config.

I think when I first did this, because its e.g. XDG_x_HOME/nvim for each folder the paths didn't make sense. (E.g. ~/.local/share/lunarvim/nvim ...).

However combined with the technique you've used already it works nicely.

I looked into the Neovim sources to work out how to do it, and it uses this variables, otherwise the defaults.

Copy link
Collaborator

@kylo252 kylo252 Oct 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be risky now that I think about it. A lot of external tools are relying on these variables to read their configuration. If this environment variable is inherited by these tools then this will break a lot of stuff.

Could you test this with git or lazygit, and maybe something like fd or ripgrep?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats a good point, anything that forks from neovim will have those variables also..
I'll double check what happens..

I wonder if theres a way to unset those env variables for the nvim process once its running.

I can see in a terminal session thats the case.. I'll see if I can find anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so its simple in VIM... once running:
Simply execute the command e.g:

unlet $XDG_CONFIG_HOME

We could do this conditionally on init.
I suppose it kind of means we should also "push" these variables if they have already been set by the user, and pop them in the lvim init too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this, and unsetting XDG_x_HOME variables just causes vim.fn.stdpath() to return the standard values.
The environment variable must be evaluated everytime.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested this, and unsetting XDG_x_HOME variables just causes vim.fn.stdpath() to return the standard values. The environment variable must be evaluated everytime.

So that's a problem, because we also don't want to be missing with these variables as you never know the workflows that people are using. I think it's fine to leave them alone tbh. We have very little dependence on them outside of the cache folder.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also the approach I thought for solving #2944
Sadly, neovim does not provide any way to configure what those folders are and make that globally available for everyone, it's very frustrating to be honest.
It really matters because it not only relies on the cache, also the plugins installation place and the extensions state/storage is shared across neovim instances, which is a mess.

Comment on lines +23 to +11
export LUNARVIM_RUNTIME_DIR="$HOME/.local/share/lunarvim/data"
export LUNARVIM_CACHE_DIR="$HOME/.local/share/lunarvim/cache"
export LUNARVIM_CONFIG_DIR="$HOME/.config/lvim"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the default values check? It's useful in case the binary and installer get out of sync.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll put that back in. (I actually didn't know what the syntax was doing)..

utils/bin/lvim Outdated
Comment on lines 39 to 57
#
# Ensure a new install has an empty lvim/config.lua file
#
if [ ! -f ${LUNARVIM_CONFIG_DIR}/config.lua ]; then
mkdir -p ${LUNARVIM_CONFIG_DIR}
touch ${LUNARVIM_CONFIG_DIR}/config.lua
fi

#
# If the global installation was updated, ensure to run a packer_sync
# on the users installation.
#
if [ -v GLOBAL ]; then
if [ ${LUNARVIM_INSTALL_DIR}/.packer_sync -nt ${LUNARVIM_RUNTIME_DIR}/.packer_sync ] || [ ! -f ${LUNARVIM_RUNTIME_DIR}/.packer_sync ]; then

LUNARVIM_ARGS="+PackerSync"
touch ${LUNARVIM_RUNTIME_DIR}/.packer_sync
fi
fi
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part should be decoupled from the binary and handled by either the installer or the update handler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -124,7 +124,7 @@ end
---pulls the latest changes from github and, resets the startup cache
function M:update()
hooks.run_pre_update()
M:update_repo()
--M:update_repo()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why isn't this working?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have it commented on my branch because I'm using a global installation.
This means that the repo is at:

/usr/share/lunarvim or /opt/lunarvim.

Basically any user process doesn't have permission to git pull at that path.. and I want the other parts of LvimUpdate to succeed.

In a global install the admin would have to update Lvim's repo through...
sudo lvim +LvimUpdate

Or

pacman -Sy lvim

I'll look at update_repo() and make work gracefully on a system where the current user doesn't have permission.

lua/lvim/bootstrap.lua Outdated Show resolved Hide resolved
init.lua Outdated Show resolved Hide resolved
@jameswalmsley jameswalmsley force-pushed the lunarvim.global.install branch 2 times, most recently from bf869aa to f597c4f Compare October 17, 2021 15:16
@jameswalmsley
Copy link
Member Author

jameswalmsley commented Oct 17, 2021

One thing I'm not set on yet, should we call it LUNARVIM_ROOT_DIR instead?

I think we should make the following changes to the names:

LUNARVIM_INSTALL_DIR -> LUNARVIM_ROOT_DIR or LUNARVIM_BASE_DIR
LUNARVIM_RUNTIME_DIR -> LUNARVIM_DATA_DIR (I find runtime a bit too ambiguous).
LUNARVIM_CONFIG_DIR -- same.
LUNARVIM_CACHE_DIR -- same.

@kylo252 Let me know what you think?

@kylo252
Copy link
Collaborator

kylo252 commented Oct 17, 2021

LUNARVIM_INSTALL_DIR -> LUNARVIM_ROOT_DIR or LUNARVIM_BASE_DIR

Let's see if what I added in https://github.com/LunarVim/LunarVim/pull/1777/files/5c3ef594c65ce2396c2f114390c3061295fccfdf fixes the issue, then we won't have to introduce a new variable.

LUNARVIM_RUNTIME_DIR -> LUNARVIM_DATA_DIR (I find runtime a bit too ambiguous).

I'm slightly worried this might cause a regression since we haven't set a reliable way to update the binary. We would need to finish #1444 first, but that should fairly straight-forward anyway.

@jameswalmsley
Copy link
Member Author

jameswalmsley commented Oct 18, 2021

LUNARVIM_INSTALL_DIR -> LUNARVIM_ROOT_DIR or LUNARVIM_BASE_DIR

Let's see if what I added in https://github.com/LunarVim/LunarVim/pull/1777/files/5c3ef594c65ce2396c2f114390c3061295fccfdf fixes the issue, then we won't have to introduce a new variable.

LUNARVIM_RUNTIME_DIR -> LUNARVIM_DATA_DIR (I find runtime a bit too ambiguous).

I'm slightly worried this might cause a regression since we haven't set a reliable way to update the binary. We would need to finish #1444 first, but that should fairly straight-forward anyway.

I like what you are doing there.
I've mocked out how that can work with the LVIM shim and the global install here:

5cb4762

This is simpler, because the SHIM doesn't need to be updated unless you allow the user to choose an arbitrary base_dir.

It defaults to using a global installation, unless the user has their own local installation, in-which case we use the users config...
And then as you demonstrated we can get the lvim_base dir() automatically.

@meijieru
Copy link
Contributor

For someone else waiting for it, here is a tricky way to do it. Put the following in your ~/.config/nvim/init.lua

local home_dir = os.getenv("HOME")
local envs = {
  LUNARVIM_CONFIG_DIR = home_dir .. "/.config/lvim",
  LUNARVIM_RUNTIME_DIR = home_dir .. "/.local/share/lunarvim",
}
for key, val in pairs(envs) do
  vim.fn.setenv(key, val)
end

local lvim_init = envs.LUNARVIM_RUNTIME_DIR .. "/lvim/init.lua"
vim.cmd("source " .. lvim_init)

@kylo252
Copy link
Collaborator

kylo252 commented Apr 17, 2022

@meijieru, @jameswalmsley
Please take a look at 8ccca67 and let me know what you think

@meijieru
Copy link
Contributor

@meijieru, @jameswalmsley Please take a look at 8ccca67 and let me know what you think

Thanks for the feature.
Is it safe to directly override the internal function?

@kylo252
Copy link
Collaborator

kylo252 commented Oct 6, 2022

Replaced by #3161

@kylo252 kylo252 closed this Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants