From e7521e289ccbcba8928a0c0a2220fbbb35716556 Mon Sep 17 00:00:00 2001 From: Volth Date: Tue, 4 Jul 2017 20:09:34 +0000 Subject: [PATCH 1/2] gitRepoToName: make it compatible with old fetchFromGitHub's "${repo}-${rev}-scr" to avoid mass rebuild --- pkgs/build-support/fetchgit/gitrepotoname.nix | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pkgs/build-support/fetchgit/gitrepotoname.nix b/pkgs/build-support/fetchgit/gitrepotoname.nix index 9f4392c387f..90005b54569 100644 --- a/pkgs/build-support/fetchgit/gitrepotoname.nix +++ b/pkgs/build-support/fetchgit/gitrepotoname.nix @@ -1,14 +1,19 @@ { lib }: -urlOrRepo: rev: let - inherit (lib) removeSuffix splitString last; - base = last (splitString ":" (baseNameOf (removeSuffix "/" urlOrRepo))); +let + inherit (lib) removeSuffix hasPrefix removePrefix splitString stringToCharacters concatMapStrings last elem; - 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 + allowedChars = stringToCharacters "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+-._?="; + sanitizeStoreName = s: + let + s' = concatMapStrings (c: if elem c allowedChars then c else "") (stringToCharacters s); + s'' = if hasPrefix "." s' then "_${removePrefix "." s'}" else s'; + in + s''; +in + urlOrRepo: rev: + let + repo' = last (splitString ":" (baseNameOf (removeSuffix ".git" (removeSuffix "/" urlOrRepo)))); + rev' = baseNameOf rev; + in + "${sanitizeStoreName repo'}-${sanitizeStoreName rev'}-src" From ab8dd33e5cda3abe78d244f23e6097cd3e3bca4e Mon Sep 17 00:00:00 2001 From: Volth Date: Wed, 5 Jul 2017 16:01:26 +0000 Subject: [PATCH 2/2] support old naming, just add escaping of unsafe chars --- pkgs/build-support/fetchgit/default.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkgs/build-support/fetchgit/default.nix b/pkgs/build-support/fetchgit/default.nix index 57afb1c4ab8..8e060b87ebd 100644 --- a/pkgs/build-support/fetchgit/default.nix +++ b/pkgs/build-support/fetchgit/default.nix @@ -1,9 +1,21 @@ -{stdenv, git, cacert, gitRepoToName}: +{stdenv, git, cacert}: let + urlToName = url: rev: let + inherit (stdenv.lib) removeSuffix splitString last; + base = last (splitString ":" (baseNameOf (removeSuffix "/" url))); + 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 ? gitRepoToName url rev +, name ? urlToName url rev , # Shell code executed after the file has been fetched # successfully. This can do things like check or transform the file. postFetch ? ""