From 58b865cfc65e7756c148f38d25cb3d6b6f077a4d Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Fri, 15 May 2015 11:02:01 +0200 Subject: [PATCH] go: remove renameImports and use goPackageAliases --- doc/language-support.xml | 31 +++++++++---------- pkgs/applications/networking/pond/default.nix | 5 --- .../go-modules/generic/default.nix | 23 ++++++++++---- pkgs/top-level/go-packages.nix | 4 +++ 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/doc/language-support.xml b/doc/language-support.xml index 87f500a491ba..5942fe01e2ed 100644 --- a/doc/language-support.xml +++ b/doc/language-support.xml @@ -662,18 +662,16 @@ standard Go packages. net = buildGoPackage rec { name = "go.net-${rev}"; - goPackagePath = "code.google.com/p/go.net"; + goPackagePath = "golang.org/x/net"; subPackages = [ "ipv4" "ipv6" ]; - rev = "28ff664507e4"; - src = fetchhg { + rev = "e0403b4e005"; + src = fetchFromGitHub { inherit rev; - url = "https://${goPackagePath}"; - sha256 = "1lkz4c9pyz3yz2yz18hiycvlfhgy3jxp68bs7mv7bcfpaj729qav"; + owner = "golang"; + repo = "net"; + sha256 = "1g7cjzw4g4301a3yqpbk8n1d4s97sfby2aysl275x04g0zh8jxqp"; }; - renameImports = [ - "code.google.com/p/go.crypto golang.org/x/crypto" - "code.google.com/p/goprotobuf github.com/golang/protobuf" - ]; + goPackageAliases = [ "code.google.com/p/go.net" ]; propagatedBuildInputs = [ goPackages.text ]; buildFlags = "--tags release"; }; @@ -703,17 +701,18 @@ the following arguments are of special significance to the function: - + - renameImports is a list of import paths to be renamed before - building the package. The path to be renamed can be a regular expression. + goPackageAliases is a list of alternative import paths + that are valid for this library. + Packages that depend on this library will automatically rename + import paths that match any of the aliases to goPackagePath. In this example imports will be renamed from - code.google.com/p/go.crypto to - golang.org/x/crypto and from - code.google.com/p/goprotobuf to - github.com/golang/protobuf. + code.google.com/p/go.net to + golang.org/x/net in every package that depend on the + go.net library. diff --git a/pkgs/applications/networking/pond/default.nix b/pkgs/applications/networking/pond/default.nix index 4ac3a0448dea..21d99013a1a0 100644 --- a/pkgs/applications/networking/pond/default.nix +++ b/pkgs/applications/networking/pond/default.nix @@ -14,11 +14,6 @@ buildGoPackage rec { subPackages = [ "client" ]; - renameImports = [ - "code.google.com/p/go.crypto golang.org/x/crypto" - "code.google.com/p/goprotobuf github.com/golang/protobuf" - ]; - buildInputs = [ trousers net crypto protobuf ed25519 govers ]; buildFlags = "--tags nogui"; 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 []) ++ diff --git a/pkgs/top-level/go-packages.nix b/pkgs/top-level/go-packages.nix index 3373ebdef2f8..035c152b6b18 100644 --- a/pkgs/top-level/go-packages.nix +++ b/pkgs/top-level/go-packages.nix @@ -13,6 +13,7 @@ let self = _self // overrides; _self = with self; { rev = "4d48e5fa3d62b5e6e71260571bf76c767198ca02"; name = "go-crypto-${rev}"; goPackagePath = "golang.org/x/crypto"; + goPackageAliases = [ "code.google.com/p/go.crypto" ]; src = fetchFromGitHub { inherit rev; @@ -49,6 +50,7 @@ let self = _self // overrides; _self = with self; { rev = "e0403b4e005737430c05a57aac078479844f919c"; name = "net-${stdenv.lib.strings.substring 0 7 rev}"; goPackagePath = "golang.org/x/net"; + goPackageAliases = [ "code.google.com/p/go.net" ]; src = fetchFromGitHub { inherit rev; @@ -84,6 +86,7 @@ let self = _self // overrides; _self = with self; { rev = "efd7476481382c195beb33acd8ec2f1527167fb4"; name = "goprotobuf-${stdenv.lib.strings.substring 0 7 rev}"; goPackagePath = "github.com/golang/protobuf"; + goPackageAliases = [ "code.google.com/p/goprotobuf" ]; src = fetchFromGitHub { inherit rev; @@ -409,6 +412,7 @@ let self = _self // overrides; _self = with self; { rev = "3b5f175f65d601d06f48d78fcbdb0add633565b9"; name = "govers-${stdenv.lib.strings.substring 0 7 rev}"; goPackagePath = "github.com/rogpeppe/govers"; + dontRenameImports = true; src = fetchFromGitHub { inherit rev; owner = "rogpeppe";