about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-09T00·51+0000
committerVincent Ambo <mail@tazj.in>2019-12-09T01·07+0000
commit6a526620e25a349642b161eb687dec2e005360e5 (patch)
tree32cd5eea61f8725be33abda129b55aface7893ad
parent28e587b348a8aaa7af00a004c05286af9d35ca9a (diff)
feat(buildGo): Add 'overrideGo' argument overriding function
This makes it possible to override arguments to the Go builders
downstream in the style of `overrideAttrs` from standard nixpkgs
derivations.

For example, given a Nix value `foo` that builds a binary called `foo`
the name of this binary could be changed and a new dependency on
`somelib` added like so:

    foo.overrideGo(old: {
      name = "bar";
      deps = old.deps ++ [ somelib ];
    })
-rw-r--r--buildGo.nix16
1 files changed, 14 insertions, 2 deletions
diff --git a/buildGo.nix b/buildGo.nix
index fba4e18e9bce..5f5118e8cec2 100644
--- a/buildGo.nix
+++ b/buildGo.nix
@@ -48,6 +48,13 @@ let
 
   pathToName = p: replaceStrings ["/"] ["_"] (toString p);
 
+  # Add an `overrideGo` attribute to a function result that works
+  # similar to `overrideAttrs`, but is used specifically for the
+  # arguments passed to Go builders.
+  makeOverridable = f: orig: (f orig) // {
+    overrideGo = new: makeOverridable f (orig // (new orig));
+  };
+
   # High-level build functions
 
   # Build a Go program out of the specified files and dependencies.
@@ -130,6 +137,11 @@ let
     inherit external;
   };
 in {
-  # Only the high-level builder functions are exposed
-  inherit program package proto grpc external;
+  # Only the high-level builder functions are exposed, but made
+  # overrideable.
+  program = makeOverridable program;
+  package = makeOverridable package;
+  proto = makeOverridable proto;
+  grpc = makeOverridable grpc;
+  external = makeOverridable external;
 }