nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]
https://nix-community.github.io/home-manager/
MIT License
7.08k stars 1.83k forks source link

Package request: lapce plugins #4541

Open KiaraGrouwstra opened 1 year ago

KiaraGrouwstra commented 1 year ago

nixpkgs has packaged the IDE lapce, but it seems this editor also offers plugins. it would be nice if those could be made reproducible as well.

see also: https://github.com/NixOS/nixpkgs/issues/259250, where @nrabulinski commented:

IIRC Lapce plugins are WASM which means we don't necessairly need to build them (though it could be nice to have them packaged or a mechanism to easily do so), but I'd probably be better to leave packaging the editor along with plugins to something like home-manager as the plugins aren't bundled with the editor directly.

andar1an commented 11 months ago

This would be so cool

stale[bot] commented 8 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

KaiserCalm commented 7 months ago

I was trying to make a module for this myself, but I don't know if I am knowledgeable enough to do it. So I ended up making one that just lets you set settings and keybindings declaratively. If you guys think I should contribute it, I might do it.

However I also figured out some other stuff and would like to share it here if it helps someone make declarative plugin installation for Lapce possible.

  1. Lapce gets it's plugins using the url: https://plugins.lapce.dev/api/v1/plugins/dzhou121/lapce-rust/0.3.1896/download
  2. The URL contains the plugin author (dzhou121), plugin name (lapce-rust) and plugin version (0.3.1896).
  3. Going to that URL gives you the URL where the actual plugin file is stored.
  4. The plugin file is plugin.volt, but actually it's just a plugin.tar.zstd file.
  5. Lapce finally puts the extracted plugin in ~/.local/share/lapce-stable/plugins
stale[bot] commented 4 months ago

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

timon-schelling commented 3 months ago

@KaiserCalm build something that achieves this. You can see my module in my config.

I would like to contribute this to home-manager. Config would look like this:

programs.lapce = {
  enable = true;
  name = "lapce-nightly";
  package = pkgs.lapce;
  settings = {
    ...
  };
  plugins = [
    {
      author = "timon-schelling";
      name = "nushell-lsp";
      version = "0.1.0-rc2";
      hash = "sha256-/s982zGl85kxRoibwSpRiXxXD1Dgq6OUVvMXIUPP//4=";
    }
    {
      author = "MrFoxPro";
      name = "lapce-nix";
      version = "0.0.1";
      hash = "sha256-n+j8p6sB/Bxdp0iY6Gty9Zkpv9Rg34HjKsT1gUuGDzQ=";
    }
  ];
  keymaps = [
    {
      command = "open_log_file";
      key = "Ctrl+Shift+L";
    }
  ];
};

Plugin download would be implemented like in my personal module:

fetchPluginTarball = { author, name, version, hash }:  pkgs.stdenvNoCC.mkDerivation (
  let
    url = "https://plugins.lapce.dev/api/v1/plugins/${author}/${name}/${version}/download";
    file = "lapce-plugin-${author}-${name}-${version}.tar.zstd";
  in
  {
    name = file;
    unpackPhase = "true";
    outputHashAlgo = "sha256";
    outputHashMode = "flat";
    outputHash = hash;
    nativeBuildInputs = [ pkgs.curl pkgs.cacert ];
    builder = builtins.toFile "download-lapce-plugin.sh" ''
      source "$stdenv/setup"
      url="$(curl ${url})"
      curl -L "$url" -o "$out"
    '';
  }
);
fetchPlugin = { author, name, version, hash } @ args: pkgs.stdenvNoCC.mkDerivation {
  name = "lapce-plugin-${author}-${name}-${version}";
  src = fetchPluginTarball args;
  unpackPhase = "true";
  nativeBuildInputs = [ pkgs.zstd ];
  installPhase = ''
    mkdir -p $out
    tar -C $out -xvf $src
  '';
};
fetchPlugins = plugins: pkgs.linkFarm "lapce-plugins" (builtins.listToAttrs (
  builtins.map (
    { author, name, version, ... } @ plugin:
    {
      name = "${author}-${name}-${version}";
      value = fetchPlugin plugin;
    }
  ) plugins
));

Symliked like this:

xdg =
  let
    appName = "lapce-nightly";
    toml = pkgs.formats.toml { };
    pluginsPkg = import ./plugins.nix { inherit plugins pkgs; };
  in
  {
    configFile = {
      "${appName}/settings.toml".source =
        toml.generate "settings.toml" settings;
      "${appName}/keymaps.toml".source =
        toml.generate "keymaps.toml" { inherit keymaps; };
    };
    dataFile."${appName}/plugins".source = pluginsPkg;
  };

@KiaraGrouwstra would this achieve your goals?

KiaraGrouwstra commented 2 months ago

@timon-schelling using that snippet i don't see the listed plugins installed yet, but i agree home-manager seems a better place - i'll close this in favor of your ticket then.

timon-schelling commented 2 months ago

@KiaraGrouwstra See my pr for implementation: module file.

Or you could use my fork in the meantime, like I do.

inputs.home-manager = {
  # TODO: change to upstream once merged into home-manager
  url = "git+https://github.com/timon-schelling/home-manager?ref=lapce";
  inputs.nixpkgs.follows = "nixpkgs";
};

src

If you need help getting it to work feel free to ask :)

timon-schelling commented 2 months ago

@KiaraGrouwstra I did open a PR (Not a new issue) that would add a module that achieves what you requested, but until that PR is merged I would not close this as complete.