diff --git a/plugins/lsp/language-servers/default.nix b/plugins/lsp/language-servers/default.nix index cad8a466..de0cf57a 100644 --- a/plugins/lsp/language-servers/default.nix +++ b/plugins/lsp/language-servers/default.nix @@ -4,11 +4,9 @@ config, pkgs, ... -}@args: +}: with lib; let - nixdSettings = import ./nixd.nix args; - servers = [ { name = "ansiblels"; @@ -408,7 +406,10 @@ let description = "nixd for Nix"; package = pkgs.nixd; settings = cfg: { nixd = cfg; }; - settingsOptions = nixdSettings.options; + settingsOptions = import ./nixd-settings.nix { inherit lib helpers; }; + extraConfig = cfg: { + extraPackages = optional (cfg.settings.formatting.command == [ "nixpkgs-fmt" ]) pkgs.nixpkgs-fmt; + }; } { name = "nushell"; @@ -683,6 +684,4 @@ in ./rust-analyzer.nix ./svelte.nix ]; - - config = lib.mkMerge [ nixdSettings.config ]; } diff --git a/plugins/lsp/language-servers/nixd-settings.nix b/plugins/lsp/language-servers/nixd-settings.nix new file mode 100644 index 00000000..a95f5c45 --- /dev/null +++ b/plugins/lsp/language-servers/nixd-settings.nix @@ -0,0 +1,46 @@ +{ lib, helpers }: +# Options: +# - https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md +# - https://github.com/nix-community/nixd/blob/main/nixd/include/nixd/Controller/Configuration.h +with lib; +{ + formatting = { + command = helpers.defaultNullOpts.mkListOf types.str ''[ "nixpkgs-fmt" ]'' '' + Which command you would like to do formatting. + Explicitly set to `["nixpkgs-fmt"]` will automatically add `pkgs.nixpkgs-fmt` to the nixvim + environment. + ''; + }; + + options = + let + provider = types.submodule { + options = { + expr = mkOption { + type = types.str; + description = "Expression to eval. Select this attrset as eval .options"; + }; + }; + }; + in + helpers.mkNullOrOption (with helpers.nixvimTypes; attrsOf (maybeRaw provider)) '' + Tell the language server your desired option set, for completion. + This is lazily evaluated. + ''; + + nixpkgs = + let + provider = types.submodule { + options = { + expr = mkOption { + type = types.str; + description = "Expression to eval. Treat it as `import { }`"; + }; + }; + }; + in + helpers.mkNullOrOption (helpers.nixvimTypes.maybeRaw provider) '' + This expression will be interpreted as "nixpkgs" toplevel + Nixd provides package, lib completion/information from it. + ''; +} diff --git a/plugins/lsp/language-servers/nixd.nix b/plugins/lsp/language-servers/nixd.nix deleted file mode 100644 index 1fcf766a..00000000 --- a/plugins/lsp/language-servers/nixd.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ - lib, - helpers, - config, - pkgs, - ... -}: -with lib; -let - cfg = config.plugins.lsp.servers.nixd; -in -{ - # Options: - # - https://github.com/nix-community/nixd/blob/main/nixd/docs/configuration.md - # - https://github.com/nix-community/nixd/blob/main/nixd/include/nixd/Controller/Configuration.h - options = { - formatting = { - command = helpers.defaultNullOpts.mkListOf types.str ''[ "nixpkgs-fmt" ]'' '' - Which command you would like to do formatting. - Explicitly set to `["nixpkgs-fmt"]` will automatically add `pkgs.nixpkgs-fmt` to the nixvim - environment. - ''; - }; - - options = - let - provider = types.submodule { - options = { - expr = mkOption { - type = types.str; - description = "Expression to eval. Select this attrset as eval .options"; - }; - }; - }; - in - helpers.mkNullOrOption (with helpers.nixvimTypes; attrsOf (maybeRaw provider)) '' - Tell the language server your desired option set, for completion. - This is lazily evaluated. - ''; - - nixpkgs = - let - provider = types.submodule { - options = { - expr = mkOption { - type = types.str; - description = "Expression to eval. Treat it as `import { }`"; - }; - }; - }; - in - helpers.mkNullOrOption (helpers.nixvimTypes.maybeRaw provider) '' - This expression will be interpreted as "nixpkgs" toplevel - Nixd provides package, lib completion/information from it. - ''; - }; - - config = mkIf cfg.enable { - extraPackages = optional (cfg.settings.formatting.command == [ "nixpkgs-fmt" ]) pkgs.nixpkgs-fmt; - }; -}