diff --git a/docs/reference/options.md b/docs/reference/options.md index 0b37a2fa0f..cd1b817af9 100644 --- a/docs/reference/options.md +++ b/docs/reference/options.md @@ -12374,6 +12374,94 @@ package +## languages.go.tools.enable + + + +Enable Go tools (lsp, debugger \& various linter) which +must be built with the same Go ` package `. + + + +*Type:* +boolean + + + +*Default:* +` true ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/languages/go.nix](https://github.com/cachix/devenv/blob/main/src/modules/languages/go.nix) + + + +## languages.go.tools.packages + + + +Go packages which need to be built with the chosen Go package. +If ` null `, then ` defaultPackages ` will be used. + + + +*Type:* +null or (list of package) + + + +*Default:* +` null ` + + + +*Example:* +` [ pkgs.gopls ] ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/languages/go.nix](https://github.com/cachix/devenv/blob/main/src/modules/languages/go.nix) + + + +## languages.go.tools.packagesDefault + + + +Packages which are used for the ` packages ` option if its ` null `. + + + +*Type:* +list of package + + + +*Default:* + +``` +[ + + + + + + + + + +] +``` + + + +*Example:* +` [ pkgs.gopls ] ` + +*Declared by:* + - [https://github.com/cachix/devenv/blob/main/src/modules/languages/go.nix](https://github.com/cachix/devenv/blob/main/src/modules/languages/go.nix) + + + ## languages.haskell.enable diff --git a/docs/supported-languages/go.md b/docs/supported-languages/go.md index 90f6c4b7d6..d500dc9f39 100644 --- a/docs/supported-languages/go.md +++ b/docs/supported-languages/go.md @@ -57,3 +57,82 @@ package *Default:* ` pkgs.go ` + + + +## languages\.go\.tools\.enable + + + +Enable Go tools (lsp, debugger \& various linter) which +must be built with the same Go ` package `\. + + + +*Type:* +boolean + + + +*Default:* +` true ` + + + +## languages\.go\.tools\.packages + + + +Go packages which need to be built with the chosen Go package\. +If ` null `, then ` defaultPackages ` will be used\. + + + +*Type:* +null or (list of package) + + + +*Default:* +` null ` + + + +*Example:* +` [ pkgs.gopls ] ` + + + +## languages\.go\.tools\.packagesDefault + + + +Packages which are used for the ` packages ` option if its ` null `\. + + + +*Type:* +list of package + + + +*Default:* + +``` +[ + + + + + + + + + +] +``` + + + +*Example:* +` [ pkgs.gopls ] ` diff --git a/src/modules/languages/go.nix b/src/modules/languages/go.nix index d8dbe457f8..aae1dc9148 100644 --- a/src/modules/languages/go.nix +++ b/src/modules/languages/go.nix @@ -1,11 +1,16 @@ -{ pkgs, config, lib, ... }: +{ pkgs +, config +, lib +, ... +}: let cfg = config.languages.go; # Override the buildGoModule function to use the specified Go package. buildGoModule = pkgs.buildGoModule.override { go = cfg.package; }; - buildWithSpecificGo = pkg: + buildWithSpecificGo = + pkg: let overrideArgs = lib.functionArgs pkg.override; in @@ -27,6 +32,51 @@ in description = "The Go package to use."; }; + tools = { + enable = lib.mkOption { + type = lib.types.bool; + default = true; + description = '' + Enable Go tools (lsp, debugger & various linter) which + must be built with the same Go `package`. + ''; + }; + + # LSP and other tools (and vs-code) should be compiled with the same Go version. + # see: https://github.com/golang/vscode-go/blob/72249dc940e5b6ec97b08e6690a5f042644e2bb5/src/goInstallTools.ts#L721 + # see: https://github.com/golang/tools/blob/master/gopls/README.md + packages = lib.mkOption { + type = lib.types.nullOr (lib.types.listOf lib.types.package); + example = lib.literalExpression "[ pkgs.gopls ]"; + default = null; + description = '' + Go packages which need to be built with the chosen Go package. + If `null`, then `defaultPackages` will be used. + ''; + }; + + packagesDefault = lib.mkOption { + type = lib.types.listOf lib.types.package; + example = lib.literalExpression "[ pkgs.gopls ]"; + default = [ + # Debugger, + pkgs.delve + # LSP, + pkgs.gopls + pkgs.gotools + pkgs.gomodifytags + pkgs.impl + pkgs.go-tools + pkgs.golines + pkgs.gotests + pkgs.iferr + ]; + description = '' + Packages which are used for the `packages` option if its `null`. + ''; + }; + }; + enableHardeningWorkaround = lib.mkOption { type = lib.types.bool; default = false; @@ -35,23 +85,13 @@ in }; config = lib.mkIf cfg.enable { - packages = [ - cfg.package - - # Required by vscode-go - (buildWithSpecificGo pkgs.delve) - - # vscode-go expects all tool compiled with the same used go version, see: https://github.com/golang/vscode-go/blob/72249dc940e5b6ec97b08e6690a5f042644e2bb5/src/goInstallTools.ts#L721 - (buildWithSpecificGo pkgs.gotools) - (buildWithSpecificGo pkgs.gomodifytags) - (buildWithSpecificGo pkgs.impl) - (buildWithSpecificGo pkgs.go-tools) - (buildWithSpecificGo pkgs.gopls) - (buildWithSpecificGo pkgs.gotests) - - # Required by vim-go - (buildWithSpecificGo pkgs.iferr) - ]; + packages = + [ + cfg.package + ] + ++ lib.optionals (cfg.tools.enable) ( + lib.map (p: buildWithSpecificGo p) (cfg.tools.packages or cfg.tools.packagesDefault) + ); hardeningDisable = lib.optional (cfg.enableHardeningWorkaround) "fortify";