about summary refs log tree commit diff
path: root/buildGo.nix
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-11-24T20·41+0000
committerVincent Ambo <tazjin@google.com>2019-11-24T20·41+0000
commit0fd74669229415907353563b3dbc2847d8a80942 (patch)
tree9849647e041eef41fd08e20a3749213f52d54aa5 /buildGo.nix
parent071babf14824aee035dd6c3ddff1957662aa7c98 (diff)
feat(buildGo): Add support for x_defs option in buildGo.program
This lets users define an attribute set with link time options.
Diffstat (limited to 'buildGo.nix')
-rw-r--r--buildGo.nix6
1 files changed, 4 insertions, 2 deletions
diff --git a/buildGo.nix b/buildGo.nix
index 029271f2f7d4..dce5502658c5 100644
--- a/buildGo.nix
+++ b/buildGo.nix
@@ -44,15 +44,17 @@ let
 
   allDeps = deps: lib.unique (lib.flatten (deps ++ (map (d: d.goDeps) deps)));
 
+  xFlags = x_defs: spaceOut (map (k: "-X ${k}=${x_defs."${k}"}") (attrNames x_defs));
+
   # High-level build functions
 
   # Build a Go program out of the specified files and dependencies.
-  program = { name, srcs, deps ? [] }:
+  program = { name, srcs, deps ? [], x_defs ? {} }:
   let uniqueDeps = allDeps deps;
   in runCommand name {} ''
     ${go}/bin/go tool compile -o ${name}.a -trimpath=$PWD -trimpath=${go} ${includeSources uniqueDeps} ${spaceOut srcs}
     mkdir -p $out/bin
-    ${go}/bin/go tool link -o $out/bin/${name} -buildid nix ${includeLibs uniqueDeps} ${name}.a
+    ${go}/bin/go tool link -o $out/bin/${name} -buildid nix ${xFlags x_defs} ${includeLibs uniqueDeps} ${name}.a
   '';
 
   # Build a Go library assembled out of the specified files.