From e11f110b4bf7352cf6a0b3711d34312bf6e2e784 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Sat, 18 Aug 2018 16:13:33 +0200 Subject: [PATCH] go: add module (cherry picked from commit 0635423e7365e9dbccac2fa154f53a45e952898e) --- modules/misc/news.nix | 7 ++++ modules/modules.nix | 1 + modules/programs/go.nix | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 modules/programs/go.nix diff --git a/modules/misc/news.nix b/modules/misc/news.nix index b8d4f86b3..9b3db5a4d 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -793,6 +793,13 @@ in A new module is available: 'programs.zathura'. ''; } + + { + time = "2018-09-20T22:10:45+00:00"; + message = '' + A new module is available: 'programs.go'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index a7f05eed4..703b22773 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -38,6 +38,7 @@ let ./programs/fzf.nix ./programs/git.nix ./programs/gnome-terminal.nix + ./programs/go.nix ./programs/home-manager.nix ./programs/htop.nix ./programs/info.nix diff --git a/modules/programs/go.nix b/modules/programs/go.nix new file mode 100644 index 000000000..d1817ae26 --- /dev/null +++ b/modules/programs/go.nix @@ -0,0 +1,74 @@ +{ 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 = "pkgs.go"; + description = "The Go package to use."; + }; + + packages = mkOption { + type = with types; attrsOf path; + default = {}; + example = literalExample '' + { + "golang.org/x/time/rate" = builtins.fetchGit "https://go.googlesource.com/text"; + } + ''; + description = "Packages to add to GOPATH."; + }; + + goPath = mkOption { + type = with types; nullOr str; + default = null; + example = "go"; + description = "GOPATH relative to HOME"; + }; + + 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: { + target = "${goPath}/src/${n}"; + source = v; + }; + in + mapAttrsToList mkSrc cfg.packages; + } + (mkIf (cfg.goPath != null) { + home.sessionVariables.GOPATH = builtins.toPath "${config.home.homeDirectory}/${cfg.goPath}"; + }) + (mkIf (cfg.goBin != null) { + home.sessionVariables.GOBIN = builtins.toPath "${config.home.homeDirectory}/${cfg.goBin}"; + }) + ]); +}