aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Felice <jason.m.felice@gmail.com>2019-06-07 11:18:32 -0400
committerJason Felice <jason.m.felice@gmail.com>2019-06-25 17:17:08 -0400
commit2a911454d349656e6140dcf919d1907c250d727a (patch)
treee5c81df1c85e4835862c0886b7e6975110bd9377
parent3297873118c2e0635d5fae9298cda329515095c1 (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.
-rw-r--r--doc/package-notes.xml12
-rw-r--r--pkgs/applications/editors/kakoune/default.nix2
-rw-r--r--pkgs/applications/editors/kakoune/plugins.nix5
-rw-r--r--pkgs/applications/editors/kakoune/wrapper.nix44
-rw-r--r--pkgs/applications/editors/kakoune/wrapper.sh30
-rw-r--r--pkgs/top-level/all-packages.nix5
6 files changed, 96 insertions, 2 deletions
diff --git a/doc/package-notes.xml b/doc/package-notes.xml
index 2b7b4b9bc51..d2c660e22a9 100644
--- a/doc/package-notes.xml
+++ b/doc/package-notes.xml
@@ -325,6 +325,18 @@ packageOverrides = pkgs: {
elm2nix</link>.
</para>
</section>
+ <section xml:id="sec-kakoune">
+ <title>Kakoune</title>
+
+ <para>
+ Kakoune can be built to autoload plugins:
+<programlisting>(kakoune.override {
+ configure = {
+ plugins = with pkgs.kakounePlugins; [ parinfer-rust ];
+ };
+})</programlisting>
+ </para>
+ </section>
<section xml:id="sec-shell-helpers">
<title>Interactive shell helpers</title>
diff --git a/pkgs/applications/editors/kakoune/default.nix b/pkgs/applications/editors/kakoune/default.nix
index 16596056c9a..8dfcc485668 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 00000000000..d2f3607d63c
--- /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 00000000000..b4cc823880e
--- /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 00000000000..48a971a10c6
--- /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[@]}"
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 09a2f6c391d..f213cc7c83f 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -3943,7 +3943,10 @@ in
kalibrate-hackrf = callPackage ../applications/radio/kalibrate-hackrf { };
- kakoune = callPackage ../applications/editors/kakoune { };
+ wrapKakoune = callPackage ../applications/editors/kakoune/wrapper.nix { };
+ kakounePlugins = callPackage ../applications/editors/kakoune/plugins.nix { };
+ kakoune-unwrapped = callPackage ../applications/editors/kakoune { };
+ kakoune = wrapKakoune kakoune-unwrapped { };
kbdd = callPackage ../applications/window-managers/kbdd { };