Extract TabNine LSP config into module
Alan Pearce alan@alanpearce.eu
Tue, 08 Oct 2019 22:01:42 +0200
2 files changed, 49 insertions(+), 21 deletions(-)
A user/modules/tabnine.nix
@@ -0,0 +1,41 @@+{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.programs.tabnine; + configFile = 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)} \ + > $out + ''; +in +{ + + options.programs.tabnine = { + enable = mkEnableOption "TabNine, Smart Compose for code."; + + lspConfig = mkOption { + type = types.attrs; + default = {}; + description = '' + LSP Server configuration written to + <filename>~/.config/TabNine/TabNine.toml</filename>. + </para><para> + ''; + }; + }; + + config = mkIf cfg.enable { + xdg.configFile."TabNine/TabNine.toml" = { + source = configFile cfg.lspConfig; + }; + }; +}
M user/settings/tabnine.nix → user/settings/tabnine.nix
@@ -1,8 +1,12 @@-{ config, pkgs, ... }: +{ ... }: -let - cfg = { - config = { +{ + imports = [ + ../modules/tabnine.nix + ]; + programs.tabnine = { + enable = true; + lspConfig = { "language.typescript" = { command = "typescript-language-server"; args = ["--stdio"]; @@ -36,22 +40,5 @@ command = "hie"; args = ["--stdio"]; }; }; - }; - configFile = config: - pkgs.runCommand "TabNine.toml" - { - buildInputs = [ pkgs.remarshal ]; - preferLocalBuild = true; - allowSubstitutes = false; - } - '' - remarshal -if json -of toml \ - < ${pkgs.writeText "config.json" (builtins.toJSON cfg.config)} \ - > $out - ''; -in -{ - xdg.configFile."TabNine/TabNine.toml" = { - source = configFile cfg.config; }; }