summary refs log tree commit diff stats
path: root/user/modules
diff options
context:
space:
mode:
authorAlan Pearce2024-12-10 19:10:29 +0100
committerAlan Pearce2024-12-10 19:34:32 +0100
commitc98dc89219bdd965b6fd3aeb31fd33335add2e3b (patch)
tree5ffae08f09f97a89663cbdd3055a33c391822b89 /user/modules
parentf4406ad7fcaaaa342fdf425a2cda0e553388be02 (diff)
downloadnixfiles-c98dc89219bdd965b6fd3aeb31fd33335add2e3b.tar.lz
nixfiles-c98dc89219bdd965b6fd3aeb31fd33335add2e3b.tar.zst
nixfiles-c98dc89219bdd965b6fd3aeb31fd33335add2e3b.zip
Revert "remove tabnine and all related configuration"
This reverts commit 1065e1ba0fce3f7295ad6017b063f6324490aacd.
Diffstat (limited to 'user/modules')
-rw-r--r--user/modules/tabnine.nix81
1 files changed, 81 insertions, 0 deletions
diff --git a/user/modules/tabnine.nix b/user/modules/tabnine.nix
new file mode 100644
index 00000000..d9b5c6c6
--- /dev/null
+++ b/user/modules/tabnine.nix
@@ -0,0 +1,81 @@
+{ config
+, lib
+, pkgs
+, ...
+}:
+with lib; let
+  inherit (pkgs) stdenv;
+  tomlFormat = pkgs.formats.toml { };
+  cfg = config.programs.tabnine;
+in
+{
+  options.programs.tabnine = {
+    enable = mkEnableOption "TabNine, Smart Compose for code.";
+
+    configDir = mkOption {
+      type = types.str;
+      default =
+        if stdenv.isDarwin
+        then "Library/Preferences/TabNine"
+        else "${config.xdg.configHome}/TabNine";
+      description = ''
+        Location of TabNine configuration directory relative to \$HOME
+      '';
+    };
+
+    config = mkOption {
+      type = types.attrs;
+      default = { };
+      description = ''
+        TabNine configuration written to
+        <filename>\${configDir}/tabnine_config.json</filename>
+      '';
+    };
+
+    registrationKey = mkOption {
+      type = types.str;
+      description = ''
+        Registration key for TabNine.  For one-time-purchase users, this should be the e-mail address and base-64-encoded key joined together without spacing.
+      '';
+    };
+
+    lspConfig = mkOption {
+      type = tomlFormat.type;
+      default = { };
+      description = ''
+        LSP Server configuration written to
+        <filename>\${configDir}/TabNine.toml</filename>
+        </para><para>
+      '';
+    };
+  };
+
+  config = mkIf cfg.enable {
+    home.file."${cfg.configDir}/TabNine.toml" = {
+      source = (tomlFormat.generate "TabNine.toml" cfg.lspConfig);
+    };
+    home.file."${cfg.configDir}/tabnine_config.json" = {
+      source = pkgs.writeText "tabnine_config.json" (builtins.toJSON cfg.config);
+    };
+    home.file."${cfg.configDir}/registration_key" = {
+      text = cfg.registrationKey;
+    };
+
+    programs.neovim.plugins = [
+      pkgs.vimPlugins.coc-tabnine
+    ];
+    programs.neovim.coc.settings = {
+      "tabnine.binary_path" = "${pkgs.tabnine}/bin/TabNine";
+    };
+
+    programs.emacs.extraPackages = epkgs: [
+      epkgs.tabnine
+    ];
+    programs.emacs.extraConfig = ''
+      (defun my/override-tabnine-exe-path (&rest args)
+        "${pkgs.tabnine}/bin/TabNine")
+      (with-eval-after-load 'tabnine-core
+        (advice-add 'tabnine--executable-path :override #'my/override-tabnine-exe-path))
+    '';
+  };
+}