Doesn't work on NixOS
The vim-startuptime looks for binaries in /usr/bin. NixOS is non FHS compliant and keeps it's binaries in /nix/store. When trying to run the pseudo code below on NixOS, it throws error: no file: /usr/local/lib/lua/5.1/loadall.so.
How can i make :StartupTime use the /nix/store locations?
'/nix/store/somehash/somebin'
'--startuptime'
'<OUTPUT>'
'-c'
'if exists('\''*timer_start'\'') | call timer_start(0, {-> execute('\''qall!'\'')}) | else | autocmd VimEnter * qall! | endif'
I'm unable to reproduce the problem.
On NixOS, I added the following lines to /etc/nixos/configuration.nix, for installing Vim, Neovim, and Git:
environment.systemPackages = with pkgs; [
vim
neovim
git
];
I then ran sudo nixos-rebuild switch.
Next, I installed vim-startuptime for Vim and Neovim.
mkdir -p ~/.vim/pack/plugin/start
git clone 'https://github.com/dstein64/vim-startuptime.git' ~/.vim/pack/plugin/start/vim-startuptime
mkdir -p ~/.config/nvim/pack/plugin/start
git clone 'https://github.com/dstein64/vim-startuptime.git' ~/.config/nvim/pack/plugin/start/vim-startuptime
The :StartupTime command worked without issue from both Vim and Neovim.
@mairs8, can you provide steps for reproducing the problem?
I have a different problem with Neovim installed via Home Manager on NixOS. It's trying to use the unwrapped binary (/nix/store/bbk0zj9xyilgbf3cwz8gvml16p525siw-neovim-unwrapped-0.10.2/bin/nvim) which fails because it can't find any of my packages. The wrapper sets LUA_PATH and provides some additional arguments to nvim setting packpath and rtp, so unsurprisingly without those it can't load my configuration.
I wonder if this is actually the problem that @mairs8 is having. Can you check and see what binary vim-startuptime is trying to call?
I haven't yet confirmed this, but I think a minimal repro would be a setup like this:
home.nix
programs.neovim = {
enable = true;
plugins = with pkgs.vimPlugins; [
vim-startuptime
tokyonight-nvim
];
};
init.lua
vim.cmd.colorscheme("tokyonight")
A simple workaround would be to somehow force vim-startuptime to use a different binary.
I confirmed that fixing the exe works - I can run :let g:startuptime_exe_path="/home/msl/.nix-profile/bin/nvim" and then I am able to get a succesful :StartupTime run. That at least validates my theory, if not the repro.
This is also the output of which nvim. I don't see any env var set matching RUNNING_VIM_PATH, but looking at the code I see that it's actually looking for g:progpath, which is the absolute path to the current running vim instance, though it then also calls exepath on it. I wonder if instead it could do exepath(g:progname). g:progname contains the name by which nvim was invoked, so it should work in both LHS environments and on NixOS. It will also work for any other wrapper script someone might have for nvim, so long as it's transparent to the additional arguments added by vim-startuptime.
Thanks for investigating @dyfrgi. I created a branch, alternative_exe_path, that implements an approach similar to what you proposed. I didn't use g:progname. For example, if a user launches Vim with vimdiff, I wouldn't want that to be used by :StartupTime.
My current plan is to not merge that approach though, since I am unsatisfied with the potential that a different version of Vim could be used for profiling than the one that's being used. For example, suppose a user has two versions of Vim installed. I think there would be an expectation that whichever one is running would be used for :StartuptTime profiling. Under the approach you proposed, that wouldn't be the case if both executables have the same name. The one that's first on the PATH would always be used for profiling, regardless of which Vim that :StartupTime is called from.
For now, I added an update to the error output that mentions that g:startuptime_exe_path may need updating in the case of an error.
Very good point about PATH.
That brings to mind a potential solution for Nix to Just Work with this extension. When it is installed, the nixpkgs wrapper that's generated could set that g:startuptime_exe_path. That solves it for the case where every plugin is installed via nix.
In the NixOS case where the user is using just e.g. lazy.nvim to install everything, the rtp set by the wrapper isn't relevant so it should also work fine.
I think the mixed install location case still has some potential bad behavior, though. If I install some plugins via vim-plug (including vim-startuptime) and some via nix, the vim-plug ones will be seen by vim-unwrapped and the nix ones will not. If startup can still run without error in this case then the nix ones will be silently ignored. This should be the case for plugins which do not require setup to run, or where the setup just sets variables rather than calling functions. Much less likely in Neovim than Vim, I think, due to the prevalence or setup() functions in lua plugins.
I guess as an alternative, the wrapper could unconditionally set an environment variable (or some global in vim) to the path for the wrapper. Then vim-startuptime (and other tools) could check for the presence of that env var and prefer it. Not sure I love that approach.
I'll think a bit more about it. The note seems helpful, for sure. Might have led me to find it a little faster. The thing that slowed me down most was not realizing that was the problem.