1
0
mirror of https://github.com/nix-community/home-manager synced 2024-07-02 11:28:32 +02:00
home-manager/modules/programs/go.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

103 lines
2.9 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.go;
in {
meta.maintainers = [ maintainers.rvolosatovs ];
options = {
programs.go = {
enable = mkEnableOption (lib.mdDoc "Go");
package = mkOption {
type = types.package;
default = pkgs.go;
defaultText = literalExpression "pkgs.go";
description = lib.mdDoc "The Go package to use.";
};
packages = mkOption {
type = with types; attrsOf path;
default = { };
example = literalExpression ''
{
"golang.org/x/text" = builtins.fetchGit "https://go.googlesource.com/text";
"golang.org/x/time" = builtins.fetchGit "https://go.googlesource.com/time";
}
'';
description = lib.mdDoc "Packages to add to GOPATH.";
};
goPath = mkOption {
type = with types; nullOr str;
default = null;
example = "go";
description = lib.mdDoc ''
Primary {env}`GOPATH` relative to
{env}`HOME`. 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 = lib.mdDoc ''
Extra {env}`GOPATH`s relative to {env}`HOME` appended
after [](#opt-programs.go.goPath), if that option is set.
'';
};
goBin = mkOption {
type = with types; nullOr str;
default = null;
example = ".local/bin.go";
description = lib.mdDoc "GOBIN relative to HOME";
};
goPrivate = mkOption {
type = with types; listOf str;
default = [ ];
example = [ "*.corp.example.com" "rsc.io/private" ];
description = lib.mdDoc ''
The {env}`GOPRIVATE` environment variable controls
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;
})
]);
}