diff --git a/flake-modules/updates/none-ls.nix b/flake-modules/updates/none-ls.nix index 8a64284cce..7a3fe3ade4 100644 --- a/flake-modules/updates/none-ls.nix +++ b/flake-modules/updates/none-ls.nix @@ -5,7 +5,7 @@ pkgs, }: let - inherit (import ../../plugins/none-ls/packages.nix pkgs) packaged noPackage unpackaged; + inherit (import ../../plugins/none-ls/packages.nix pkgs) packaged noPackage; builtinSources = lib.trivial.importJSON "${vimPlugins.none-ls-nvim.src}/doc/builtins.json"; @@ -14,11 +14,11 @@ let toolNames = lib.unique (lib.flatten (lib.attrValues builtinSourceNames)); undeclaredTool = lib.filter ( - name: !(lib.hasAttr name packaged || lib.elem name noPackage || lib.elem name unpackaged) + name: !(lib.hasAttr name packaged || lib.elem name noPackage) ) toolNames; uselesslyDeclaredTool = lib.filter (name: !(lib.elem name toolNames)) ( - unpackaged ++ noPackage ++ (lib.attrNames packaged) + noPackage ++ (lib.attrNames packaged) ); in writeText "efmls-configs-sources.nix" ( diff --git a/plugins/none-ls/_mk-source-plugin.nix b/plugins/none-ls/_mk-source-plugin.nix new file mode 100644 index 0000000000..2cf25577b9 --- /dev/null +++ b/plugins/none-ls/_mk-source-plugin.nix @@ -0,0 +1,55 @@ +# mkSourcePlugin, returns a module +sourceType: sourceName: +{ + config, + pkgs, + lib, + helpers, + ... +}: +let + inherit (import ./packages.nix pkgs) packaged; + pkg = packaged.${sourceName}; + + cfg = config.plugins.none-ls; + cfg' = config.plugins.none-ls.sources.${sourceType}.${sourceName}; +in +{ + options.plugins.none-ls.sources.${sourceType}.${sourceName} = + { + enable = lib.mkEnableOption "the ${sourceName} ${sourceType} source for none-ls"; + withArgs = helpers.mkNullOrOption helpers.nixvimTypes.strLua '' + Raw Lua code passed as an argument to the source's `with` method. + ''; + } + # Only declare a package option if a package is required + // lib.optionalAttrs (packaged ? ${sourceName}) { + package = lib.mkOption ( + { + type = lib.types.nullOr lib.types.package; + description = + "Package to use for ${sourceName}." + + (lib.optionalString (pkg == null) ( + "\n\n" + + '' + Currently not packaged in nixpkgs. + Either set this to `null` and install ${sourceName} outside of nix, + or set this to a custom nix package. + '' + )); + } + // lib.optionalAttrs (pkg != null) { default = pkg; } + ); + }; + + config = lib.mkIf (cfg.enable && cfg'.enable) { + plugins.none-ls.settings.sources = lib.mkDefault [ + ( + "require('null-ls').builtins.${sourceType}.${sourceName}" + + lib.optionalString (cfg'.withArgs != null) ".with(${cfg'.withArgs})" + ) + ]; + + extraPackages = [ (cfg'.package or null) ]; + }; +} diff --git a/plugins/none-ls/default.nix b/plugins/none-ls/default.nix index e4e7b387cb..7b63befe2b 100644 --- a/plugins/none-ls/default.nix +++ b/plugins/none-ls/default.nix @@ -51,7 +51,7 @@ helpers.neovim-plugin.mkNeovimPlugin config { settingsPath = basePluginPath ++ [ "settings" ]; in [ - ./servers.nix + ./sources.nix (mkRenamedOptionModule oldPluginPath basePluginPath) (mkRenamedOptionModule (basePluginPath ++ [ "sourcesItems" ]) (settingsPath ++ [ "sources" ])) ]; diff --git a/plugins/none-ls/packages.nix b/plugins/none-ls/packages.nix index 146160fdf2..1b3f7edb76 100644 --- a/plugins/none-ls/packages.nix +++ b/plugins/none-ls/packages.nix @@ -1,46 +1,4 @@ pkgs: { - # builtin sources that are not packaged in nixpkgs - unpackaged = [ - "blade_formatter" - "bsfmt" - "bslint" - "cljstyle" - "cueimports" - "erb_lint" - "findent" - "forge_fmt" - "gccdiag" - "gersemi" - "markuplint" - "mlint" - "nginx_beautifier" - "npm_groovy_lint" - "ocdc" - "packer" - "perlimports" - "pint" - "pretty_php" - "purs_tidy" - "pyink" - "reek" - "regal" - "remark" - "rescript" - "saltlint" - "solhint" - "spectral" - "sqlfmt" - "sql_formatter" - "styler" - "stylint" - "swiftformat" - "swiftlint" - "textidote" - "textlint" - "twigcs" - "vacuum" - ]; - # builtin sources that don't require a package noPackage = [ "gitrebase" @@ -60,163 +18,205 @@ pkgs: { ]; # nixpkgs packages for a given source - packaged = { - inherit (pkgs) - actionlint - alejandra - asmfmt - astyle - bibclean - biome - buf - cbfmt - checkmake - checkstyle - clazy - codespell - commitlint - cppcheck - csharpier - deadnix - dfmt - djhtml - djlint - erlfmt - fantomas - fish - fnlfmt - fprettify - gitlint - gofumpt - golines - hadolint - hclfmt - isort - joker - just - ktlint - leptosfmt - mdformat - mdl - mypy - pmd - prettierd - proselint - protolint - pylint - revive - rstcheck - rubocop - rubyfmt - rufo - rustywind - scalafmt - selene - semgrep - shellharden - shfmt - smlfmt - sqlfluff - statix - stylelint - stylua - tfsec - topiary - treefmt - trivy - typstfmt - typstyle - uncrustify - usort - vale - verilator - yamlfix - yamlfmt - yamllint - yapf - zprint - zsh - ; - inherit (pkgs.nodePackages) alex prettier; - inherit (pkgs.python3.pkgs) black; - inherit (pkgs.phpPackages) phpmd phpstan; - inherit (pkgs.rubyPackages) htmlbeautifier; - inherit (pkgs.ocamlPackages) ocamlformat; - ansiblelint = pkgs.ansible-lint; - bean_check = pkgs.beancount; - bean_format = pkgs.beancount; - blackd = pkgs.black; - buildifier = pkgs.bazel-buildtools; - cfn_lint = pkgs.python3.pkgs.cfn-lint; - clang_format = pkgs.clang-tools; - clj_kondo = pkgs.clj-kondo; - cmake_format = pkgs.cmake-format; - cmake_lint = pkgs.cmake-format; - credo = pkgs.elixir; - crystal_format = pkgs.crystal; - cue_fmt = pkgs.cue; - d2_fmt = pkgs.d2; - dart_format = pkgs.dart; - dictionary = pkgs.curl; - dotenv_linter = pkgs.dotenv-linter; - dxfmt = pkgs.dioxus-cli; - editorconfig_checker = pkgs.editorconfig-checker; - elm_format = pkgs.elmPackages.elm-format; - emacs_scheme_mode = pkgs.emacs; - emacs_vhdl_mode = pkgs.emacs; - erb_format = pkgs.rubyPackages.erb-formatter; - fish_indent = pkgs.fish; - format_r = pkgs.R; - # TODO: Added 2024-06-13; remove 2024-09-13 - # Nixpkgs renamed to _3 & _4 without maintaining an alias - # Out of sync lock files could be using either attr name... - gdformat = pkgs.gdtoolkit_4 or pkgs.gdtoolkit; - gdlint = pkgs.gdtoolkit_4 or pkgs.gdtoolkit; - gitsigns = pkgs.git; - gleam_format = pkgs.gleam; - glslc = pkgs.shaderc; - gn_format = pkgs.gn; - gofmt = pkgs.go; - goimports = pkgs.gotools; - goimports_reviser = pkgs.goimports-reviser; - golangci_lint = pkgs.golangci-lint; - google_java_format = pkgs.google-java-format; - haml_lint = pkgs.mastodon; - haxe_formatter = pkgs.haxe; - isortd = pkgs.isort; - ltrs = pkgs.languagetool-rust; - markdownlint_cli2 = pkgs.markdownlint-cli2; - markdownlint = pkgs.nodePackages.markdownlint-cli; - mix = pkgs.elixir; - nimpretty = pkgs.nim; - nixfmt = pkgs.nixfmt-classic; - nixpkgs_fmt = pkgs.nixpkgs-fmt; - opacheck = pkgs.open-policy-agent; - opentofu_fmt = pkgs.opentofu; - pg_format = pkgs.pgformatter; - phpcbf = pkgs.phpPackages.php-codesniffer; - phpcsfixer = pkgs.phpPackages.php-cs-fixer; - phpcs = pkgs.phpPackages.php-codesniffer; - prisma_format = pkgs.nodePackages.prisma; - ptop = pkgs.fpc; - puppet_lint = pkgs.puppet-lint; - qmlformat = pkgs.qt6.qtdeclarative; - qmllint = pkgs.qt6.qtdeclarative; - racket_fixw = pkgs.racket; - raco_fmt = pkgs.racket; - rego = pkgs.open-policy-agent; - rpmspec = pkgs.rpm; - sqlformat = pkgs.python3.pkgs.sqlparse; - staticcheck = pkgs.go-tools; - surface = pkgs.elixir; - swift_format = pkgs.swift-format; - teal = pkgs.luaPackages.tl; - terraform_fmt = pkgs.terraform; - terraform_validate = pkgs.terraform; - tidy = pkgs.html-tidy; - verible_verilog_format = pkgs.verible; - vint = pkgs.vim-vint; - write_good = pkgs.write-good; - xmllint = pkgs.libxml2; - }; + packaged = + { + inherit (pkgs) + actionlint + alejandra + asmfmt + astyle + bibclean + biome + buf + cbfmt + checkmake + checkstyle + clazy + codespell + commitlint + cppcheck + csharpier + deadnix + dfmt + djhtml + djlint + erlfmt + fantomas + fish + fnlfmt + fprettify + gitlint + gofumpt + golines + hadolint + hclfmt + isort + joker + just + ktlint + leptosfmt + mdformat + mdl + mypy + pmd + prettierd + proselint + protolint + pylint + revive + rstcheck + rubocop + rubyfmt + rufo + rustywind + scalafmt + selene + semgrep + shellharden + shfmt + smlfmt + sqlfluff + statix + stylelint + stylua + tfsec + topiary + treefmt + trivy + typstfmt + typstyle + uncrustify + usort + vale + verilator + yamlfix + yamlfmt + yamllint + yapf + zprint + zsh + ; + inherit (pkgs.nodePackages) alex prettier; + inherit (pkgs.python3.pkgs) black; + inherit (pkgs.phpPackages) phpmd phpstan; + inherit (pkgs.rubyPackages) htmlbeautifier; + inherit (pkgs.ocamlPackages) ocamlformat; + ansiblelint = pkgs.ansible-lint; + bean_check = pkgs.beancount; + bean_format = pkgs.beancount; + blackd = pkgs.black; + buildifier = pkgs.bazel-buildtools; + cfn_lint = pkgs.python3.pkgs.cfn-lint; + clang_format = pkgs.clang-tools; + clj_kondo = pkgs.clj-kondo; + cmake_format = pkgs.cmake-format; + cmake_lint = pkgs.cmake-format; + credo = pkgs.elixir; + crystal_format = pkgs.crystal; + cue_fmt = pkgs.cue; + d2_fmt = pkgs.d2; + dart_format = pkgs.dart; + dictionary = pkgs.curl; + dotenv_linter = pkgs.dotenv-linter; + dxfmt = pkgs.dioxus-cli; + editorconfig_checker = pkgs.editorconfig-checker; + elm_format = pkgs.elmPackages.elm-format; + emacs_scheme_mode = pkgs.emacs; + emacs_vhdl_mode = pkgs.emacs; + erb_format = pkgs.rubyPackages.erb-formatter; + fish_indent = pkgs.fish; + format_r = pkgs.R; + # TODO: Added 2024-06-13; remove 2024-09-13 + # Nixpkgs renamed to _3 & _4 without maintaining an alias + # Out of sync lock files could be using either attr name... + gdformat = pkgs.gdtoolkit_4 or pkgs.gdtoolkit; + gdlint = pkgs.gdtoolkit_4 or pkgs.gdtoolkit; + gitsigns = pkgs.git; + gleam_format = pkgs.gleam; + glslc = pkgs.shaderc; + gn_format = pkgs.gn; + gofmt = pkgs.go; + goimports = pkgs.gotools; + goimports_reviser = pkgs.goimports-reviser; + golangci_lint = pkgs.golangci-lint; + google_java_format = pkgs.google-java-format; + haml_lint = pkgs.mastodon; + haxe_formatter = pkgs.haxe; + isortd = pkgs.isort; + ltrs = pkgs.languagetool-rust; + markdownlint_cli2 = pkgs.markdownlint-cli2; + markdownlint = pkgs.nodePackages.markdownlint-cli; + mix = pkgs.elixir; + nimpretty = pkgs.nim; + nixfmt = pkgs.nixfmt-classic; + nixpkgs_fmt = pkgs.nixpkgs-fmt; + opacheck = pkgs.open-policy-agent; + opentofu_fmt = pkgs.opentofu; + pg_format = pkgs.pgformatter; + phpcbf = pkgs.phpPackages.php-codesniffer; + phpcsfixer = pkgs.phpPackages.php-cs-fixer; + phpcs = pkgs.phpPackages.php-codesniffer; + prisma_format = pkgs.nodePackages.prisma; + ptop = pkgs.fpc; + puppet_lint = pkgs.puppet-lint; + qmlformat = pkgs.qt6.qtdeclarative; + qmllint = pkgs.qt6.qtdeclarative; + racket_fixw = pkgs.racket; + raco_fmt = pkgs.racket; + rego = pkgs.open-policy-agent; + rpmspec = pkgs.rpm; + sqlformat = pkgs.python3.pkgs.sqlparse; + staticcheck = pkgs.go-tools; + surface = pkgs.elixir; + swift_format = pkgs.swift-format; + teal = pkgs.luaPackages.tl; + terraform_fmt = pkgs.terraform; + terraform_validate = pkgs.terraform; + tidy = pkgs.html-tidy; + verible_verilog_format = pkgs.verible; + vint = pkgs.vim-vint; + write_good = pkgs.write-good; + xmllint = pkgs.libxml2; + } + # builtin sources that are not packaged in nixpkgs + // pkgs.lib.genAttrs [ + "blade_formatter" + "bsfmt" + "bslint" + "cljstyle" + "cueimports" + "erb_lint" + "findent" + "forge_fmt" + "gccdiag" + "gersemi" + "markuplint" + "mlint" + "nginx_beautifier" + "npm_groovy_lint" + "ocdc" + "packer" + "perlimports" + "pint" + "pretty_php" + "purs_tidy" + "pyink" + "reek" + "regal" + "remark" + "rescript" + "saltlint" + "solhint" + "spectral" + "sqlfmt" + "sql_formatter" + "styler" + "stylint" + "swiftformat" + "swiftlint" + "textidote" + "textlint" + "twigcs" + "vacuum" + ] (_: null); } diff --git a/plugins/none-ls/servers.nix b/plugins/none-ls/servers.nix deleted file mode 100644 index d37020017c..0000000000 --- a/plugins/none-ls/servers.nix +++ /dev/null @@ -1,82 +0,0 @@ -{ - pkgs, - config, - lib, - helpers, - ... -}: -let - noneLsBuiltins = import ../../generated/none-ls.nix; - - inherit (import ./packages.nix pkgs) packaged unpackaged; - - # Does this builitin require a package ? - builitinNeedsPackage = source: lib.hasAttr source packaged || lib.elem source unpackaged; -in -{ - imports = [ ./prettier.nix ]; - - options.plugins.none-ls.sources = lib.mapAttrs ( - sourceType: sources: - lib.listToAttrs ( - lib.map (source: { - name = source; - value = - { - enable = lib.mkEnableOption "the ${source} ${sourceType} source for none-ls"; - withArgs = helpers.mkNullOrOption helpers.nixvimTypes.strLua '' - Raw Lua code passed as an argument to the source's `with` method. - ''; - } - // lib.optionalAttrs (builitinNeedsPackage source) { - package = - let - pkg = packaged.${source} or null; - in - lib.mkOption ( - { - type = lib.types.nullOr lib.types.package; - description = - "Package to use for ${source} by none-ls. " - + (lib.optionalString (pkg == null) '' - Not handled in nixvim, either install externally and set to null or set the option with a derivation. - ''); - } - // lib.optionalAttrs (pkg != null) { default = pkg; } - ); - }; - }) sources - ) - ) noneLsBuiltins; - - config = - let - cfg = config.plugins.none-ls; - gitsignsEnabled = cfg.sources.code_actions.gitsigns.enable; - - flattenedSources = lib.flatten ( - lib.mapAttrsToList ( - sourceType: sources: - (lib.mapAttrsToList (sourceName: source: source // { inherit sourceType sourceName; }) sources) - ) cfg.sources - ); - - enabledSources = builtins.filter (source: source.enable) flattenedSources; - in - lib.mkIf cfg.enable { - plugins.none-ls.settings.sources = lib.mkIf (enabledSources != [ ]) ( - map ( - { - sourceType, - sourceName, - withArgs, - ... - }: - "require('null-ls').builtins.${sourceType}.${sourceName}" - + lib.optionalString (withArgs != null) ".with(${withArgs})" - ) enabledSources - ); - plugins.gitsigns.enable = lib.mkIf gitsignsEnabled true; - extraPackages = map (source: source.package or null) enabledSources; - }; -} diff --git a/plugins/none-ls/sources.nix b/plugins/none-ls/sources.nix new file mode 100644 index 0000000000..16a470230b --- /dev/null +++ b/plugins/none-ls/sources.nix @@ -0,0 +1,22 @@ +{ config, lib, ... }: +let + noneLsBuiltins = import ../../generated/none-ls.nix; + mkSourcePlugin = import ./_mk-source-plugin.nix; +in +{ + imports = + [ ./prettier.nix ] + ++ (lib.flatten ( + lib.mapAttrsToList (category: (lib.map (mkSourcePlugin category))) noneLsBuiltins + )); + + config = + let + cfg = config.plugins.none-ls; + gitsignsEnabled = cfg.sources.code_actions.gitsigns.enable; + in + lib.mkIf cfg.enable { + # Enable gitsigns if the gitsigns source is enabled + plugins.gitsigns.enable = lib.mkIf gitsignsEnabled true; + }; +} diff --git a/tests/fetch-tests.nix b/tests/fetch-tests.nix index 7cb5229e75..0e86a19c4d 100644 --- a/tests/fetch-tests.nix +++ b/tests/fetch-tests.nix @@ -53,10 +53,6 @@ let inherit pkgs lib helpers; config = { }; }; - nonels-sources-options = import ../plugins/none-ls/servers.nix { - inherit pkgs lib helpers; - config = { }; - }; }; inherit namespace; } diff --git a/tests/test-sources/plugins/none-ls.nix b/tests/test-sources/plugins/none-ls.nix index 6a9a43192a..9a13dcc89d 100644 --- a/tests/test-sources/plugins/none-ls.nix +++ b/tests/test-sources/plugins/none-ls.nix @@ -1,4 +1,3 @@ -{ pkgs, nonels-sources-options, ... }: { # Empty configuration empty = { @@ -100,95 +99,70 @@ }; with-sources = { - plugins.none-ls = { - # sandbox-exec: pattern serialization length 159032 exceeds maximum (65535) - enable = !pkgs.stdenv.isDarwin; - - sources = - let - options = nonels-sources-options.options.plugins.none-ls.sources; - - unpackaged = - [ - "blade_formatter" - "bsfmt" - "bslint" - "cljstyle" - "cueimports" - # As of 2024-03-22, pkgs.d2 is broken - # TODO: re-enable this test when fixed - "d2_fmt" - "erb_lint" - "findent" - "forge_fmt" - "gccdiag" - "gersemi" - "markuplint" - "mlint" - "nginx_beautifier" - "npm_groovy_lint" - "ocdc" - "packer" - "perlimports" - "pint" - "pretty_php" - "purs_tidy" - "pyink" - "reek" - "regal" - "remark" - "rescript" - "saltlint" - "solhint" - "spectral" - "sqlfmt" - "sql_formatter" - "styler" - "stylint" - "swiftformat" - "swiftlint" - "textidote" - "textlint" - "twigcs" - "vacuum" - "yamlfix" - ] - ++ (pkgs.lib.optionals (pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64) [ - # As of 2024-03-27, pkgs.graalvm-ce (a dependency of pkgs.clj-kondo) is broken on x86_64-darwin - # TODO: re-enable this test when fixed - "clj_kondo" - ]) - ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [ - # As of 2024-05-22, python311Packages.k5test (one of ansible-lint's dependenvies) is broken on darwin - # TODO: re-enable this test when fixed - "ansible_lint" - "clazy" - "gdformat" - "gdlint" - "haml_lint" - # As of 2024-06-29, pkgs.rubyfmt is broken on darwin - # TODO: re-enable this test when fixed - "rubyfmt" - "verilator" - "verible_verilog_format" - ]) - ++ (pkgs.lib.optionals pkgs.stdenv.isAarch64 [ - "semgrep" - "smlfmt" - # As of 2024-03-11, swift-format is broken on aarch64 - # TODO: re-enable this test when fixed - "swift_format" - ]); + module = + { + config, + options, + lib, + pkgs, + ... + }: + { + plugins.none-ls = { + # sandbox-exec: pattern serialization length 159032 exceeds maximum (65535) + enable = !pkgs.stdenv.isDarwin; - sources = pkgs.lib.mapAttrs ( - _: sources: - pkgs.lib.mapAttrs ( - source: _: - { enable = true; } // pkgs.lib.optionalAttrs (builtins.elem source unpackaged) { package = null; } - ) sources - ) options; - in - sources; - }; + sources = + let + disabled = + [ + # As of 2024-03-22, pkgs.d2 is broken + # TODO: re-enable this test when fixed + "d2_fmt" + # TODO: can this be re-enabled? + "yamlfix" + ] + ++ (lib.optionals (pkgs.stdenv.isDarwin && pkgs.stdenv.isx86_64) [ + # As of 2024-03-27, pkgs.graalvm-ce (a dependency of pkgs.clj-kondo) is broken on x86_64-darwin + # TODO: re-enable this test when fixed + "clj_kondo" + ]) + ++ (lib.optionals pkgs.stdenv.isDarwin [ + # As of 2024-05-22, python311Packages.k5test (one of ansible-lint's dependenvies) is broken on darwin + # TODO: re-enable this test when fixed + "ansible_lint" + "clazy" + "gdformat" + "gdlint" + "haml_lint" + # As of 2024-06-29, pkgs.rubyfmt is broken on darwin + # TODO: re-enable this test when fixed + "rubyfmt" + "verilator" + "verible_verilog_format" + ]) + ++ (lib.optionals pkgs.stdenv.isAarch64 [ + "semgrep" + "smlfmt" + # As of 2024-03-11, swift-format is broken on aarch64 + # TODO: re-enable this test when fixed + "swift_format" + ]); + in + # Enable every none-ls source that has an option + lib.mapAttrs ( + _: + lib.mapAttrs ( + sourceName: opts: + { + # Enable unless disabled above + enable = !(lib.elem sourceName disabled); + } + # Some sources have a package option with no default + // lib.optionalAttrs (opts ? package && !(opts.package ? default)) { package = null; } + ) + ) options.plugins.none-ls.sources; + }; + }; }; }