1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-23 11:39:46 +01:00

lapce: add module

Adds the 'programs.lapce' module for configuring lapce text editor.
Options for settings, plugins and keymaps are available.
This commit is contained in:
Timon Schelling 2024-10-09 11:03:58 +00:00 committed by Timon Schelling
parent 038630363e
commit 3a000f71a4
10 changed files with 282 additions and 0 deletions

View file

@ -535,6 +535,13 @@
githubId = 1545895; githubId = 1545895;
name = "Nicola Squartini"; name = "Nicola Squartini";
}; };
timon-schelling = {
name = "Timon Schelling";
email = "me@timon.zip";
github = "timon-schelling";
githubId = 36821505;
matrix = "@timon:beeper.com";
};
toastal = { toastal = {
email = "toastal+nix@posteo.net"; email = "toastal+nix@posteo.net";
matrix = "@toastal:matrix.org"; matrix = "@toastal:matrix.org";

View file

@ -1700,6 +1700,16 @@ in {
''; '';
} }
{
time = "2024-08-18T11:42:08+00:00";
message = ''
A new module is available: 'programs.lapce'.
Lightning-fast and Powerful Code Editor written in Rust.
See https://lapce.dev/ for more.
'';
}
{ {
time = "2024-09-13T08:58:17+00:00"; time = "2024-09-13T08:58:17+00:00";
condition = hostPlatform.isLinux; condition = hostPlatform.isLinux;

View file

@ -140,6 +140,7 @@ let
./programs/khard.nix ./programs/khard.nix
./programs/kitty.nix ./programs/kitty.nix
./programs/kodi.nix ./programs/kodi.nix
./programs/lapce.nix
./programs/lazygit.nix ./programs/lazygit.nix
./programs/ledger.nix ./programs/ledger.nix
./programs/less.nix ./programs/less.nix

187
modules/programs/lapce.nix Normal file
View file

@ -0,0 +1,187 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.lapce;
options = {
enable = mkEnableOption "lapce";
package = mkPackageOption pkgs "lapce" { };
channel = mkOption {
type = types.enum [ "stable" "nightly" ];
default = "stable";
description = ''
Lapce channel to configure.
Should correspond to the package channel.
This is used to determine the correct configuration and data directories.
'';
};
settings = mkOption {
type = settingsFormat.type;
default = { };
description = ''
Configuration written to {file}`$XDG_CONFIG_HOME/lapce/settings.toml`.
See <https://github.com/lapce/lapce/blob/master/extra/schemas/settings.json> for schema.
'';
example = literalExpression ''
{
core = {
custom-titlebar = false;
color-theme = "Custom";
icon-theme = "Material Icons";
};
editor = {
font-family = "FiraCode Nerd Bold Font, monospace";
font-size = 22;
tab-width = 2;
cursor-surrounding-lines = 4;
render-whitespace = "all";
bracket-pair-colorization = true;
highlight-matching-brackets = true;
};
ui = {
font-size = 20;
open-editors-visible = false;
};
lapce-nix.lsp-path = "$\{pkgs.nil\}/bin/nil";
}
'';
};
plugins = mkOption {
type = types.listOf (types.submodule {
options = {
author = mkOption {
type = types.str;
description = ''
Author of the plugin.
'';
};
name = mkOption {
type = types.str;
description = ''
Name of the plugin.
'';
};
version = mkOption {
type = types.str;
description = ''
Version of the plugin.
'';
};
hash = mkOption {
type = types.str;
description = ''
Hash of the plugin tarball.
To find the hash leave this empty, rebuild and copy the hash from the error message.
'';
default = "";
};
};
});
default = [ ];
description = ''
Plugins to install.
'';
example = literalExpression ''
[
{
author = "MrFoxPro";
name = "lapce-nix";
version = "0.0.1";
hash = "sha256-...";
}
{
author = "dzhou121";
name = "lapce-rust";
version = "0.3.1932";
hash = "sha256-...";
}
]
'';
};
keymaps = mkOption {
type = settingsFormat.type;
default = [ ];
description = ''
Keymaps written to {file}`$XDG_CONFIG_HOME/lapce/keymaps.toml`.
See <https://github.com/lapce/lapce/blob/master/defaults/keymaps-common.toml> for examples.
'';
example = literalExpression ''
[
{
command = "open_log_file";
key = "Ctrl+Shift+L";
}
]
'';
};
};
settingsFormat = pkgs.formats.toml { };
fetchPluginTarballFromRegistry = { 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;
nativeBuildInputs = [ pkgs.curl pkgs.cacert ];
dontUnpack = true;
dontBuild = true;
installPhase = ''
runHook preInstall
url="$(curl ${url})"
curl -L "$url" -o "$out"
runHook postInstall
'';
outputHashAlgo = "sha256";
outputHashMode = "flat";
outputHash = hash;
inherit meta;
});
pluginFromRegistry = { author, name, version, hash }@args:
pkgs.stdenvNoCC.mkDerivation {
pname = "lapce-plugin-${author}-${name}";
inherit version;
src = fetchPluginTarballFromRegistry args;
nativeBuildInputs = [ pkgs.zstd ];
phases = [ "installPhase" ];
installPhase = ''
runHook preInstall
mkdir -p $out
tar -C $out -xvf $src
runHook postInstall
'';
};
pluginsFromRegistry = plugins:
pkgs.linkFarm "lapce-plugins" (builtins.listToAttrs (builtins.map
({ author, name, version, ... }@plugin: {
name = "${author}-${name}-${version}";
value = pluginFromRegistry plugin;
}) plugins));
in {
meta.maintainers = [ hm.maintainers.timon-schelling ];
options.programs.lapce = options;
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
xdg = let dir = "lapce-${cfg.channel}";
in {
configFile = {
"${dir}/settings.toml".source =
settingsFormat.generate "settings.toml" cfg.settings;
"${dir}/keymaps.toml".source =
settingsFormat.generate "keymaps.toml" { keymaps = cfg.keymaps; };
};
dataFile."${dir}/plugins".source = pluginsFromRegistry cfg.plugins;
};
};
}

View file

@ -96,6 +96,7 @@ in import nmtSrc {
./modules/programs/khal ./modules/programs/khal
./modules/programs/khard ./modules/programs/khard
./modules/programs/kitty ./modules/programs/kitty
./modules/programs/lapce
./modules/programs/ledger ./modules/programs/ledger
./modules/programs/less ./modules/programs/less
./modules/programs/lf ./modules/programs/lf

View file

@ -0,0 +1,4 @@
{
lapce-example-keymaps = ./example-keymaps.nix;
lapce-example-settings = ./example-settings.nix;
}

View file

@ -0,0 +1,3 @@
[[keymaps]]
command = "open_log_file"
key = "Ctrl+Shift+L"

View file

@ -0,0 +1,18 @@
{ config, ... }:
{
programs.lapce = {
enable = true;
package = config.lib.test.mkStubPackage { };
keymaps = [{
command = "open_log_file";
key = "Ctrl+Shift+L";
}];
};
nmt.script = ''
assertFileContent \
home-files/.config/lapce-stable/keymaps.toml \
${./example-keymaps-expected.toml}
'';
}

View file

@ -0,0 +1,17 @@
[core]
color-theme = "Custom"
custom-titlebar = false
icon-theme = "Material Icons"
[editor]
bracket-pair-colorization = true
cursor-surrounding-lines = 4
font-family = "FiraCode Nerd Bold Font, monospace"
font-size = 22
highlight-matching-brackets = true
render-whitespace = "all"
tab-width = 2
[ui]
font-size = 20
open-editors-visible = false

View file

@ -0,0 +1,34 @@
{ config, ... }:
{
programs.lapce = {
enable = true;
package = config.lib.test.mkStubPackage { };
settings = {
core = {
custom-titlebar = false;
color-theme = "Custom";
icon-theme = "Material Icons";
};
editor = {
font-family = "FiraCode Nerd Bold Font, monospace";
font-size = 22;
tab-width = 2;
cursor-surrounding-lines = 4;
render-whitespace = "all";
bracket-pair-colorization = true;
highlight-matching-brackets = true;
};
ui = {
font-size = 20;
open-editors-visible = false;
};
};
};
nmt.script = ''
assertFileContent \
home-files/.config/lapce-stable/settings.toml \
${./example-settings-expected.toml}
'';
}