diff --git a/generate/generate.go b/generate/generate.go index c9d88f9..3ca63cb 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -8,6 +8,7 @@ import ( "io" "io/ioutil" "os/exec" + "path/filepath" "sort" "sync" @@ -29,7 +30,8 @@ type goModDownload struct { GoModSum string } -func GeneratePkgs(goModPath string, goMod2NixPath string) ([]*schema.Package, error) { +func GeneratePkgs(directory string, goMod2NixPath string) ([]*schema.Package, error) { + goModPath := filepath.Join(directory, "go.mod") log.WithFields(log.Fields{ "modPath": goModPath, @@ -57,9 +59,11 @@ func GeneratePkgs(goModPath string, goMod2NixPath string) ([]*schema.Package, er { log.Info("Downloading dependencies") - stdout, err := exec.Command( + cmd := exec.Command( "go", "mod", "download", "--json", - ).Output() + ) + cmd.Dir = directory + stdout, err := cmd.Output() if err != nil { return nil, err } diff --git a/main.go b/main.go index 114c71a..a0f3726 100644 --- a/main.go +++ b/main.go @@ -21,11 +21,9 @@ func main() { outDir = *directory } - goModPath := filepath.Join(*directory, "go.mod") - goMod2NixPath := filepath.Join(outDir, "gomod2nix.toml") outFile := goMod2NixPath - pkgs, err := generate.GeneratePkgs(goModPath, goMod2NixPath) + pkgs, err := generate.GeneratePkgs(*directory, goMod2NixPath) if err != nil { panic(err) }