aboutsummaryrefslogtreecommitdiff
path: root/pkgs/build-support/fetchcvs
diff options
context:
space:
mode:
authorRoy van den Broek <rbroek@cs.uu.nl>2006-05-11 12:36:16 +0000
committerRoy van den Broek <rbroek@cs.uu.nl>2006-05-11 12:36:16 +0000
commit9ece10787e7eb56974d71c17327f609d88584b5d (patch)
tree5469166ac14c2b7f457d3fdea1374b4431404d3a /pkgs/build-support/fetchcvs
parent179e41fe9def1a9fc458fa1b74e18fde5743b6c2 (diff)
Added fetchcvs.
svn path=/nixpkgs/trunk/; revision=5295
Diffstat (limited to 'pkgs/build-support/fetchcvs')
-rw-r--r--pkgs/build-support/fetchcvs/builder.sh24
-rw-r--r--pkgs/build-support/fetchcvs/default.nix16
-rwxr-xr-xpkgs/build-support/fetchcvs/nix-prefetch-cvs89
3 files changed, 129 insertions, 0 deletions
diff --git a/pkgs/build-support/fetchcvs/builder.sh b/pkgs/build-support/fetchcvs/builder.sh
new file mode 100644
index 000000000000..55a87c1660ad
--- /dev/null
+++ b/pkgs/build-support/fetchcvs/builder.sh
@@ -0,0 +1,24 @@
+source $stdenv/setup
+
+header "exporting $url $module into $out"
+
+prefetch=$(dirname $out)/cvs-checkout-tmp-$outputHash
+echo $prefetch
+if test -e "$prefetch"; then
+ mv $prefetch $out
+else
+ if test -z "$tag"; then
+ rtag="-DNOW"
+ else
+ rtag="-r $tag"
+ fi
+ cvs -f -d $url export $rtag -d $out $module
+fi
+
+actual=$(nix-hash $out)
+if test "$actual" != "$outputHash"; then
+ echo "hash is $actual, expected $outputHash" >&2
+ exit 1
+fi
+
+stopNest
diff --git a/pkgs/build-support/fetchcvs/default.nix b/pkgs/build-support/fetchcvs/default.nix
new file mode 100644
index 000000000000..a97e9d927efa
--- /dev/null
+++ b/pkgs/build-support/fetchcvs/default.nix
@@ -0,0 +1,16 @@
+{stdenv, cvs, nix}: {url, module, tag, md5}:
+
+stdenv.mkDerivation {
+ name = "cvs-export";
+ builder = ./builder.sh;
+ buildInputs = [cvs nix];
+
+ # Nix <= 0.7 compatibility.
+ id = md5;
+
+ outputHashAlgo = "md5";
+ outputHashMode = "recursive";
+ outputHash = md5;
+
+ inherit url module tag;
+}
diff --git a/pkgs/build-support/fetchcvs/nix-prefetch-cvs b/pkgs/build-support/fetchcvs/nix-prefetch-cvs
new file mode 100755
index 000000000000..3b0ba58683d9
--- /dev/null
+++ b/pkgs/build-support/fetchcvs/nix-prefetch-cvs
@@ -0,0 +1,89 @@
+#! /bin/sh -e
+
+url=$1
+module=$2
+tag=$3
+hash=$4
+
+if test -z "$url"; then
+ echo "syntax: nix-prefetch-cvs URL MODULE [TAG [HASH]]" >&2
+ exit 1
+elif test -z "$module"; then
+ echo "syntax: nix-prefetch-cvs URL MODULE [TAG [HASH]]" >&2
+ exit 1
+fi
+
+# Use a restrictive umask to ensure that the output in the Nix store
+# is not group- or world-writable. Nix 0.10 complains about this.
+umask 0022
+
+# Determine the hash, unless it was given.
+if test -z "$hash"; then
+
+ # !!! hacky; we should have a way to query the location of the store.
+ if storeDir=$(which nix-store); then
+ storeDir=$(dirname $(dirname "$storeDir"))/store
+ else
+ storeDir=/nix/store
+ fi
+
+ # !!! race? should be relatively safe, `svn export' barfs if $tmpPath exists.
+ cvsPath="cvs-checkout-tmp-$$"
+ tmpPath1=$storeDir/$cvsPath
+
+ # Test whether we have write permission in the store. If not,
+ # fetch to /tmp and don't copy to the store. This is a hack to
+ # make this script at least work somewhat in setuid installations.
+ if ! touch $tmpPath1 2> /dev/null; then
+ echo "(cannot write to the store, result won't be cached)" >&2
+ dummyMode=1
+ tmpPath1=/tmp/nix-prefetch-cvs-$$ # !!! security?
+ fi
+ rm -f $tmpPath1
+
+ # Perform the checkout.
+ if test -z "$tag"; then
+ rtag="-DNOW"
+ else
+ rtag="-r $tag"
+ fi
+ # CVS has a problem with absolute paths, so cd into the nix store
+ current=$(pwd)
+ cd $storeDir
+ cvs -f -d $url export $rtag -d $cvsPath $module >&2
+ # Change back to the original directory
+ cd $current
+
+ # Compute the hash.
+ hash=$(nix-hash $tmpPath1)
+ echo "hash is $hash" >&2
+
+ # Rename it so that the fetchcvs builder can find it.
+ if test "$dummyMode" != 1; then
+ tmpPath2=$storeDir/cvs-checkout-tmp-$hash
+ test -e $tmpPath2 || mv $tmpPath1 $tmpPath2 # !!! race
+ fi
+fi
+
+# Create a Nix expression that does a fetchcvs.
+nixExpr=$(dirname $0)/../../top-level/all-packages.nix
+storeExpr=$( \
+ echo "(import $nixExpr {}).fetchcvs {url=\"$url\"; module=\"$module\"; tag=\"$tag\"; md5=\"$hash\";}" \
+ | nix-instantiate -)
+
+# Realise it.
+finalPath=$(nix-store -r $storeExpr)
+
+echo "path is $finalPath" >&2
+
+if test -n "$tmpPath1" -o -n "$tmpPath2"; then
+ rm -rf $tmpPath1 $tmpPath2 || true
+fi
+
+echo "debug hash is $hash" >&2
+echo $hash
+
+if test -n "$PRINT_PATH"; then
+ echo "debug path is $finalPath" >&2
+ echo $finalPath
+fi