Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions docs/reference/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:*

```
[
<derivation delve-1.24.2>
<derivation gopls-0.18.1>
<derivation gotools-0.30.0>
<derivation gomodifytags-1.17.0>
<derivation impl-1.4.0>
<derivation go-tools-2025.1.1>
<derivation golines-0.12.2>
<derivation gotests-1.6.0>
<derivation iferr-0-unstable-2024-01-22>
]
```



*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


Expand Down
79 changes: 79 additions & 0 deletions docs/supported-languages/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:*

```
[
<derivation delve-1.24.2>
<derivation gopls-0.18.1>
<derivation gotools-0.30.0>
<derivation gomodifytags-1.17.0>
<derivation impl-1.4.0>
<derivation go-tools-2025.1.1>
<derivation golines-0.12.2>
<derivation gotests-1.6.0>
<derivation iferr-0-unstable-2024-01-22>
]
```



*Example:*
` [ pkgs.gopls ] `
78 changes: 59 additions & 19 deletions src/modules/languages/go.nix
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
Expand All @@ -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";

Expand Down