2020-10-12 00:22:58 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.go;
|
|
|
|
|
|
|
|
in {
|
|
|
|
meta.maintainers = [ maintainers.rvolosatovs ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.go = {
|
|
|
|
enable = mkEnableOption "Go";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.go;
|
2021-11-04 16:42:44 +00:00
|
|
|
defaultText = literalExpression "pkgs.go";
|
2020-10-12 00:22:58 +00:00
|
|
|
description = "The Go package to use.";
|
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
|
|
|
type = with types; attrsOf path;
|
|
|
|
default = { };
|
2021-11-04 16:42:44 +00:00
|
|
|
example = literalExpression ''
|
2020-10-12 00:22:58 +00:00
|
|
|
{
|
|
|
|
"golang.org/x/text" = builtins.fetchGit "https://go.googlesource.com/text";
|
|
|
|
"golang.org/x/time" = builtins.fetchGit "https://go.googlesource.com/time";
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
description = "Packages to add to GOPATH.";
|
|
|
|
};
|
|
|
|
|
|
|
|
goPath = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "go";
|
|
|
|
description = ''
|
2023-08-08 10:19:01 +00:00
|
|
|
Primary {env}`GOPATH` relative to
|
|
|
|
{env}`HOME`. It will be exported first and therefore
|
2020-10-12 00:22:58 +00:00
|
|
|
used by default by the Go tooling.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraGoPaths = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "extraGoPath1" "extraGoPath2" ];
|
2023-01-10 09:35:00 +00:00
|
|
|
description = ''
|
2023-08-08 10:19:01 +00:00
|
|
|
Extra {env}`GOPATH`s relative to {env}`HOME` appended
|
|
|
|
after [](#opt-programs.go.goPath), if that option is set.
|
2020-10-12 00:22:58 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
goBin = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = ".local/bin.go";
|
|
|
|
description = "GOBIN relative to HOME";
|
|
|
|
};
|
|
|
|
|
|
|
|
goPrivate = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "*.corp.example.com" "rsc.io/private" ];
|
|
|
|
description = ''
|
2023-08-08 10:19:01 +00:00
|
|
|
The {env}`GOPRIVATE` environment variable controls
|
2020-10-12 00:22:58 +00:00
|
|
|
which modules the go command considers to be private (not
|
|
|
|
available publicly) and should therefore not use the proxy
|
|
|
|
or checksum database.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
|
|
|
home.file = let
|
|
|
|
goPath = if cfg.goPath != null then cfg.goPath else "go";
|
|
|
|
mkSrc = n: v: { "${goPath}/src/${n}".source = v; };
|
|
|
|
in foldl' (a: b: a // b) { } (mapAttrsToList mkSrc cfg.packages);
|
|
|
|
}
|
|
|
|
|
|
|
|
(mkIf (cfg.goPath != null) {
|
|
|
|
home.sessionVariables.GOPATH = concatStringsSep ":" (map builtins.toPath
|
|
|
|
(map (path: "${config.home.homeDirectory}/${path}")
|
|
|
|
([ cfg.goPath ] ++ cfg.extraGoPaths)));
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.goBin != null) {
|
|
|
|
home.sessionVariables.GOBIN =
|
|
|
|
builtins.toPath "${config.home.homeDirectory}/${cfg.goBin}";
|
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (cfg.goPrivate != [ ]) {
|
|
|
|
home.sessionVariables.GOPRIVATE = concatStringsSep "," cfg.goPrivate;
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|