diff --git a/fetch/fetch.go b/fetch/fetch.go index 21dd80e..adf5f49 100644 --- a/fetch/fetch.go +++ b/fetch/fetch.go @@ -73,16 +73,10 @@ func FetchPackages(goModPath string, goSumPath string, goMod2NixPath string, dep caches = append(caches, buildGoCache) } - // // Parse require - // require := make(map[string]module.Version) - // for _, req := range mod.Require { - // require[req.Mod.Path] = req.Mod - // } - // Map repos -> replacement repo replace := make(map[string]string) for _, repl := range mod.Replace { - replace[repl.Old.Path] = repl.New.Path + replace[repl.New.Path] = repl.Old.Path } log.WithFields(log.Fields{ @@ -111,12 +105,12 @@ func FetchPackages(goModPath string, goSumPath string, goMod2NixPath string, dep log.WithFields(log.Fields{ "numJobs": numJobs, }).Info("Queuing jobs") - for goPackagePath, sumVersion := range sumVersions { + for importPath, sumVersion := range sumVersions { // Check for replacement path (only original goPackagePath is recorded in go.sum) - importPath := goPackagePath + goPackagePath := importPath v, ok := replace[goPackagePath] if ok { - importPath = v + goPackagePath = v } jobs <- &packageJob{ @@ -251,6 +245,12 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka return nil, err } + vendorPath := "" + if importPath != goPackagePath { + importPathPrefix, _, _ := module.SplitPathVersion(importPath) + vendorPath = importPathPrefix + } + return &types.Package{ GoPackagePath: goPackagePath, URL: repoRoot.Repo, @@ -260,6 +260,7 @@ func fetchPackage(caches []map[string]*types.Package, importPath string, goPacka // It's also used to construct the vendor directory in the Nix build SumVersion: sumVersion, RelPath: relPath, + VendorPath: vendorPath, }, nil } diff --git a/formats/gomod2nix/gomod2nix.go b/formats/gomod2nix/gomod2nix.go index f48fb71..1210bda 100644 --- a/formats/gomod2nix/gomod2nix.go +++ b/formats/gomod2nix/gomod2nix.go @@ -18,6 +18,7 @@ type fetchInfo struct { type packageT struct { SumVersion string `toml:"sumVersion"` RelPath string `toml:"relPath"` + VendorPath string `toml:"vendorPath"` Fetch *fetchInfo `toml:"fetch"` } @@ -26,6 +27,7 @@ func Marshal(pkgs []*types.Package) ([]byte, error) { for _, pkg := range pkgs { result[pkg.GoPackagePath] = &packageT{ + VendorPath: pkg.VendorPath, SumVersion: pkg.SumVersion, RelPath: pkg.RelPath, Fetch: &fetchInfo{ @@ -75,6 +77,7 @@ func LoadGomod2Nix(filePath string) map[string]*types.Package { Sha256: v.Fetch.Sha256, SumVersion: v.SumVersion, RelPath: v.RelPath, + VendorPath: v.VendorPath, } } diff --git a/types/types.go b/types/types.go index a844b66..6aad1fc 100644 --- a/types/types.go +++ b/types/types.go @@ -7,4 +7,5 @@ type Package struct { Sha256 string SumVersion string RelPath string + VendorPath string }