From 0635423e7365e9dbccac2fa154f53a45e952898e Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Sat, 18 Aug 2018 16:13:33 +0200 Subject: [PATCH] go: add module --- 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 082f371a..c79962c4 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -800,6 +800,13 @@ in A new module is available: 'programs.noti'. ''; } + + { + 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 889df467..c5e96b33 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 00000000..d1817ae2 --- /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}"; + }) + ]); +}