How to handle extra arguments for derivation?

I’m trying to submit a derivation(#116747) for gomobile and I have a dilemma. I have some arguments which can affect how this till can be used, like the xcode wrapper for iOS builds or Android env for Android builds, and want them to be easily passable by user, so currently I’m doing two sets of arguments:

{ stdenv, lib, fetchgit, buildGoModule, zlib, makeWrapper, xcodeenv, androidenv }:

{ xcodeWrapperArgs ? { }
, xcodeWrapper ? xcodeenv.composeXcodeWrapper xcodeWrapperArgs
, androidPkgs ? androidenv.composeAndroidPackages {
    includeNDK = true;
    ndkVersion = "21.3.6528147"; # WARNING: 22.0.7026061 is broken.
  } }:


But the issue with that, is if I include this package in pkgs/top-level/all-packages.nix it fails to build normally, for example in the REPL:

 > nix repl .                                                                               
Welcome to Nix version 2.3.10. Type :? for help.

Loading '.'...
Added 13855 variables.

nix-repl> :b pkgs.gomobile    
error: expression does not evaluate to a derivation, so I can't build it

Although it builds fine with nix-build:

 > nix-build --no-out-link -A gomobile --arg config '{ android_sdk.accept_license = true; }'

So I’m seeing two options:

  • Include these arguments in the first set of arguments
  • Provide another empty set in pkgs/top-level/all-packages.nix

Not sure what is the kosher solution.