go: remove renameImports and use goPackageAliases

+36 -27
+15 -16
doc/language-support.xml
··· 662 662 <programlisting> 663 663 net = buildGoPackage rec { 664 664 name = "go.net-${rev}"; 665 - goPackagePath = "code.google.com/p/go.net"; <co xml:id='ex-buildGoPackage-1' /> 665 + goPackagePath = "golang.org/x/net"; <co xml:id='ex-buildGoPackage-1' /> 666 666 subPackages = [ "ipv4" "ipv6" ]; <co xml:id='ex-buildGoPackage-2' /> 667 - rev = "28ff664507e4"; 668 - src = fetchhg { 667 + rev = "e0403b4e005"; 668 + src = fetchFromGitHub { 669 669 inherit rev; 670 - url = "https://${goPackagePath}"; 671 - sha256 = "1lkz4c9pyz3yz2yz18hiycvlfhgy3jxp68bs7mv7bcfpaj729qav"; 670 + owner = "golang"; 671 + repo = "net"; 672 + sha256 = "1g7cjzw4g4301a3yqpbk8n1d4s97sfby2aysl275x04g0zh8jxqp"; 672 673 }; 673 - renameImports = [ <co xml:id='ex-buildGoPackage-3' /> 674 - "code.google.com/p/go.crypto golang.org/x/crypto" 675 - "code.google.com/p/goprotobuf github.com/golang/protobuf" 676 - ]; 674 + goPackageAliases = [ "code.google.com/p/go.net" ]; <co xml:id='ex-buildGoPackage-3' /> 677 675 propagatedBuildInputs = [ goPackages.text ]; <co xml:id='ex-buildGoPackage-4' /> 678 676 buildFlags = "--tags release"; <co xml:id='ex-buildGoPackage-5' /> 679 677 }; ··· 703 701 </para> 704 702 </callout> 705 703 706 - <callout arearefs='ex-buildGoPackage-4'> 704 + <callout arearefs='ex-buildGoPackage-3'> 707 705 <para> 708 - <varname>renameImports</varname> is a list of import paths to be renamed before 709 - building the package. The path to be renamed can be a regular expression. 706 + <varname>goPackageAliases</varname> is a list of alternative import paths 707 + that are valid for this library. 708 + Packages that depend on this library will automatically rename 709 + import paths that match any of the aliases to <literal>goPackagePath</literal>. 710 710 </para> 711 711 <para> 712 712 In this example imports will be renamed from 713 - <literal>code.google.com/p/go.crypto</literal> to 714 - <literal>golang.org/x/crypto</literal> and from 715 - <literal>code.google.com/p/goprotobuf</literal> to 716 - <literal>github.com/golang/protobuf</literal>. 713 + <literal>code.google.com/p/go.net</literal> to 714 + <literal>golang.org/x/net</literal> in every package that depend on the 715 + <literal>go.net</literal> library. 717 716 </para> 718 717 </callout> 719 718
-5
pkgs/applications/networking/pond/default.nix
··· 14 14 15 15 subPackages = [ "client" ]; 16 16 17 - renameImports = [ 18 - "code.google.com/p/go.crypto golang.org/x/crypto" 19 - "code.google.com/p/goprotobuf github.com/golang/protobuf" 20 - ]; 21 - 22 17 buildInputs = [ trousers net crypto protobuf ed25519 govers ]; 23 18 24 19 buildFlags = "--tags nogui";
+17 -6
pkgs/development/go-modules/generic/default.nix
··· 5 5 # Go import path of the package 6 6 , goPackagePath 7 7 8 + # Go package aliases 9 + , goPackageAliases ? [ ] 10 + 8 11 # Extra sources to include in the gopath 9 12 , extraSrcs ? [ ] 10 13 14 + , dontRenameImports ? false 15 + 11 16 , meta ? {}, ... } @ args': 12 17 13 18 let 14 19 args = lib.filterAttrs (name: _: name != "extraSrcs") args'; 15 20 in 16 21 17 - go.stdenv.mkDerivation ( args // { 22 + go.stdenv.mkDerivation ( 23 + (builtins.removeAttrs args [ "goPackageAliases" ]) // { 24 + 18 25 name = "go${go.meta.branch}-${name}"; 19 - buildInputs = [ go ] ++ buildInputs ++ (lib.optional (args ? renameImports) govers) ; 26 + buildInputs = [ go ] ++ buildInputs ++ (lib.optional (!dontRenameImports) govers) ; 20 27 21 28 configurePhase = args.configurePhase or '' 22 29 runHook preConfigure ··· 40 47 runHook postConfigure 41 48 ''; 42 49 43 - renameImports = lib.optionalString (args ? renameImports) 44 - (lib.concatMapStringsSep "\n" 45 - (cmdargs: "govers -m ${cmdargs}") 46 - args.renameImports); 50 + renameImports = args.renameImports or ( 51 + let 52 + inputsWithAliases = lib.filter (x: x ? goPackageAliases) buildInputs; 53 + rename = to: from: "echo Renaming '${from}' to '${to}'; govers -m ${from} ${to}"; 54 + renames = p: lib.concatMapStringsSep "\n" (rename p.goPackagePath) p.goPackageAliases; 55 + in lib.concatMapStringsSep "\n" renames inputsWithAliases); 47 56 48 57 buildPhase = args.buildPhase or '' 49 58 runHook preBuild ··· 106 115 107 116 runHook postInstall 108 117 ''; 118 + 119 + passthru = lib.optionalAttrs (goPackageAliases != []) { inherit goPackageAliases; }; 109 120 110 121 meta = meta // { 111 122 # add an extra maintainer to every package
+4
pkgs/top-level/go-packages.nix
··· 13 13 rev = "4d48e5fa3d62b5e6e71260571bf76c767198ca02"; 14 14 name = "go-crypto-${rev}"; 15 15 goPackagePath = "golang.org/x/crypto"; 16 + goPackageAliases = [ "code.google.com/p/go.crypto" ]; 16 17 17 18 src = fetchFromGitHub { 18 19 inherit rev; ··· 49 50 rev = "e0403b4e005737430c05a57aac078479844f919c"; 50 51 name = "net-${stdenv.lib.strings.substring 0 7 rev}"; 51 52 goPackagePath = "golang.org/x/net"; 53 + goPackageAliases = [ "code.google.com/p/go.net" ]; 52 54 53 55 src = fetchFromGitHub { 54 56 inherit rev; ··· 84 86 rev = "efd7476481382c195beb33acd8ec2f1527167fb4"; 85 87 name = "goprotobuf-${stdenv.lib.strings.substring 0 7 rev}"; 86 88 goPackagePath = "github.com/golang/protobuf"; 89 + goPackageAliases = [ "code.google.com/p/goprotobuf" ]; 87 90 88 91 src = fetchFromGitHub { 89 92 inherit rev; ··· 409 412 rev = "3b5f175f65d601d06f48d78fcbdb0add633565b9"; 410 413 name = "govers-${stdenv.lib.strings.substring 0 7 rev}"; 411 414 goPackagePath = "github.com/rogpeppe/govers"; 415 + dontRenameImports = true; 412 416 src = fetchFromGitHub { 413 417 inherit rev; 414 418 owner = "rogpeppe";