diff --git a/pkgs/build-support/fetchmtn/builder.sh b/pkgs/build-support/fetchmtn/builder.sh new file mode 100644 index 000000000000..58fd7e41c9a7 --- /dev/null +++ b/pkgs/build-support/fetchmtn/builder.sh @@ -0,0 +1,41 @@ +source $stdenv/setup + +set -x + +header "getting revision $selector"; + +done=; +for source in $dbs; do + if mtn pull --debug --db "$cacheDB" "$source" "${branch}"; then + revision="$(mtn --db "$cacheDB" au toposort $(mtn --db "$cacheDB" au select "$selector") | tail -1)"; + if [ -n "$revision" ]; then + if mtn --db "$cacheDB" au get_revision "$revision"; then + echo "found revision $revision" + done=1; + else + echo "revision $revision does not exist"; + fi + else + echo "selector $selector does not match any revision"; + fi + else + echo "pulling branch $branch wasn't succesfull"; + fi; + if test -n "$done"; then + break; + fi; +done; + +stopNest; + +header "checking out the revision $revision"; + +if test -n "$done"; then + mtn checkout --db "$cacheDB" -r "$revision" "$out" -b "${branch}" +else + echo "Needed revision still not found. Exiting"; + exit 1; +fi; + +stopNest + diff --git a/pkgs/build-support/fetchmtn/default.nix b/pkgs/build-support/fetchmtn/default.nix new file mode 100644 index 000000000000..7fda2821905f --- /dev/null +++ b/pkgs/build-support/fetchmtn/default.nix @@ -0,0 +1,32 @@ +# You can specify some extra mirrors and a cache DB via options +{stdenv, monotone, defaultDBMirrors ? [], cacheDB ? ""}: +# dbs is a list of strings +# each is an url for sync + +# selector is mtn selector, like h:org.example.branch +# +{name ? "", dbs ? [], selector ? "", branch, md5 ? "", sha1 ? "", sha256 ? ""}: + +stdenv.mkDerivation { + name = if name != "" then name else "mtn-checkout"; + builder = ./builder.sh; + buildInputs = [monotone]; + + outputHashAlgo = if sha256 == "" then (if sha1 == "" then "md5" else "sha1") else "sha256"; + outputHashMode = "recursive"; + outputHash = if sha256 == "" then (if sha1 == "" then md5 else sha1) else sha256; + + dbs = defaultDBMirrors ++ dbs; + cacheDB = if cacheDB != "" then cacheDB else "./mtn-checkout.db"; + selector = if selector != "" then selector else "h:" + branch; + inherit branch; + + impureEnvVars = [ + # We borrow these environment variables from the caller to allow + # easy proxy configuration. This is impure, but a fixed-output + # derivation like fetchurl is allowed to do so since its result is + # by definition pure. + "http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy" + ]; +} +