go/workspace: fix nix-instantiate exec error typecast

Also skip nix tests on systems without nix.

Change-Id: I4c0069a429df10a496b2651c2506b2d4625d5f43
Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1585
Reviewed-by: q3k <q3k@hackerspace.pl>
diff --git a/go/workspace/nix.go b/go/workspace/nix.go
index 8d005a7..22b50cf 100644
--- a/go/workspace/nix.go
+++ b/go/workspace/nix.go
@@ -48,8 +48,10 @@
 	cmd := exec.CommandContext(ctx, "nix-instantiate", args...)
 	out, err := cmd.Output()
 	if err != nil {
-		eerr := err.(*exec.ExitError)
-		return fmt.Errorf("nix-instantiate failed: %w, stderr: %q", err, eerr.Stderr)
+		if eerr, ok := err.(*exec.ExitError); ok {
+			return fmt.Errorf("nix-instantiate failed: %w, stderr: %q", err, eerr.Stderr)
+		}
+		return fmt.Errorf("nix-instantiate failed: %w", err)
 	}
 
 	if err := json.Unmarshal(out, target); err != nil {
diff --git a/go/workspace/nix_test.go b/go/workspace/nix_test.go
index acb6d99..d1daf88 100644
--- a/go/workspace/nix_test.go
+++ b/go/workspace/nix_test.go
@@ -2,6 +2,7 @@
 
 import (
 	"context"
+	"os"
 	"testing"
 
 	"github.com/google/go-cmp/cmp"
@@ -49,6 +50,9 @@
 // TestEvalHscloud nix exercises EvalHscloudNix against
 // //go/workspace/exports.nix.
 func TestEvalHscloudNix(t *testing.T) {
+	if _, err := os.Stat("/nix/store"); err != nil {
+		t.Skip("no /nix/store")
+	}
 	ctx, ctxC := context.WithCancel(context.Background())
 	defer ctxC()