{ config, lib, pkgs, ... }:
with lib;
let
inherit (pkgs) stdenv;
cfg = config.programs.tabnine;
lspConfigFile = config:
pkgs.runCommand "TabNine.toml"
{
buildInputs = [ pkgs.remarshal ];
preferLocalBuild = true;
allowSubstitutes = false;
}
''
remarshal -if json -of toml \
< ${pkgs.writeText "config.json" (builtins.toJSON cfg.lspConfig)} \
| sed -e 's/^\["\(.*\)"\]/[\1]/' \
> $out
'';
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
'';
};
lspConfig = mkOption {
type = types.attrs;
default = {};
description = ''
LSP Server configuration written to
\${configDir}/TabNine.toml
'';
};
};
config = mkIf cfg.enable {
home.file."${cfg.configDir}/TabNine.toml" = {
source = lspConfigFile cfg.lspConfig;
};
home.file."${cfg.configDir}/tabnine_config.json" = {
source = pkgs.writeText "tabnine_config.json" (builtins.toJSON cfg.config);
};
};
}