summary refs log tree commit diff
path: root/pkgs/development/go-modules
diff options
context:
space:
mode:
authorLuca Bruno <lethalman88@gmail.com>2015-05-15 11:02:01 +0200
committerLuca Bruno <lethalman88@gmail.com>2015-05-15 11:16:59 +0200
commit58b865cfc65e7756c148f38d25cb3d6b6f077a4d (patch)
tree4578028594c083bf9e0ab8747718fa98f15dded4 /pkgs/development/go-modules
parentf66cd5dbe99b4343df58d26e0a48b87c6f471c22 (diff)
downloadnixlib-58b865cfc65e7756c148f38d25cb3d6b6f077a4d.tar
nixlib-58b865cfc65e7756c148f38d25cb3d6b6f077a4d.tar.gz
nixlib-58b865cfc65e7756c148f38d25cb3d6b6f077a4d.tar.bz2
nixlib-58b865cfc65e7756c148f38d25cb3d6b6f077a4d.tar.lz
nixlib-58b865cfc65e7756c148f38d25cb3d6b6f077a4d.tar.xz
nixlib-58b865cfc65e7756c148f38d25cb3d6b6f077a4d.tar.zst
nixlib-58b865cfc65e7756c148f38d25cb3d6b6f077a4d.zip
go: remove renameImports and use goPackageAliases
Diffstat (limited to 'pkgs/development/go-modules')
-rw-r--r--pkgs/development/go-modules/generic/default.nix23
1 files changed, 17 insertions, 6 deletions
diff --git a/pkgs/development/go-modules/generic/default.nix b/pkgs/development/go-modules/generic/default.nix
index 6d52d0cc92f8..271e0ed66336 100644
--- a/pkgs/development/go-modules/generic/default.nix
+++ b/pkgs/development/go-modules/generic/default.nix
@@ -5,18 +5,25 @@
 # Go import path of the package
 , goPackagePath
 
+# Go package aliases
+, goPackageAliases ? [ ]
+
 # Extra sources to include in the gopath
 , extraSrcs ? [ ]
 
+, dontRenameImports ? false
+
 , meta ? {}, ... } @ args':
 
 let
   args = lib.filterAttrs (name: _: name != "extraSrcs") args';
 in
 
-go.stdenv.mkDerivation ( args // {
+go.stdenv.mkDerivation (
+  (builtins.removeAttrs args [ "goPackageAliases" ]) // {
+
   name = "go${go.meta.branch}-${name}";
-  buildInputs = [ go ] ++ buildInputs ++ (lib.optional (args ? renameImports) govers) ;
+  buildInputs = [ go ] ++ buildInputs ++ (lib.optional (!dontRenameImports) govers) ;
 
   configurePhase = args.configurePhase or ''
     runHook preConfigure
@@ -40,10 +47,12 @@ go.stdenv.mkDerivation ( args // {
     runHook postConfigure
   '';
 
-  renameImports = lib.optionalString (args ? renameImports)
-                    (lib.concatMapStringsSep "\n"
-                      (cmdargs: "govers -m ${cmdargs}")
-                      args.renameImports);
+  renameImports = args.renameImports or (
+    let
+      inputsWithAliases = lib.filter (x: x ? goPackageAliases) buildInputs;
+      rename = to: from: "echo Renaming '${from}' to '${to}'; govers -m ${from} ${to}";
+      renames = p: lib.concatMapStringsSep "\n" (rename p.goPackagePath) p.goPackageAliases;
+    in lib.concatMapStringsSep "\n" renames inputsWithAliases);
 
   buildPhase = args.buildPhase or ''
     runHook preBuild
@@ -107,6 +116,8 @@ go.stdenv.mkDerivation ( args // {
     runHook postInstall
   '';
 
+  passthru = lib.optionalAttrs (goPackageAliases != []) { inherit goPackageAliases; };
+
   meta = meta // {
     # add an extra maintainer to every package
     maintainers = (meta.maintainers or []) ++