From a8a7e405f413708ce42dca436105e6210a15278a Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Tue, 3 Sep 2024 16:15:48 +0100 Subject: [PATCH] plugins/efmls: use `mkPackageOption` --- .../language-servers/efmls-configs-pkgs.nix | 258 ++++++++++-------- .../lsp/language-servers/efmls-configs.nix | 12 +- tests/generated.nix | 2 +- 3 files changed, 153 insertions(+), 119 deletions(-) diff --git a/plugins/lsp/language-servers/efmls-configs-pkgs.nix b/plugins/lsp/language-servers/efmls-configs-pkgs.nix index f9277d8e..e5703b95 100644 --- a/plugins/lsp/language-servers/efmls-configs-pkgs.nix +++ b/plugins/lsp/language-servers/efmls-configs-pkgs.nix @@ -1,4 +1,4 @@ -pkgs: { +lib: { # efmls-configs tools that have no corresponding nixpkgs package unpackaged = [ "blade_formatter" @@ -27,115 +27,149 @@ pkgs: { ]; # Mapping from a efmls-configs tool name to the corresponding nixpkgs package - packaged = with pkgs; { - inherit - actionlint - alejandra - ameba - astyle - bashate - beautysh - biome - black - buf - cbfmt - checkmake - clazy - codespell - cppcheck - cpplint - dfmt - djlint - dmd - dprint - fish - flawfinder - fnlfmt - gcc - gitlint - gofumpt - golines - golint - hadolint - isort - joker - jq - languagetool - mypy - php - prettypst - proselint - protolint - pylint - rubocop - ruff - rustfmt - scalafmt - selene - shellcheck - shellharden - shfmt - smlfmt - sqlfluff - statix - stylua - taplo - typstfmt - typstyle - uncrustify - vale - yamllint - yapf - ; - inherit (python3.pkgs) - autopep8 - flake8 - mdformat - vulture - ; - inherit (nodePackages) - eslint_d - prettier - alex - sql-formatter - stylelint - textlint - ; - inherit (phpPackages) phan phpstan psalm; - inherit (luaPackages) luacheck; - inherit (haskellPackages) fourmolu; - ansible_lint = ansible-lint; - chktex = texliveMedium; - clang_format = clang-tools; - clang_tidy = clang-tools; - clj_kondo = clj-kondo; - cmake_lint = cmake-format; - dartfmt = dart; - dotnet_format = dotnet-runtime; - # TODO: Added 2024-08-31; remove 2024-11-31 - # eslint was moved out of nodePackages set without alias - # Using fallback as a transition period - eslint = pkgs.eslint or pkgs.nodePackages.eslint; - fish_indent = fish; - gofmt = go; - goimports = go-tools; - golangci_lint = golangci-lint; - google_java_format = google-java-format; - go_revive = revive; - latexindent = texliveMedium; - lua_format = luaformatter; - markdownlint = markdownlint-cli; - mcs = mono; - nixfmt = nixfmt-classic; - phpcbf = phpPackages.php-codesniffer; - php_cs_fixer = phpPackages.php-cs-fixer; - phpcs = phpPackages.php-codesniffer; - prettier_d = prettierd; - slither = slither-analyzer; - staticcheck = go-tools; - terraform_fmt = terraform; - vint = vim-vint; - write_good = write-good; - yq = yq-go; - }; + packaged = + let + # TODO: move these helpers to a shared location so that none-ls can also use them + topLevel = names: lib.genAttrs names lib.id; + scoped = lib.concatMapAttrs ( + scope: v: + if builtins.isAttrs v then + lib.mapAttrs (_: loc: [ scope ] ++ loc) (scoped v) + else + lib.genAttrs (lib.toList v) (name: [ + scope + name + ]) + ); + in + # Top-level packages + topLevel [ + "actionlint" + "alejandra" + "ameba" + "astyle" + "bashate" + "beautysh" + "biome" + "black" + "buf" + "cbfmt" + "checkmake" + "clazy" + "codespell" + "cppcheck" + "cpplint" + "dfmt" + "djlint" + "dmd" + "dprint" + "fish" + "flawfinder" + "fnlfmt" + "gcc" + "gitlint" + "gofumpt" + "golines" + "golint" + "hadolint" + "isort" + "joker" + "jq" + "languagetool" + "mypy" + "php" + "prettypst" + "proselint" + "protolint" + "pylint" + "rubocop" + "ruff" + "rustfmt" + "scalafmt" + "selene" + "shellcheck" + "shellharden" + "shfmt" + "smlfmt" + "sqlfluff" + "statix" + "stylua" + "taplo" + "typstfmt" + "typstyle" + "uncrustify" + "vale" + "yamllint" + "yapf" + ] + # Scoped packages + // scoped { + python3.pkgs = [ + "autopep8" + "flake8" + "mdformat" + "vulture" + ]; + nodePackages = [ + "eslint" # FIXME: No way to have a transition fallback... + "eslint_d" + "prettier" + "alex" + "sql-formatter" + "stylelint" + "textlint" + ]; + phpPackages = [ + "phan" + "phpstan" + "psalm" + ]; + luaPackages = [ + "luacheck" + ]; + haskellPackages = [ + "fourmolu" + ]; + } + # Packages where the name is different + // { + ansible_lint = "ansible-lint"; + chktex = "texliveMedium"; + clang_format = "clang-tools"; + clang_tidy = "clang-tools"; + clj_kondo = "clj-kondo"; + cmake_lint = "cmake-format"; + dartfmt = "dart"; + dotnet_format = "dotnet-runtime"; + fish_indent = "fish"; + gofmt = "go"; + goimports = "go-tools"; + golangci_lint = "golangci-lint"; + google_java_format = "google-java-format"; + go_revive = "revive"; + latexindent = "texliveMedium"; + lua_format = "luaformatter"; + markdownlint = "markdownlint-cli"; + mcs = "mono"; + nixfmt = "nixfmt-classic"; + phpcbf = [ + "phpPackages" + "php-codesniffer" + ]; + php_cs_fixer = [ + "phpPackages" + "php-cs-fixer" + ]; + phpcs = [ + "phpPackages" + "php-codesniffer" + ]; + prettier_d = "prettierd"; + slither = "slither-analyzer"; + staticcheck = "go-tools"; + terraform_fmt = "terraform"; + vint = "vim-vint"; + write_good = "write-good"; + yq = "yq-go"; + }; } diff --git a/plugins/lsp/language-servers/efmls-configs.nix b/plugins/lsp/language-servers/efmls-configs.nix index fdc6aad0..2ab20e78 100644 --- a/plugins/lsp/language-servers/efmls-configs.nix +++ b/plugins/lsp/language-servers/efmls-configs.nix @@ -7,7 +7,7 @@ }: let tools = import ../../../generated/efmls-configs.nix; - inherit (import ./efmls-configs-pkgs.nix pkgs) packaged; + inherit (import ./efmls-configs-pkgs.nix lib) packaged; in { options.plugins.efmls-configs = { @@ -26,10 +26,10 @@ in toolPackages = lib.pipe packaged [ # Produce package a option for each tool (lib.attrsets.mapAttrs ( - tool: pkg: - helpers.mkPackageOption { - name = tool; - default = pkg; + name: loc: + lib.mkPackageOption pkgs name { + nullable = true; + default = loc; } )) # Filter package defaults that are not compatible with the current platform @@ -38,7 +38,7 @@ in if lib.meta.availableOn pkgs.stdenv.hostPlatform opt.default then opt else - opt // { default = null; } + builtins.removeAttrs opt [ "defaultText" ] // { default = null; } )) ]; diff --git a/tests/generated.nix b/tests/generated.nix index 46b763bc..c97a4fac 100644 --- a/tests/generated.nix +++ b/tests/generated.nix @@ -54,7 +54,7 @@ let declared = let - inherit (import ../plugins/lsp/language-servers/efmls-configs-pkgs.nix pkgs) packaged unpackaged; + inherit (import ../plugins/lsp/language-servers/efmls-configs-pkgs.nix lib) packaged unpackaged; in unpackaged ++ lib.attrsets.attrNames packaged;