Make nki-kakoune slightly more extensible, expose it as an overlay

This commit is contained in:
Natsu Kagami 2025-04-04 14:32:20 +02:00
parent 9156c6049c
commit b3ebb46101
Signed by: nki
GPG key ID: 55A032EB38B49ADB
6 changed files with 539 additions and 505 deletions

View file

@ -189,7 +189,12 @@
in in
{ {
overlays.default = lib.composeManyExtensions overlays; overlays = {
default = lib.composeManyExtensions overlays;
kakoune = final: prev: {
nki-kakoune = final.callPackage ./packages/common/nki-kakoune { };
};
};
packages.x86_64-linux.deploy-rs = deploy-rs.packages.x86_64-linux.default; packages.x86_64-linux.deploy-rs = deploy-rs.packages.x86_64-linux.default;
apps.x86_64-linux.deploy-rs = deploy-rs.apps.x86_64-linux.default; apps.x86_64-linux.deploy-rs = deploy-rs.apps.x86_64-linux.default;

View file

@ -2,21 +2,24 @@
callPackage, callPackage,
kakoune, kakoune,
kakoune-unwrapped, kakoune-unwrapped,
nki-kak-util ? callPackage ./util.nix { },
nki-kak-lsp ? callPackage ./lsp.nix { },
nki-kak-rc ? callPackage ./rc.nix { },
nki-kak-plugins ? callPackage ./plugins.nix { util = nki-kak-util; },
nki-kak-kaktex ? callPackage ./kaktex { },
nki-kak-themes ? callPackage ./themes.nix { },
nki-kak-faces ? callPackage ./faces.nix { util = nki-kak-util; },
... ...
}: }:
let
lsp = callPackage ./lsp.nix { };
rc = (callPackage ./rc.nix { });
in
(kakoune.override { (kakoune.override {
plugins = plugins =
callPackage ./plugins.nix { } nki-kak-plugins
++ callPackage ./themes.nix { } ++ nki-kak-themes
++ [ ++ [
(callPackage ./kaktex { }) nki-kak-kaktex
(callPackage ./faces.nix { }) nki-kak-faces
rc nki-kak-rc
lsp.plugin nki-kak-lsp.plugin
]; ];
}).overrideAttrs }).overrideAttrs
(attrs: { (attrs: {
@ -27,6 +30,15 @@ in
rm "$out/bin/kak" rm "$out/bin/kak"
makeWrapper "${kakoune-unwrapped}/bin/kak" "$out/bin/kak" \ makeWrapper "${kakoune-unwrapped}/bin/kak" "$out/bin/kak" \
--set KAKOUNE_RUNTIME "$out/share/kak" \ --set KAKOUNE_RUNTIME "$out/share/kak" \
--suffix PATH ":" "${lsp.extraPaths}" --suffix PATH ":" "${nki-kak-lsp.extraPaths}"
''; '';
passthru = {
lsp = nki-kak-lsp;
rc = nki-kak-rc;
plugins = nki-kak-plugins;
kaktex = nki-kak-kaktex;
themes = nki-kak-themes;
faces = nki-kak-faces;
};
}) })

View file

@ -1,6 +1,9 @@
{ callPackage, ... }: {
callPackage,
utils ? callPackage ./utils.nix { },
...
}:
let let
utils = callPackage ./utils.nix { };
faces = { faces = {
Default = "%opt{text},%opt{base}"; Default = "%opt{text},%opt{base}";
BufferPadding = "%opt{base},%opt{base}"; BufferPadding = "%opt{base},%opt{base}";

View file

@ -19,11 +19,15 @@
marksman, marksman,
templ, templ,
rust-analyzer, rust-analyzer,
overrideConfig ? (baseConfig: baseConfig),
extraSetup ? "",
... ...
}: }:
let let
# Configuration for kak-lsp # Configuration for kak-lsp
config = { config =
let
baseConfig = {
languageIDs = { languageIDs = {
c = "c_cpp"; c = "c_cpp";
cpp = "c_cpp"; cpp = "c_cpp";
@ -462,6 +466,8 @@ let
verbosity = 255; verbosity = 255;
}; };
}; };
in
overrideConfig baseConfig;
per-lang-config = per-lang-config =
lang: lang:
@ -602,6 +608,9 @@ in
## Faces ## Faces
${faces-config} ${faces-config}
## Extra setup
${extraSetup}
} }
''; '';
} }

View file

@ -1,59 +1,14 @@
{ {
pkgs, callPackage,
symlinkJoin, utils ? callPackage ./utils.nix { },
writeTextDir, fetchFromGitHub,
kakouneUtils, fetchFromGitLab,
luajit,
... ...
}: }:
with { with {
inherit (kakouneUtils) buildKakounePluginFrom2Nix; inherit (utils) toDir writeModuleWrapper kakounePlugin;
}; };
let
toDir = name: file: writeTextDir name (builtins.readFile file);
writeActivationScript =
script:
writeTextDir "on-load.kak" ''
hook global KakBegin .* %{
${script}
}
'';
writeModuleWrapper =
name: script:
writeTextDir "module.kak" ''
provide-module ${name} %
${script}
'';
kakounePlugin =
{
name,
src,
wrapAsModule ? false,
activationScript ? null,
...
}@attrs:
let
module = if wrapAsModule then writeModuleWrapper name (builtins.readFile src) else src;
in
buildKakounePluginFrom2Nix {
pname = name;
version = attrs.version or "latest";
src =
if activationScript == null then
module
else
symlinkJoin {
name = "${name}-src";
paths = [
module
(writeActivationScript activationScript)
];
};
};
in
builtins.map kakounePlugin [ builtins.map kakounePlugin [
# My own scripts # My own scripts
{ {
@ -68,7 +23,7 @@ builtins.map kakounePlugin [
# Plugins # Plugins
{ {
name = "luar"; name = "luar";
src = pkgs.fetchFromGitHub { src = fetchFromGitHub {
owner = "gustavo-hms"; owner = "gustavo-hms";
repo = "luar"; repo = "luar";
rev = "2f430316f8fc4d35db6c93165e2e77dc9f3d0450"; rev = "2f430316f8fc4d35db6c93165e2e77dc9f3d0450";
@ -78,12 +33,12 @@ builtins.map kakounePlugin [
# Enable luar # Enable luar
require-module luar require-module luar
# Use luajit # Use luajit
set-option global luar_interpreter ${pkgs.luajit}/bin/luajit set-option global luar_interpreter ${luajit}/bin/luajit
''; '';
} }
{ {
name = "peneira"; name = "peneira";
src = pkgs.fetchFromGitHub { src = fetchFromGitHub {
owner = "gustavo-hms"; owner = "gustavo-hms";
repo = "peneira"; repo = "peneira";
rev = "b56dd10bb4771da327b05a9071b3ee9a092f9788"; rev = "b56dd10bb4771da327b05a9071b3ee9a092f9788";
@ -128,7 +83,7 @@ builtins.map kakounePlugin [
} }
{ {
name = "kakoune-focus"; name = "kakoune-focus";
src = pkgs.fetchFromGitHub { src = fetchFromGitHub {
owner = "caksoylar"; owner = "caksoylar";
repo = "kakoune-focus"; repo = "kakoune-focus";
rev = "949c0557cd4c476822acfa026ca3c50f3d38a3c0"; rev = "949c0557cd4c476822acfa026ca3c50f3d38a3c0";
@ -140,7 +95,7 @@ builtins.map kakounePlugin [
} }
{ {
name = "kakoune-inc-dec"; name = "kakoune-inc-dec";
src = pkgs.fetchFromGitLab { src = fetchFromGitLab {
owner = "Screwtapello"; owner = "Screwtapello";
repo = "kakoune-inc-dec"; repo = "kakoune-inc-dec";
rev = "7bfe9c51"; rev = "7bfe9c51";
@ -158,14 +113,10 @@ builtins.map kakounePlugin [
}) })
+ "/rc"; + "/rc";
} }
# {
# name = "kakoune-discord";
# src = (builtins.getFlake "github:natsukagami/kakoune-discord/03f95e40d6efd8fd3de7bca31653d43de2dcfc5f").packages.${pkgs.system}.kakoune-discord-rc + "/rc";
# }
rec { rec {
name = "kakoune-mirror"; name = "kakoune-mirror";
src = src =
pkgs.fetchFromGitHub { fetchFromGitHub {
owner = "Delapouite"; owner = "Delapouite";
repo = "kakoune-mirror"; repo = "kakoune-mirror";
rev = "5710635f440bcca914d55ff2ec1bfcba9efe0f15"; rev = "5710635f440bcca914d55ff2ec1bfcba9efe0f15";
@ -182,7 +133,7 @@ builtins.map kakounePlugin [
} }
{ {
name = "unicode-math"; name = "unicode-math";
src = pkgs.fetchFromGitHub { src = fetchFromGitHub {
owner = "natsukagami"; owner = "natsukagami";
repo = "kakoune-unicode-math"; repo = "kakoune-unicode-math";
rev = "08dff25da2b86ee0b0777091992bc7fb28c3cb1d"; rev = "08dff25da2b86ee0b0777091992bc7fb28c3cb1d";
@ -199,7 +150,7 @@ builtins.map kakounePlugin [
} }
{ {
name = "kakoune-buffers"; name = "kakoune-buffers";
src = pkgs.fetchFromGitHub { src = fetchFromGitHub {
owner = "Delapouite"; owner = "Delapouite";
repo = "kakoune-buffers"; repo = "kakoune-buffers";
rev = "6b2081f5b7d58c72de319a5cba7bf628b6802881"; rev = "6b2081f5b7d58c72de319a5cba7bf628b6802881";

View file

@ -1,5 +1,14 @@
{ lib, writeTextDir, ... }:
{ {
lib,
writeTextDir,
kakouneUtils,
symlinkJoin,
...
}:
with {
inherit (kakouneUtils) buildKakounePluginFrom2Nix;
};
rec {
mkFacesScript = mkFacesScript =
name: faces: name: faces:
writeTextDir "share/kak/autoload/${name}/faces.kak" '' writeTextDir "share/kak/autoload/${name}/faces.kak" ''
@ -9,4 +18,49 @@
)} )}
} }
''; '';
toDir = name: file: writeTextDir name (builtins.readFile file);
writeActivationScript =
script:
writeTextDir "on-load.kak" ''
hook global KakBegin .* %{
${script}
}
'';
writeModuleWrapper =
name: script:
writeTextDir "module.kak" ''
provide-module ${name} %
${script}
'';
kakounePlugin =
{
name,
src,
wrapAsModule ? false,
activationScript ? null,
...
}@attrs:
let
module = if wrapAsModule then writeModuleWrapper name (builtins.readFile src) else src;
in
buildKakounePluginFrom2Nix {
pname = name;
version = attrs.version or "latest";
src =
if activationScript == null then
module
else
symlinkJoin {
name = "${name}-src";
paths = [
module
(writeActivationScript activationScript)
];
};
};
} }