2018-08-18 16:13:33 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.go;
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2018-08-18 16:13:33 +02:00
|
|
|
meta.maintainers = [ maintainers.rvolosatovs ];
|
|
|
|
|
|
|
|
options = {
|
|
|
|
programs.go = {
|
2023-07-01 01:30:13 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Go");
|
2018-08-18 16:13:33 +02:00
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.go;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.go";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc "The Go package to use.";
|
2018-08-18 16:13:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
packages = mkOption {
|
|
|
|
type = with types; attrsOf path;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = { };
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''
|
2018-08-18 16:13:33 +02:00
|
|
|
{
|
2018-09-21 09:42:38 +02:00
|
|
|
"golang.org/x/text" = builtins.fetchGit "https://go.googlesource.com/text";
|
|
|
|
"golang.org/x/time" = builtins.fetchGit "https://go.googlesource.com/time";
|
2018-08-18 16:13:33 +02:00
|
|
|
}
|
|
|
|
'';
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc "Packages to add to GOPATH.";
|
2018-08-18 16:13:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
goPath = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = "go";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Primary {env}`GOPATH` relative to
|
|
|
|
{env}`HOME`. It will be exported first and therefore
|
2019-12-12 19:45:06 +01:00
|
|
|
used by default by the Go tooling.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extraGoPaths = mkOption {
|
|
|
|
type = types.listOf types.str;
|
2020-02-02 00:39:17 +01:00
|
|
|
default = [ ];
|
2019-12-12 19:45:06 +01:00
|
|
|
example = [ "extraGoPath1" "extraGoPath2" ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Extra {env}`GOPATH`s relative to {env}`HOME` appended
|
|
|
|
after [](#opt-programs.go.goPath), if that option is set.
|
2020-02-02 00:39:17 +01:00
|
|
|
'';
|
2018-08-18 16:13:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
goBin = mkOption {
|
|
|
|
type = with types; nullOr str;
|
|
|
|
default = null;
|
|
|
|
example = ".local/bin.go";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc "GOBIN relative to HOME";
|
2018-08-18 16:13:33 +02:00
|
|
|
};
|
2020-04-04 05:45:44 +02:00
|
|
|
|
|
|
|
goPrivate = mkOption {
|
|
|
|
type = with types; listOf str;
|
|
|
|
default = [ ];
|
|
|
|
example = [ "*.corp.example.com" "rsc.io/private" ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The {env}`GOPRIVATE` environment variable controls
|
2020-04-04 05:45:44 +02:00
|
|
|
which modules the go command considers to be private (not
|
|
|
|
available publicly) and should therefore not use the proxy
|
|
|
|
or checksum database.
|
|
|
|
'';
|
|
|
|
};
|
2018-08-18 16:13:33 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
home.packages = [ cfg.package ];
|
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
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);
|
2018-08-18 16:13:33 +02:00
|
|
|
}
|
2020-01-11 19:36:24 +01:00
|
|
|
|
2018-08-18 16:13:33 +02:00
|
|
|
(mkIf (cfg.goPath != null) {
|
2020-02-02 00:39:17 +01:00
|
|
|
home.sessionVariables.GOPATH = concatStringsSep ":" (map builtins.toPath
|
2019-12-12 19:45:06 +01:00
|
|
|
(map (path: "${config.home.homeDirectory}/${path}")
|
2020-02-02 00:39:17 +01:00
|
|
|
([ cfg.goPath ] ++ cfg.extraGoPaths)));
|
2018-08-18 16:13:33 +02:00
|
|
|
})
|
2020-01-11 19:36:24 +01:00
|
|
|
|
2018-08-18 16:13:33 +02:00
|
|
|
(mkIf (cfg.goBin != null) {
|
2020-02-02 00:39:17 +01:00
|
|
|
home.sessionVariables.GOBIN =
|
|
|
|
builtins.toPath "${config.home.homeDirectory}/${cfg.goBin}";
|
2018-08-18 16:13:33 +02:00
|
|
|
})
|
2020-04-04 05:45:44 +02:00
|
|
|
|
|
|
|
(mkIf (cfg.goPrivate != [ ]) {
|
|
|
|
home.sessionVariables.GOPRIVATE = concatStringsSep "," cfg.goPrivate;
|
|
|
|
})
|
2018-08-18 16:13:33 +02:00
|
|
|
]);
|
|
|
|
}
|