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

using local plugin without git #6596

Closed
KiaraGrouwstra opened this issue Jan 23, 2025 · 3 comments
Closed

using local plugin without git #6596

KiaraGrouwstra opened this issue Jan 23, 2025 · 3 comments
Labels
enhancement New feature or request

Comments

@KiaraGrouwstra
Copy link

Is your feature request related to a problem? Please describe.
wezterm.plugin.require may be used to load plugins from a local directory, but unfortunately seems tied to Git.
this now makes it harder to use alternate methods to distribute plugins, for example to reproduce plugin setups (say using Nix), which may be desirable for security.

Describe the solution you'd like
allow wezterm.plugin.require (or similar) to be used without Git, given that seems used only for downloading remote plugins (rather than adding value for local plugins as well)

Describe alternatives you've considered

  • not reproducing plugins
  • try to retain/mock git

Additional context

c.f.

@KiaraGrouwstra KiaraGrouwstra added the enhancement New feature or request label Jan 23, 2025
@PrayagS
Copy link

PrayagS commented Jan 29, 2025

wezterm.plugin.require may be used to load plugins from a local directory, but unfortunately seems tied to Git.

Can you please elaborate on this? I was able to use local directories and have it parse directory locations without any issues.

@KiaraGrouwstra
Copy link
Author

@PrayagS:

wezterm.plugin.require may be used to load plugins from a local directory, but unfortunately seems tied to Git.

Can you please elaborate on this? I was able to use local directories and have it parse directory locations without any issues.

Whereas a local checkout of a plugin should get loaded successfully, such a directory without the .git parts tho will no longer be accepted by the used git2 library

error snippet
runtime error: [string "/home/kiara/.config/wezterm/wezterm.lua"]:7: module '/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init.lua' not found:
        no field package.preload['/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init.lua']
        no file '$XDG_CONFIG_DIRS}/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '$XDG_CONFIG_DIRS}/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/home/kiara/.local/share/wezterm/plugins//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/plugin/init.lua'
        no file '+/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '+/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/nix/store/pa0mhac3p1q1fdz7w13dl13k19a7vd7z-stylix-kde-config${XDG_CONFIG_DIRS/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/nix/store/pa0mhac3p1q1fdz7w13dl13k19a7vd7z-stylix-kde-config${XDG_CONFIG_DIRS/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/home/kiara/.config/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/home/kiara/.config/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/home/kiara/.wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/home/kiara/.wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/usr/local/share/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/usr/local/share/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/usr/local/lib/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/usr/local/lib/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file './/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file './/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'

        can't load C modules in safe mode
stack traceback:
        [C]: in function 'require'
        [string "/home/kiara/.config/wezterm/wezterm.lua"]:7: in local 'stylix_wrapped_config'
        [string "/home/kiara/.config/wezterm/wezterm.lua"]:390: in main chunk

runtime error: [string "/home/kiara/.config/wezterm/wezterm.lua"]:7: module '/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init.lua' not found:
        no field package.preload['/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init.lua']
        no file '$XDG_CONFIG_DIRS}/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '$XDG_CONFIG_DIRS}/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/home/kiara/.local/share/wezterm/plugins//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/plugin/init.lua'
        no file '+/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '+/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/nix/store/pa0mhac3p1q1fdz7w13dl13k19a7vd7z-stylix-kde-config${XDG_CONFIG_DIRS/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/nix/store/pa0mhac3p1q1fdz7w13dl13k19a7vd7z-stylix-kde-config${XDG_CONFIG_DIRS/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/home/kiara/.config/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/home/kiara/.config/wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/home/kiara/.wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/home/kiara/.wezterm//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/usr/local/share/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/usr/local/share/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file '/usr/local/lib/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file '/usr/local/lib/lua/5.4//nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'
        no file './/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua.lua'
        no file './/nix/store/xzh5c035xavk1z3i67dsp2jxm88d3y2f-source/plugin/init/lua/init.lua'

        can't load C modules in safe mode
stack traceback:
        [C]: in function 'require'
        [string "/home/kiara/.config/wezterm/wezterm.lua"]:7: in local 'stylix_wrapped_config'
        [string "/home/kiara/.config/wezterm/wezterm.lua"]:390: in main chunk

syntax error: [string "/home/kiara/.config/wezterm/wezterm.lua"]:7: unexpected symbol near '#'

@sbresin
Copy link

sbresin commented Feb 23, 2025

Hi @KiaraGrouwstra,

just like you i wanted to manage my plugins using nix, especially controlling the exact git revision. First i tried to clone the repos from the store using file:// style uris, which only works with the .git dir intact, which nix usually drops because its a reproducibility problem . Using pkgs.fetchGit with leaveDotGit = true, made the cloning work, but some plugins add themselves to the lua package.path to load their submodules and don't expect the file-uri pieces in their path. Also even with the local clone i would still need more stuff to actually checkout the revision i want.

So what i opted for instead is not using the wezterm.plugin pieces at all and loading the plugins directly from the store using plain lua methods. for each plugin i add its directory to the path to allow submodule loading and then execute the init.lua file.

Heres the examples from my nix config, but people without nix can use the same techniques to load plugins from any path.
You could use flake inputs for the paths as well, it should work the same.

{pkgs, ...}: let
  wezterm_tabline = pkgs.fetchFromGitHub {
    owner = "michaelbrusegard";
    repo = "tabline.wez";
    rev = "c4c9573bc292a8483a0eab398ef51768d008263b";
    sha256 = "sha256-40fZaveu8JnbVZtDHiRAEVRTonrSyhrJRl7SrpIaoBw=";
  };
  wezterm_switcher = pkgs.fetchFromGitHub {
    owner = "MLFlexer";
    repo = "smart_workspace_switcher.wezterm";
    rev = "ef7b5de9280cb8270767cca87385e0a16ed8ead7";
    hash = "sha256-ClhlFTiT0e3gNGid0XomiSMLUJ6FAvE26okoeLNL1C0=";
  };
  wezterm_resurrect = pkgs.fetchFromGitHub {
    owner = "MLFlexer";
    repo = "resurrect.wezterm";
    rev = "8abcbd3345cd95a679d9bd79e4f613f3530c633b";
    hash = "sha256-v8yhkqrjbZAixGDvweKo/uGSkTA+mmGV2isRixmHUfU=";
  };
in {
  xdg.configFile."wezterm/plugins.lua".text = ''
    local M = {}

    local function loadPlugin(plugin_path)
      package.path = package.path .. ';' .. plugin_path .. '/plugin/?.lua'
      return dofile(plugin_path .. '/plugin/init.lua')
    end

    function M.tabline()
      return loadPlugin('${wezterm_tabline}')
    end

    function M.switcher()
      return loadPlugin('${wezterm_switcher}')
    end

    function M.resurrect()
      return loadPlugin('${wezterm_resurrect}')
    end

    return M
  '';
}

and in my main wezterm config (which i don't manage through nix and a symlink instead, to avoid building for every change):

local function file_exists(name)
    local f = io.open(name, "r")
    return f ~= nil and io.close(f)
end

if file_exists(os.getenv("HOME") .. "/.config/wezterm/plugins.lua") then
    local plugins = require("plugins")
    plugins.tabline().setup({options = {theme = 'Rosé Pine (base16)'}})
end

Hope this works for your usecase as well! :)

UPDATE:
just tried the same on my work machine, where i never installed a plugin before and loading of the tabline plugin failed, because it expects wezterm.plugins.list() to return something (at least itself).
i fixed it by adding a dummy plugin directory by mkdir -p .local/share/wezterm/plugins/dummy (macOS: mkdir -p '~/Library/Application Support/wezterm/plugins/dummy'), git init it and adding a dummy remote git remote add https://github.com/...

This can be easily fixed in the individual plugins, eventually i will get to this sometime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants