about summary refs log tree commit diff
path: root/nixpkgs/pkgs/build-support/fetchmtn
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/build-support/fetchmtn')
-rw-r--r--nixpkgs/pkgs/build-support/fetchmtn/builder.sh46
-rw-r--r--nixpkgs/pkgs/build-support/fetchmtn/default.nix25
2 files changed, 71 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/build-support/fetchmtn/builder.sh b/nixpkgs/pkgs/build-support/fetchmtn/builder.sh
new file mode 100644
index 000000000000..de929fad55a9
--- /dev/null
+++ b/nixpkgs/pkgs/build-support/fetchmtn/builder.sh
@@ -0,0 +1,46 @@
+if [ -e "$NIX_ATTRS_SH_FILE" ]; then . "$NIX_ATTRS_SH_FILE"; elif [ -f .attrs.sh ]; then . .attrs.sh; fi
+source $stdenv/setup
+
+set -x
+
+if ! [ -f "$cacheDB" ]; then
+    echo "Creating cache DB $cacheDB"
+    mtn --db "$cacheDB" db init
+fi
+
+echo "getting revision $selector";
+
+done=;
+for source in $dbs; do
+    if mtn pull --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 successful";
+    fi;
+    if test -n "$done"; then
+        break;
+    fi;
+done;
+
+echo "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;
+
+echo "clearing _MTN in the output"
+
+rm -rf "$out/_MTN"
diff --git a/nixpkgs/pkgs/build-support/fetchmtn/default.nix b/nixpkgs/pkgs/build-support/fetchmtn/default.nix
new file mode 100644
index 000000000000..4aa134242aa7
--- /dev/null
+++ b/nixpkgs/pkgs/build-support/fetchmtn/default.nix
@@ -0,0 +1,25 @@
+# You can specify some extra mirrors and a cache DB via options
+{lib, stdenvNoCC, monotone, defaultDBMirrors ? [], cacheDB ? "./mtn-checkout.db"}:
+# dbs is a list of strings
+# each is an url for sync
+
+# selector is mtn selector, like h:org.example.branch
+#
+{name ? "mtn-checkout", dbs ? [], sha256
+, selector ? "h:" + branch, branch}:
+
+stdenvNoCC.mkDerivation {
+  builder = ./builder.sh;
+  nativeBuildInputs = [monotone];
+
+  outputHashAlgo = "sha256";
+  outputHashMode = "recursive";
+  outputHash = sha256;
+
+  dbs = defaultDBMirrors ++ dbs;
+  inherit branch cacheDB name selector;
+
+  impureEnvVars = lib.fetchers.proxyImpureEnvVars;
+
+}
+