all repos — nixfiles @ 6ad10b9f40527a2e7c279734361fc0e13f5ee373

System and user configuration, managed by nix and home-manager

user/modules/tabnine.nix (view raw)

{
  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
        \${configDir}/tabnine_config.json
      '';
    };

    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
        \${configDir}/TabNine.toml
        
      '';
    };
  };

  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.nixvim.plugins = {
      blink-compat.enable = true;
      cmp-tabnine.enable = true;
    };

    programs.emacs.extraPackages = epkgs: [
      epkgs.tabnine
    ];
  };
}