From 535a6c3520c3e34c5d74008764d12165650ec4d4 Mon Sep 17 00:00:00 2001 From: Volth Date: Mon, 26 Jun 2017 12:56:00 +0000 Subject: [PATCH 1/2] fetchFromGitHub: fix fetchSubmodules=true when revision is not hexadecimal --- pkgs/build-support/fetchgit/default.nix | 16 ++-------------- pkgs/build-support/fetchgit/gitrepotoname.nix | 14 ++++++++++++++ pkgs/build-support/fetchgit/nix-prefetch-git | 4 ++-- pkgs/top-level/all-packages.nix | 12 +++++++----- 4 files changed, 25 insertions(+), 21 deletions(-) create mode 100644 pkgs/build-support/fetchgit/gitrepotoname.nix diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 8e060b87ebd3..57afb1c4ab87 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -1,21 +1,9 @@ -{stdenv, git, cacert}: let - urlToName = url: rev: let - inherit (stdenv.lib) removeSuffix splitString last; - base = last (splitString ":" (baseNameOf (removeSuffix "/" url))); +{stdenv, git, cacert, gitRepoToName}: - matched = builtins.match "(.*).git" base; - - short = builtins.substring 0 7 rev; - - appendShort = if (builtins.match "[a-f0-9]*" rev) != null - then "-${short}" - else ""; - in "${if matched == null then base else builtins.head matched}${appendShort}"; -in { url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone , fetchSubmodules ? true, deepClone ? false , branchName ? null -, name ? urlToName url rev +, name ? gitRepoToName url rev , # Shell code executed after the file has been fetched # successfully. This can do things like check or transform the file. postFetch ? "" diff --git a/pkgs/build-support/fetchgit/gitrepotoname.nix b/pkgs/build-support/fetchgit/gitrepotoname.nix new file mode 100644 index 000000000000..9f4392c387f6 --- /dev/null +++ b/pkgs/build-support/fetchgit/gitrepotoname.nix @@ -0,0 +1,14 @@ +{ lib }: + +urlOrRepo: rev: let + inherit (lib) removeSuffix splitString last; + base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo))); + + matched = builtins.match "(.*).git" base; + + short = builtins.substring 0 7 rev; + + appendShort = if (builtins.match "[a-f0-9]*" rev) != null + then "-${short}" + else ""; +in "${if matched == null then base else builtins.head matched}${appendShort}" \ No newline at end of file diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git index 9e4f346f7a52..c3ba15d59023 100755 --- a/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/pkgs/build-support/fetchgit/nix-prefetch-git @@ -282,8 +282,8 @@ _clone_user_rev() { if test -z "$(echo "$rev" | tr -d 0123456789abcdef)"; then clone "$dir" "$url" "$rev" "" 1>&2 else - echo 1>&2 "Bad commit hash or bad reference." - exit 1 + # if revision is not hexadecimal it might be a tag + clone "$dir" "$url" "" "refs/tags/$rev" 1>&2 fi;; esac diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 5114b46bf396..aa6259c3f840 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -185,8 +185,10 @@ with pkgs; fetchzip = callPackage ../build-support/fetchzip { }; + gitRepoToName = callPackage ../build-support/fetchgit/gitrepotoname.nix { }; + fetchFromGitHub = { - owner, repo, rev, name ? "${repo}-${rev}-src", + owner, repo, rev, name ? gitRepoToName repo rev, fetchSubmodules ? false, private ? false, githubBase ? "github.com", varPrefix ? null, ... # For hash agility @@ -223,7 +225,7 @@ with pkgs; } // passthruAttrs) // { inherit rev; }; fetchFromBitbucket = { - owner, repo, rev, name ? "${repo}-${rev}-src", + owner, repo, rev, name ? gitRepoToName repo rev, ... # For hash agility }@args: fetchzip ({ inherit name; @@ -234,7 +236,7 @@ with pkgs; # cgit example, snapshot support is optional in cgit fetchFromSavannah = { - repo, rev, name ? "${repo}-${rev}-src", + repo, rev, name ? gitRepoToName repo rev, ... # For hash agility }@args: fetchzip ({ inherit name; @@ -244,7 +246,7 @@ with pkgs; # gitlab example fetchFromGitLab = { - owner, repo, rev, name ? "${repo}-${rev}-src", + owner, repo, rev, name ? gitRepoToName repo rev, ... # For hash agility }@args: fetchzip ({ inherit name; @@ -254,7 +256,7 @@ with pkgs; # gitweb example, snapshot support is optional in gitweb fetchFromRepoOrCz = { - repo, rev, name ? "${repo}-${rev}-src", + repo, rev, name ? gitRepoToName repo rev, ... # For hash agility }@args: fetchzip ({ inherit name; From b935b21ffd06284d0c8297651d7d28c0961d3274 Mon Sep 17 00:00:00 2001 From: Volth Date: Mon, 26 Jun 2017 18:10:37 +0000 Subject: [PATCH 2/2] fix regressions where "${repo}-${rev}-scr" pattern was hardcoded --- pkgs/applications/audio/sisco.lv2/default.nix | 2 +- pkgs/development/interpreters/ruby/default.nix | 2 +- pkgs/servers/mail/postfix/pfixtools.nix | 2 +- pkgs/tools/networking/email/default.nix | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/applications/audio/sisco.lv2/default.nix b/pkgs/applications/audio/sisco.lv2/default.nix index d429d5452345..8ac7a9115ca8 100644 --- a/pkgs/applications/audio/sisco.lv2/default.nix +++ b/pkgs/applications/audio/sisco.lv2/default.nix @@ -25,7 +25,7 @@ stdenv.mkDerivation rec { inherit name; srcs = [ src robtkSrc ]; - sourceRoot = "sisco.lv2-${src.rev}-src"; + sourceRoot = src.name; buildInputs = [ pkgconfig lv2 pango cairo libjack2 mesa ]; diff --git a/pkgs/development/interpreters/ruby/default.nix b/pkgs/development/interpreters/ruby/default.nix index a552b2719bb2..f3d4ae4bb00e 100644 --- a/pkgs/development/interpreters/ruby/default.nix +++ b/pkgs/development/interpreters/ruby/default.nix @@ -59,7 +59,7 @@ let srcs = [ rubySrc rubygemsSrc ]; sourceRoot = if useRailsExpress then - "ruby-${tag}-src" + rubySrc.name else unpackdir rubySrc; diff --git a/pkgs/servers/mail/postfix/pfixtools.nix b/pkgs/servers/mail/postfix/pfixtools.nix index 1bbe6f3466b8..6a0d7fb588fd 100644 --- a/pkgs/servers/mail/postfix/pfixtools.nix +++ b/pkgs/servers/mail/postfix/pfixtools.nix @@ -10,7 +10,7 @@ let sha256 = "1vmbrw686f41n6xfjphfshn96vl07ynvnsyjdw9yfn9bfnldcjcq"; }; - srcRoot = "pfixtools-${pfixtoolsSrc.rev}-src"; + srcRoot = pfixtoolsSrc.name; libCommonSrc = fetchFromGitHub { owner = "Fruneau"; diff --git a/pkgs/tools/networking/email/default.nix b/pkgs/tools/networking/email/default.nix index 017da63a1e92..c7a6fbcfd7c7 100644 --- a/pkgs/tools/networking/email/default.nix +++ b/pkgs/tools/networking/email/default.nix @@ -8,7 +8,7 @@ let sha256 = "1cxxzhm36civ6vjdgrk7mfmlzkih44kdii6l2xgy4r434s8rzcpn"; }; - srcRoot = "eMail-${eMailSrc.rev}-src"; + srcRoot = eMailSrc.name; dlibSrc = fetchFromGitHub { owner = "deanproxy";