#! /usr/bin/env bash # This script has been generated automatically by Hydra from the build # at [% c.uri_for('/build' build.id) %]. set -e tmpDir=${TMPDIR:-/tmp}/build-[% build.id +%] declare -a args extraArgs # Process the command line. while [ $# -gt 0 ]; do arg="$1" shift if [ "$arg" = --help ]; then cat <&2 exit 1 fi shift else extraArgs+=("$arg") fi done export NIX_PATH= mkdir -p "$tmpDir" cd "$tmpDir" echo "storing inputs and results in $tmpDir" >&2 requireCommand() { local cmd="$1" if ! type -P "$cmd" > /dev/null; then echo "$0: command ‘$cmd’ is not installed; please install it and try again" >&2 exit 1 fi return 0 } # Fetch the inputs. [%+ FOREACH input IN build.inputs %] inputDir= [%+ IF input.type == "git" %] inputDir="$tmpDir/[% input.name %]/git-export" if ! [ -d "$inputDir" ]; then echo echo "fetching Git input ‘[% input.name %]’ from ‘[% input.uri %]’ (commit [% input.revision %])..." >&2 requireCommand git inputDirTmp="$inputDir.tmp" rm -rf "$inputDirTmp" mkdir -p "$inputDirTmp" git clone '[% input.uri %]' "$inputDirTmp" (cd "$inputDirTmp" && git checkout '[% input.revision %]') revCount="$(cd "$inputDirTmp" && (git rev-list '[% input.revision %]' | wc -l))" rm -rf "$inputDirTmp/.git" mv "$inputDirTmp" "$inputDir" fi args+=(--arg '[% input.name %]' "{ outPath = $inputDir; rev = \"[% input.revision %]\"; shortRev = \"[% input.revision.substr(0, 7) %]\"; revCount = \"$revCount\"; }") [%+ ELSIF input.type == "hg" %] inputDir="$tmpDir/[% input.name %]/hg-archive" if ! [ -d "$inputDir" ]; then echo echo "fetching Mercurial input ‘[% input.name %]’ from ‘[% input.uri %]’ (commit [% input.revision %])..." >&2 requireCommand hg inputDirTmp="$inputDir.tmp" rm -rf "$inputDirTmp" hg clone '[% input.uri %]' "$inputDirTmp" -r '[% input.revision %]' rm -rf "$inputDirTmp/.hg" mv "$inputDirTmp" "$inputDir" fi args+=(--arg '[% input.name %]' "{ outPath = $inputDir; rev = \"[% input.revision %]\"; revCount = \"$revCount\"; }") [%+ ELSIF input.type == "svn" %] inputDir="$tmpDir/[% input.name %]/svn-export" if ! [ -d "$inputDir" ]; then echo echo "fetching Subversion input ‘[% input.name %]’ from ‘[% input.uri %]’ (commit [% input.revision %])..." >&2 requireCommand svn rm -rf "$inputDir.tmp" svn export '[% input.uri %]@[% input.revision %]' "$inputDir.tmp" mv "$inputDir.tmp" "$inputDir" fi args+=(--arg '[% input.name %]' "{ outPath = $inputDir; rev = \"[% input.revision %]\"; }") [% ELSIF input.type == "string" %] args+=(--arg '[% input.name %]' '"[% input.value %]"') [% ELSIF input.type == "boolean" %] args+=(--arg '[% input.name %]' '[% input.value %]') [% ELSE %] echo "$0: input ‘[% input.name %]’ has unsupported type ‘[% input.type %]’" >&2 exit 1 [% END %] [% IF input.name == build.nixexprinput +%] nixExprInputDir="$inputDir" [%+ END %] if [ -n "$inputDir" ]; then NIX_PATH="$NIX_PATH${NIX_PATH:+:}[% input.name %]=$inputDir" fi [%+ END %] # Run nix-build. requireCommand nix-build if [ -z "$nixExprInputDir" ]; then echo "$0: don't know the path to the Nix expression!" >&2 exit 1 fi #args+=(--option binary-caches '[% c.uri_for('/') %]') # Since Hydra runs on x86_64-linux, pretend we're one. This matters # when evaluating jobs that rely on builtins.currentSystem. args+=(--option system x86_64-linux) echo echo "Nix path is $NIX_PATH" >&2 echo "Nix args are ${args[@]}" >&2 nix-build "$nixExprInputDir/[% build.nixexprpath %]" -A '[% build.job.name %]' "${args[@]}" "${extraArgs[@]}"