about summary refs log tree commit diff
path: root/pkgs/build-support/fetchgit/gitrepotoname.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support/fetchgit/gitrepotoname.nix')
-rw-r--r--pkgs/build-support/fetchgit/gitrepotoname.nix14
1 files changed, 14 insertions, 0 deletions
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