fork/home-manager
git clone https://git.julia.blue/fork/home-manager
75790441
master
1{ config , lib , pkgs , ...} : 2 3with lib ; 4 5let 6 7cfg = config . programs . go ; 8 9in { 10meta . maintainers = [ maintainers . rvolosatovs ]; 11 12options = { 13programs . go = { 14enable = mkEnableOption "Go" ; 15 16package = mkOption { 17type = types . package ; 18default = pkgs . go ; 19defaultText = literalExpression "pkgs.go" ; 20description = "The Go package to use." ; 21}; 22 23packages = mkOption { 24type = with types ; attrsOf path ; 25default = { }; 26example = literalExpression '' 27{ 28"golang.org/x/text" = builtins.fetchGit "https://go.googlesource.com/text"; 29"golang.org/x/time" = builtins.fetchGit "https://go.googlesource.com/time"; 30} 31'' ; 32description = "Packages to add to GOPATH." ; 33}; 34 35goPath = mkOption { 36type = with types ; nullOr str ; 37default = null ; 38example = "go" ; 39description = '' 40Primary {env}`GOPATH` relative to 41{env}`HOME`. It will be exported first and therefore 42used by default by the Go tooling. 43'' ; 44}; 45 46extraGoPaths = mkOption { 47type = types . listOf types . str ; 48default = [ ]; 49example = [ "extraGoPath1" "extraGoPath2" ]; 50description = '' 51Extra {env}`GOPATH`s relative to {env}`HOME` appended 52after [](#opt-programs.go.goPath), if that option is set. 53'' ; 54}; 55 56goBin = mkOption { 57type = with types ; nullOr str ; 58default = null ; 59example = ".local/bin.go" ; 60description = "GOBIN relative to HOME" ; 61}; 62 63goPrivate = mkOption { 64type = with types ; listOf str ; 65default = [ ]; 66example = [ "*.corp.example.com" "rsc.io/private" ]; 67description = '' 68The {env}`GOPRIVATE` environment variable controls 69which modules the go command considers to be private (not 70available publicly) and should therefore not use the proxy 71or checksum database. 72'' ; 73}; 74}; 75}; 76 77config = mkIf cfg . enable ( mkMerge [ 78{ 79home . packages = [ cfg . package ]; 80 81home . file = let 82goPath = if cfg . goPath != null then cfg . goPath else "go" ; 83mkSrc = n :v :{ " ${ goPath } /src/ ${ n } " . source = v ; }; 84in foldl' ( a :b :a // b ) { } ( mapAttrsToList mkSrc cfg . packages ); 85} 86 87( mkIf ( cfg . goPath != null ) { 88home . sessionVariables . GOPATH = concatStringsSep ":" ( map builtins . toPath 89( map ( path :" ${ config . home . homeDirectory } / ${ path } " ) 90([ cfg . goPath ] ++ cfg . extraGoPaths ))); 91}) 92 93( mkIf ( cfg . goBin != null ) { 94home . sessionVariables . GOBIN = 95builtins . toPath " ${ config . home . homeDirectory } / ${ cfg . goBin } " ; 96}) 97 98( mkIf ( cfg . goPrivate != [ ]) { 99home . sessionVariables . GOPRIVATE = concatStringsSep "," cfg . goPrivate ; 100}) 101]); 102}