Skip to content

Instantly share code, notes, and snippets.

@enricozb
Created May 27, 2023 19:33
Show Gist options
  • Select an option

  • Save enricozb/2d890fcb17ad4e641f5c9df110cca1d7 to your computer and use it in GitHub Desktop.

Select an option

Save enricozb/2d890fcb17ad4e641f5c9df110cca1d7 to your computer and use it in GitHub Desktop.

Revisions

  1. enricozb created this gist May 27, 2023.
    93 changes: 93 additions & 0 deletions kakoune.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,93 @@
    { pkgs, ... }:

    let
    # nightly toolchain of rustfmt
    rustfmt = (pkgs.callPackage (pkgs.fetchFromGitHub {
    owner = "nix-community";
    repo = "fenix";
    rev = "d0b0d39d4f74bec4634ea6b52e6bd49314c3988b";
    sha256 = "1ss5mx8w19c19kis9mivxl4mqsnyifqwm4wpzlg9h9k2pbqzkjpm";
    }) { }).latest.rustfmt;

    kak-tabs = pkgs.callPackage (pkgs.fetchFromGitHub {
    owner = "enricozb";
    repo = "tabs.kak";
    rev = "v0.1.5";
    sha256 = "0zcsk1difl2wbgns0gp8a4qm89fhik9avpwqw9ri7dkl57kpmnjm";
    }) { };

    kak-lsp = pkgs.writeShellScriptBin "kak-lsp" ''
    exec ${pkgs.kak-lsp}/bin/kak-lsp --config ${./config/kak-lsp.toml} "$@"
    '';

    python-lsp = pkgs.python310.withPackages
    (ps: with ps; [ black isort python-lsp-server ]);

    kakoune = pkgs.callPackage (import ./lib.nix) { } {
    config = ./config;
    plugins = [
    "enricozb/beancount.kak"
    "enricozb/cursors.kak"
    "enricozb/mapeval.kak"
    "enricozb/nix.kak"
    "enricozb/tabs.kak"
    "enricozb/wiki.kak"
    "kak-lsp/kak-lsp"
    ];

    # include these files from the standard library
    rc = [
    "filetype/c-family.kak"
    "filetype/css.kak"
    "filetype/diff.kak"
    "filetype/dockerfile.kak"
    "filetype/etc.kak"
    "filetype/fish.kak"
    "filetype/git.kak"
    "filetype/go.kak"
    "filetype/haskell.kak"
    "filetype/html.kak"
    "filetype/i3.kak"
    "filetype/java.kak"
    "filetype/javascript.kak"
    "filetype/json.kak"
    "filetype/kakrc.kak"
    "filetype/latex.kak"
    "filetype/makefile.kak"
    "filetype/nix.kak"
    "filetype/python.kak"
    "filetype/rust.kak"
    "filetype/sh.kak"
    "filetype/sql.kak"
    "filetype/svelte.kak"
    "filetype/swift.kak"
    "filetype/toml.kak"
    "filetype/yaml.kak"

    "detection"
    "tools"
    ];

    extraPackages = with pkgs; [
    kak-lsp
    kak-tabs

    gopls
    python-lsp
    rust-analyzer
    rnix-lsp

    clang-tools
    gotools

    nixfmt
    ocamlformat
    deno # for js/ts formatting
    rustfmt
    shfmt
    ];
    };

    in {
    environment.systemPackages = [ kakoune ];
    }
    72 changes: 72 additions & 0 deletions lib.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,72 @@
    { pkgs, ... }:

    # construct the kakoune package by symlinking the autoload directory, and creating a
    # wrapper kakoune script that sets KAKOUNE_RUNTIME to the symlinked autoload dir.
    with pkgs;
    { config, plugins, extraPackages, rc }:

    let
    pluginPaths = map (import ./plugins.nix { inherit pkgs; }) plugins;
    extras = symlinkJoin {
    name = "kakoune-${lib.strings.getVersion kakoune-unwrapped}-extras";

    paths = extraPackages;
    };

    in symlinkJoin {
    name = "kakoune-${lib.strings.getVersion kakoune-unwrapped}-and-config";

    paths = pluginPaths ++ [ kakoune-unwrapped ];

    postBuild = ''
    rm $out/bin/kak
    # make wrapper manually for custom PATH
    cat >$out/bin/kak <<EOF
    #! ${bash}/bin/bash -e
    export KAKOUNE_RUNTIME='$out/share/kak'
    export PATH="${extras}/bin:\$PATH"
    exec "${kakoune-unwrapped}/bin/kak" "\$@"
    EOF
    chmod +x $out/bin/kak
    ln -s ${config} $out/share/kak/autoload/config
    # set up autoload/rc manully
    # 1. remove existing rc symlink
    rm -f $out/share/kak/autoload/rc
    # 2. link things from `rc` into `basis`
    basis=$out/share/kak/autoload/basis
    mkdir -p $basis
    for pattern in "${builtins.concatStringsSep " " rc}"; do
    local paths="$(cd $out/share/kak/rc; echo $pattern)"
    for path in $paths; do
    echo "linking basis: $out/share/kak/rc/$path"
    mkdir -p $(dirname $basis/$path)
    ln -s $out/share/kak/rc/$path $basis/$path
    done
    done
    mkdir -p $out/share/kak/autoload/plugins
    for plugin in ${builtins.concatStringsSep " " pluginPaths}; do
    printf '%s\n' "linking plugin $plugin"
    ln -s "$plugin" $out/share/kak/autoload/plugins
    done
    # TODO(enricozb): link up packages under '$out/share/kak/autoload/config'
    # workaround kakoune ignoring doc files if they are symlinks
    mkdir $out/DELETE_ME
    mv $out/share/kak/doc $out/DELETE_ME
    cp -r --dereference $out/DELETE_ME/doc $out/share/kak
    rm -Rf $out/DELETE_ME
    $out/bin/kak -e q
    '';

    meta = kakoune-unwrapped.meta // {
    priority = (kakoune-unwrapped.meta.priority or 0) - 1;
    };
    }
    56 changes: 56 additions & 0 deletions plugins.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    { pkgs, ... }:

    let
    plugins = {
    "enricozb/beancount.kak" = {
    owner = "enricozb";
    repo = "beancount.kak";
    rev = "v0.4.0";
    sha256 = "06vi8fryljzbnd9dk7arl9hql9g1pccr61pghqfh8hsnkv6l5k6r";
    };

    "enricozb/cursors.kak" = {
    owner = "enricozb";
    repo = "cursors.kak";
    rev = "v0.1.0";
    sha256 = "1zqmd122rr48vhbq738lk3y767x79j5mcsp9wbwykln9a0d143kv";
    };

    "enricozb/mapeval.kak" = {
    owner = "enricozb";
    repo = "mapeval.kak";
    rev = "87f8819934aa5df909714b35a371f84934ebe5fb";
    sha256 = "NUfzjC8KLzR5+p2dLrosCrvL/2ZzafIH6Zz1R0XO0gY=";
    };

    "enricozb/nix.kak" = {
    owner = "enricozb";
    repo = "nix.kak";
    rev = "v0.1.1";
    sha256 = "1p1p6yqzdgr092dvndfahw7x8hd558g6xydys9j2az9gzy86bz0v";
    };

    "enricozb/tabs.kak" = {
    owner = "enricozb";
    repo = "tabs.kak";
    rev = "v0.1.5";
    sha256 = "0zcsk1difl2wbgns0gp8a4qm89fhik9avpwqw9ri7dkl57kpmnjm";
    };

    "enricozb/wiki.kak" = {
    owner = "enricozb";
    repo = "wiki.kak";
    rev = "v0.1.1";
    sha256 = "1f0fllnmjmsnqf4kiqwmraiw5j2kil8gbcxwsnsnfirvxpvvfm31";
    };

    "kak-lsp/kak-lsp" = {
    owner = "kak-lsp";
    repo = "kak-lsp";
    rev = "v14.1.0";
    sha256 = "5eGp11qPLT1fen39bZmICReK2Ly8Kg9Y3g30ZV0gk04=";
    };
    };
    in path:
    pkgs.fetchFromGitHub
    (plugins.${path} // { name = builtins.replaceStrings [ "/" ] [ "-" ] path; })