about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/fetchbzr
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/build-support/fetchbzr')
-rw-r--r--nixpkgs/pkgs/build-support/fetchbzr/builder.sh8
-rw-r--r--nixpkgs/pkgs/build-support/fetchbzr/default.nix15
-rwxr-xr-xnixpkgs/pkgs/build-support/fetchbzr/nix-prefetch-bzr74
3 files changed, 97 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/fetchbzr/builder.sh b/nixpkgs/pkgs/build-support/fetchbzr/builder.sh
new file mode 100644
index 000000000000..4515e0e82f49
--- /dev/null
+++ b/nixpkgs/pkgs/build-support/fetchbzr/builder.sh
@@ -0,0 +1,8 @@
+if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
+source "$stdenv/setup"
+
+echo "exporting \`$url' (revision $rev) into \`$out'"
+
+# Perform a lightweight checkout so that we don't end up importing
+# all the repository's history.
+XDG_CACHE_HOME="$TMPDIR" BRZ_LOG=/dev/null bzr -Ossl.cert_reqs=none export -r "$rev" --format=dir "$out" "$url"
diff --git a/nixpkgs/pkgs/build-support/fetchbzr/default.nix b/nixpkgs/pkgs/build-support/fetchbzr/default.nix
new file mode 100644
index 000000000000..b7db9e9274da
--- /dev/null
+++ b/nixpkgs/pkgs/build-support/fetchbzr/default.nix
@@ -0,0 +1,15 @@
+{ stdenvNoCC, breezy }:
+{ url, rev, sha256 }:
+
+stdenvNoCC.mkDerivation {
+  name = "bzr-export";
+
+  builder = ./builder.sh;
+  nativeBuildInputs = [ breezy ];
+
+  outputHashAlgo = "sha256";
+  outputHashMode = "recursive";
+  outputHash = sha256;
+
+  inherit url rev;
+}
diff --git a/nixpkgs/pkgs/build-support/fetchbzr/nix-prefetch-bzr b/nixpkgs/pkgs/build-support/fetchbzr/nix-prefetch-bzr
new file mode 100755
index 000000000000..dbe8a7ef8013
--- /dev/null
+++ b/nixpkgs/pkgs/build-support/fetchbzr/nix-prefetch-bzr
@@ -0,0 +1,74 @@
+#! /bin/sh -e
+
+url=$1
+rev=$2
+expHash=$3
+
+hashType=$NIX_HASH_ALGO
+if test -z "$hashType"; then
+    hashType=sha256
+fi
+if test -z "$hashFormat"; then
+    hashFormat=--base32
+fi
+
+if test -z "$url"; then
+    echo "syntax: nix-prefetch-bzr URL [REVISION [EXPECTED-HASH]]" >&2
+    exit 1
+fi
+
+revarg="-r $rev"
+test -n "$rev" || revarg=""
+
+repoName=$(echo $url | sed '
+  s,.*/\([^/]\+\)/trunk/*$,\1,;t
+  s,.*/\([^/]\+\)/branches/\([^/]\+\)/*$,\1-\2,;t
+  s,.*/\([^/]\+\)/tags/\([^/]\+\)/*$,\1-\2,;t
+  s,.*/\([^/]\+\)/*$,\1,;t
+')
+dstFile="bzr-export"
+
+# If the hash was given, a file with that hash may already be in the
+# store.
+if test -n "$expHash"; then
+    finalPath=$(nix-store --print-fixed-path --recursive "$hashType" "$expHash" $dstFile)
+    if ! nix-store --check-validity "$finalPath" 2> /dev/null; then
+        finalPath=
+    fi
+    hash=$expHash
+fi
+
+
+# If we don't know the hash or a path with that hash doesn't exist,
+# download the file and add it to the store.
+if test -z "$finalPath"; then
+    tmpPath="$(mktemp -d "${TMPDIR:-/tmp}/bzr-checkout-tmp-XXXXXXXX")"
+    trap "rm -rf \"$tmpPath\"" EXIT
+
+    tmpFile="$tmpPath/$dstFile"
+
+    # Perform the checkout.
+    bzr -Ossl.cert_reqs=none export $revarg --format=dir "$tmpFile" "$url"
+
+    echo "bzr revision is $(bzr revno $revarg "$url")"
+
+    # Compute the hash.
+    hash=$(nix-hash --type $hashType $hashFormat $tmpFile)
+    if ! test -n "$QUIET"; then echo "hash is $hash" >&2; fi
+
+    # Add the downloaded file to the Nix store.
+    finalPath=$(nix-store --add-fixed --recursive "$hashType" $tmpFile)
+
+    if test -n "$expHash" -a "$expHash" != "$hash"; then
+        echo "hash mismatch for URL \`$url'"
+        exit 1
+    fi
+fi
+
+if ! test -n "$QUIET"; then echo "path is $finalPath" >&2; fi
+
+echo $hash
+
+if test -n "$PRINT_PATH"; then
+    echo $finalPath
+fi