func BuildExpression(nixPath string, expressionPath string, outLink *string) (string, error) {
	tempDir, err := ioutil.TempDir("", "")
	if err != nil {
		return "", err
	}
	defer os.RemoveAll(tempDir)
	var cmd *exec.Cmd
	if outLink == nil {
		cmd = exec.Command("nix-build", "--no-link", expressionPath)
	} else {
		cmd = exec.Command("nix-build", "-o", *outLink, expressionPath)
	}
	cmd.Env = []string{fmt.Sprintf("NIX_PATH=%s", nixPath)}
	output := bytes.NewBuffer(nil)
	err = runCommandWithLogging(cmd, output)
	if err != nil {
		return "", fmt.Errorf("building expression failed: %s", formatChildErr(err))
	}
	if outLink == nil {
		return strings.TrimSpace(output.String()), nil
	} else {
		return os.Readlink(*outLink)
	}
}
BuildExpression builds a nix expression, returning the store path.
package nix
import (
	"bytes"
	"errors"
	"fmt"
	"io/ioutil"
	"net"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
	"time"
)
func formatChildErr(err error) error {
	if err == nil {
		return nil
	}
	if err, ok := err.(*exec.ExitError); ok {
		return errors.New(string(err.Stderr))
	}
	return err
}