diff --git a/modules/lib/maintainers.nix b/modules/lib/maintainers.nix index 70f480d06..92686bacf 100644 --- a/modules/lib/maintainers.nix +++ b/modules/lib/maintainers.nix @@ -535,6 +535,13 @@ githubId = 1545895; name = "Nicola Squartini"; }; + timon-schelling = { + name = "Timon Schelling"; + email = "me@timon.zip"; + github = "timon-schelling"; + githubId = 36821505; + matrix = "@timon:beeper.com"; + }; toastal = { email = "toastal+nix@posteo.net"; matrix = "@toastal:matrix.org"; diff --git a/modules/misc/news.nix b/modules/misc/news.nix index f8786de2f..eb7f5e842 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -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"; condition = hostPlatform.isLinux; diff --git a/modules/modules.nix b/modules/modules.nix index ed2e177f2..d6aa97e73 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -140,6 +140,7 @@ let ./programs/khard.nix ./programs/kitty.nix ./programs/kodi.nix + ./programs/lapce.nix ./programs/lazygit.nix ./programs/ledger.nix ./programs/less.nix diff --git a/modules/programs/lapce.nix b/modules/programs/lapce.nix new file mode 100644 index 000000000..f3fd24f28 --- /dev/null +++ b/modules/programs/lapce.nix @@ -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 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 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; + }; + }; +} diff --git a/tests/default.nix b/tests/default.nix index 4117ea8ea..63fda7342 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -96,6 +96,7 @@ in import nmtSrc { ./modules/programs/khal ./modules/programs/khard ./modules/programs/kitty + ./modules/programs/lapce ./modules/programs/ledger ./modules/programs/less ./modules/programs/lf diff --git a/tests/modules/programs/lapce/default.nix b/tests/modules/programs/lapce/default.nix new file mode 100644 index 000000000..21726024d --- /dev/null +++ b/tests/modules/programs/lapce/default.nix @@ -0,0 +1,4 @@ +{ + lapce-example-keymaps = ./example-keymaps.nix; + lapce-example-settings = ./example-settings.nix; +} diff --git a/tests/modules/programs/lapce/example-keymaps-expected.toml b/tests/modules/programs/lapce/example-keymaps-expected.toml new file mode 100644 index 000000000..26d4403c4 --- /dev/null +++ b/tests/modules/programs/lapce/example-keymaps-expected.toml @@ -0,0 +1,3 @@ +[[keymaps]] +command = "open_log_file" +key = "Ctrl+Shift+L" diff --git a/tests/modules/programs/lapce/example-keymaps.nix b/tests/modules/programs/lapce/example-keymaps.nix new file mode 100644 index 000000000..bf6f0a76e --- /dev/null +++ b/tests/modules/programs/lapce/example-keymaps.nix @@ -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} + ''; +} diff --git a/tests/modules/programs/lapce/example-settings-expected.toml b/tests/modules/programs/lapce/example-settings-expected.toml new file mode 100644 index 000000000..e279a54a6 --- /dev/null +++ b/tests/modules/programs/lapce/example-settings-expected.toml @@ -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 diff --git a/tests/modules/programs/lapce/example-settings.nix b/tests/modules/programs/lapce/example-settings.nix new file mode 100644 index 000000000..4851ef391 --- /dev/null +++ b/tests/modules/programs/lapce/example-settings.nix @@ -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} + ''; +}