1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-16 08:09:45 +01:00
home-manager/modules/programs/go.nix

98 lines
2.5 KiB
Nix
Raw Normal View History

2018-08-18 16:13:33 +02: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;
defaultText = literalExample "pkgs.go";
2018-08-18 16:13:33 +02:00
description = "The Go package to use.";
};
packages = mkOption {
type = with types; attrsOf path;
default = {};
example = literalExample ''
{
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
}
'';
description = "Packages to add to GOPATH.";
};
goPath = mkOption {
type = with types; nullOr str;
default = null;
example = "go";
description = ''
Primary <envar>GOPATH</envar> relative to
<envar>HOME</envar>. It will be exported first and therefore
used by default by the Go tooling.
'';
};
extraGoPaths = mkOption {
type = types.listOf types.str;
default = [];
example = [ "extraGoPath1" "extraGoPath2" ];
description =
let
goPathOpt = "programs.go.goPath";
in
''
Extra <envar>GOPATH</envar>s relative to <envar>HOME</envar> appended
after
<varname><link linkend="opt-${goPathOpt}">${goPathOpt}</link></varname>,
if that option is set.
'';
2018-08-18 16:13:33 +02:00
};
goBin = mkOption {
type = with types; nullOr str;
default = null;
example = ".local/bin.go";
description = "GOBIN relative to HOME";
};
};
};
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; };
2018-08-18 16:13:33 +02:00
in
foldl' (a: b: a // b) {} (mapAttrsToList mkSrc cfg.packages);
2018-08-18 16:13:33 +02:00
}
2018-08-18 16:13:33 +02:00
(mkIf (cfg.goPath != null) {
home.sessionVariables.GOPATH =
concatStringsSep ":"
(map builtins.toPath
(map (path: "${config.home.homeDirectory}/${path}")
([cfg.goPath] ++ cfg.extraGoPaths)));
2018-08-18 16:13:33 +02:00
})
2018-08-18 16:13:33 +02:00
(mkIf (cfg.goBin != null) {
home.sessionVariables.GOBIN = builtins.toPath "${config.home.homeDirectory}/${cfg.goBin}";
})
]);
}