diff options
author | Jason Felice <jason.m.felice@gmail.com> | 2019-06-07 11:18:32 -0400 |
---|---|---|
committer | Jason Felice <jason.m.felice@gmail.com> | 2019-06-25 17:17:08 -0400 |
commit | 2a911454d349656e6140dcf919d1907c250d727a (patch) | |
tree | e5c81df1c85e4835862c0886b7e6975110bd9377 /pkgs/applications/editors/kakoune | |
parent | 3297873118c2e0635d5fae9298cda329515095c1 (diff) |
kakoune: support for adding plugins
Motivation: There is a thriving plugin ecosystem for Kakoune now,
and it is nice to add these in our Nix configurations. This was modeled
on neovim's plugins.
parinfer-rust is useable both standalone and as a Kakoune plugin,
so the plugin file inherits the same definition as pkgs.
I'll make PRs for other plugins if this gets accepted.
[Here](https://github.com/eraserhd/nixpkgs/tree/kak-ansi)'s a tested
branch for the `kak-ansi` plugin.
Diffstat (limited to 'pkgs/applications/editors/kakoune')
-rw-r--r-- | pkgs/applications/editors/kakoune/default.nix | 2 | ||||
-rw-r--r-- | pkgs/applications/editors/kakoune/plugins.nix | 5 | ||||
-rw-r--r-- | pkgs/applications/editors/kakoune/wrapper.nix | 44 | ||||
-rw-r--r-- | pkgs/applications/editors/kakoune/wrapper.sh | 30 |
4 files changed, 80 insertions, 1 deletions
diff --git a/pkgs/applications/editors/kakoune/default.nix b/pkgs/applications/editors/kakoune/default.nix index 16596056c9a0..8dfcc4856680 100644 --- a/pkgs/applications/editors/kakoune/default.nix +++ b/pkgs/applications/editors/kakoune/default.nix @@ -3,7 +3,7 @@ with stdenv.lib; stdenv.mkDerivation rec { - name = "kakoune-${version}"; + pname = "kakoune-unwrapped"; version = "2019.01.20"; src = fetchFromGitHub { repo = "kakoune"; diff --git a/pkgs/applications/editors/kakoune/plugins.nix b/pkgs/applications/editors/kakoune/plugins.nix new file mode 100644 index 000000000000..d2f3607d63cb --- /dev/null +++ b/pkgs/applications/editors/kakoune/plugins.nix @@ -0,0 +1,5 @@ +{ parinfer-rust }: + +{ + inherit parinfer-rust; +} diff --git a/pkgs/applications/editors/kakoune/wrapper.nix b/pkgs/applications/editors/kakoune/wrapper.nix new file mode 100644 index 000000000000..b4cc823880e7 --- /dev/null +++ b/pkgs/applications/editors/kakoune/wrapper.nix @@ -0,0 +1,44 @@ +{ stdenv, bash }: +with stdenv.lib; + +kakoune: + +let + getPlugins = { plugins ? [] }: plugins; + + wrapper = { configure ? {} }: + stdenv.mkDerivation rec { + pname = "kakoune"; + version = getVersion kakoune; + + src = ./.; + buildCommand = '' + mkdir -p $out/share/kak + for plugin in ${strings.escapeShellArgs (getPlugins configure)}; do + if [[ -d $plugin/share/kak/autoload ]]; then + find "$plugin/share/kak/autoload" -type f -name '*.kak'| while read rcfile; do + printf 'source "%s"\n' "$rcfile" + done + fi + done >>$out/share/kak/plugins.kak + + mkdir -p $out/bin + substitute ${src}/wrapper.sh $out/bin/kak \ + --subst-var-by bash "${bash}" \ + --subst-var-by kakoune "${kakoune}" \ + --subst-var-by out "$out" + chmod +x $out/bin/kak + ''; + + preferLocalBuild = true; + buildInputs = [ bash kakoune ]; + passthru = { unwrapped = kakoune; }; + + meta = kakoune.meta // { + # prefer wrapper over the package + priority = (kakoune.meta.priority or 0) - 1; + hydraPlatforms = []; + }; + }; +in + makeOverridable wrapper diff --git a/pkgs/applications/editors/kakoune/wrapper.sh b/pkgs/applications/editors/kakoune/wrapper.sh new file mode 100644 index 000000000000..48a971a10c6e --- /dev/null +++ b/pkgs/applications/editors/kakoune/wrapper.sh @@ -0,0 +1,30 @@ +#!@bash@/bin/bash + +# We use the -E option to load plugins. This only makes sense when we are +# starting a new session, so we detect that. Also, Kakoune can only handle +# one -E option, so we prepend loading plugins to an existing one. +args=( "$@" ) +loadPlugins=true +EValueOffset=-1 +pluginScript='@out@/share/kak/plugins.kak' + +for (( i = 0; i < ${#args[@]}; i++ )); do + case "${args[i]}" in + -n|-c|-l|-p|-clear|-version) loadPlugins=false;; + -E) EValueOffset=$(( i + 1 ));; + --) break;; + esac + case "${args[i]}" in + -E|-c|-e|-s|-p|-f|-i|-ui|-debug) i=$(( i + 1 ));; + esac +done + +if [[ $loadPlugins = true ]]; then + if (( EValueOffset >= 0 )); then + args[EValueOffset]="source '$pluginScript'"$'\n'"${args[EValueOffset]}" + else + args=( "-E" "source '$pluginScript'" "${args[@]}" ) + fi +fi + +exec @kakoune@/bin/kak "${args[@]}" |