├── .envrc ├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── .gitignore ├── COPYING ├── Makefile ├── README.org ├── default.nix ├── deps.nix ├── depsnix.go ├── go.mod ├── go.sum ├── main.go ├── shell.nix └── tests ├── run_tests ├── shell.nix ├── test_major_version ├── expected.nix ├── go.mod ├── go.sum └── main.go ├── test_package ├── expected.nix ├── go.mod └── go.sum ├── test_replace_url ├── expected.nix ├── go.mod ├── go.sum └── main.go ├── test_replace_version ├── expected.nix ├── go.mod └── go.sum └── test_reporoot ├── expected.nix ├── go.mod └── go.sum /.envrc: -------------------------------------------------------------------------------- 1 | use nix 2 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "github-actions" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: "Test" 2 | on: 3 | pull_request: 4 | push: 5 | jobs: 6 | tests: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v2 10 | - uses: cachix/install-nix-action@v15 11 | with: 12 | nix_path: nixpkgs=channel:nixpkgs-unstable 13 | - run: make test 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /vgo2nix 2 | /tests/*/deps.nix 3 | result 4 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | Copyright 2018 Adam Hose 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: all test 2 | 3 | all: test 4 | 5 | test: 6 | ./tests/run_tests 7 | -------------------------------------------------------------------------------- /README.org: -------------------------------------------------------------------------------- 1 | * vgo2nix 2 | 3 | Vgo2nix is deprecated in favour of [[https://github.com/tweag/gomod2nix][gomod2nix]]. 4 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | with pkgs; 3 | 4 | assert lib.versionAtLeast go.version "1.11"; 5 | buildGoPackage rec { 6 | name = "vgo2nix-${version}"; 7 | version = "git"; 8 | goPackagePath = "github.com/nix-community/vgo2nix"; 9 | 10 | nativeBuildInputs = [ makeWrapper ]; 11 | 12 | src = lib.cleanSourceWith { 13 | filter = name: type: builtins.match ".*tests.*" name == null; 14 | src = (lib.cleanSource ./.); 15 | }; 16 | 17 | goDeps = ./deps.nix; 18 | 19 | allowGoReference = true; 20 | 21 | postInstall = let 22 | binPath = lib.makeBinPath [ nix-prefetch-git go ]; 23 | in '' 24 | wrapProgram $out/bin/vgo2nix --prefix PATH : ${binPath} 25 | ''; 26 | 27 | meta = with lib; { 28 | description = "Convert go.mod files to nixpkgs buildGoPackage compatible deps.nix files"; 29 | homepage = https://github.com/nix-community/vgo2nix; 30 | license = licenses.mit; 31 | maintainers = with maintainers; [ adisbladis ]; 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /deps.nix: -------------------------------------------------------------------------------- 1 | # file generated from go.mod using vgo2nix (https://github.com/nix-community/vgo2nix) 2 | [ 3 | { 4 | goPackagePath = "github.com/alecthomas/assert"; 5 | fetch = { 6 | type = "git"; 7 | url = "https://github.com/alecthomas/assert"; 8 | rev = "405dbfeb8e38"; 9 | sha256 = "1l567pi17k593nrd1qlbmiq8z9jy3qs60px2a16fdpzjsizwqx8l"; 10 | }; 11 | } 12 | { 13 | goPackagePath = "github.com/alecthomas/colour"; 14 | fetch = { 15 | type = "git"; 16 | url = "https://github.com/alecthomas/colour"; 17 | rev = "60882d9e2721"; 18 | sha256 = "0iq566534gbzkd16ixg7fk298wd766821vvs80838yifx9yml5vs"; 19 | }; 20 | } 21 | { 22 | goPackagePath = "github.com/alecthomas/kingpin"; 23 | fetch = { 24 | type = "git"; 25 | url = "https://github.com/alecthomas/kingpin"; 26 | rev = "v2.2.6"; 27 | sha256 = "0mndnv3hdngr3bxp7yxfd47cas4prv98sqw534mx7vp38gd88n5r"; 28 | }; 29 | } 30 | { 31 | goPackagePath = "github.com/alecthomas/repr"; 32 | fetch = { 33 | type = "git"; 34 | url = "https://github.com/alecthomas/repr"; 35 | rev = "117648cd9897"; 36 | sha256 = "05v1rgzdqc8razf702laagrvhvx68xd9yxxmzd3dyz0d6425pdrp"; 37 | }; 38 | } 39 | { 40 | goPackagePath = "github.com/alecthomas/template"; 41 | fetch = { 42 | type = "git"; 43 | url = "https://github.com/alecthomas/template"; 44 | rev = "a0175ee3bccc"; 45 | sha256 = "0qjgvvh26vk1cyfq9fadyhfgdj36f1iapbmr5xp6zqipldz8ffxj"; 46 | }; 47 | } 48 | { 49 | goPackagePath = "github.com/alecthomas/units"; 50 | fetch = { 51 | type = "git"; 52 | url = "https://github.com/alecthomas/units"; 53 | rev = "2efee857e7cf"; 54 | sha256 = "1j65b91qb9sbrml9cpabfrcf07wmgzzghrl7809hjjhrmbzri5bl"; 55 | }; 56 | } 57 | { 58 | goPackagePath = "github.com/davecgh/go-spew"; 59 | fetch = { 60 | type = "git"; 61 | url = "https://github.com/davecgh/go-spew"; 62 | rev = "v1.1.1"; 63 | sha256 = "0hka6hmyvp701adzag2g26cxdj47g21x6jz4sc6jjz1mn59d474y"; 64 | }; 65 | } 66 | { 67 | goPackagePath = "github.com/mattn/go-isatty"; 68 | fetch = { 69 | type = "git"; 70 | url = "https://github.com/mattn/go-isatty"; 71 | rev = "v0.0.3"; 72 | sha256 = "06w45aqz2a6yrk25axbly2k5wmsccv8cspb94bfmz4izvw8h927n"; 73 | }; 74 | } 75 | { 76 | goPackagePath = "github.com/orivej/e"; 77 | fetch = { 78 | type = "git"; 79 | url = "https://github.com/orivej/e"; 80 | rev = "ac3492690fda"; 81 | sha256 = "11jizr28kfkr6zscjxg95pqi6cjp08aqnhs41sdhc98nww78ilkr"; 82 | }; 83 | } 84 | { 85 | goPackagePath = "github.com/orivej/go-nix"; 86 | fetch = { 87 | type = "git"; 88 | url = "https://github.com/orivej/go-nix"; 89 | rev = "dae45d921a44"; 90 | sha256 = "17hfmsz8hs3h2d5c06j1bvbw8ijrhzm3iz911z5zydsl4x7y0cgy"; 91 | }; 92 | } 93 | { 94 | goPackagePath = "github.com/pkg/profile"; 95 | fetch = { 96 | type = "git"; 97 | url = "https://github.com/pkg/profile"; 98 | rev = "v1.2.1"; 99 | sha256 = "0blqmvgqvdbqmh3fp9pfdxc9w1qfshrr0zy9whj0sn372bw64qnr"; 100 | }; 101 | } 102 | { 103 | goPackagePath = "github.com/pmezard/go-difflib"; 104 | fetch = { 105 | type = "git"; 106 | url = "https://github.com/pmezard/go-difflib"; 107 | rev = "v1.0.0"; 108 | sha256 = "0c1cn55m4rypmscgf0rrb88pn58j3ysvc2d0432dp3c6fqg6cnzw"; 109 | }; 110 | } 111 | { 112 | goPackagePath = "github.com/sergi/go-diff"; 113 | fetch = { 114 | type = "git"; 115 | url = "https://github.com/sergi/go-diff"; 116 | rev = "v1.0.0"; 117 | sha256 = "0swiazj8wphs2zmk1qgq75xza6m19snif94h2m6fi8dqkwqdl7c7"; 118 | }; 119 | } 120 | { 121 | goPackagePath = "github.com/stretchr/testify"; 122 | fetch = { 123 | type = "git"; 124 | url = "https://github.com/stretchr/testify"; 125 | rev = "v1.2.2"; 126 | sha256 = "0dlszlshlxbmmfxj5hlwgv3r22x0y1af45gn1vd198nvvs3pnvfs"; 127 | }; 128 | } 129 | { 130 | goPackagePath = "github.com/yuin/goldmark"; 131 | fetch = { 132 | type = "git"; 133 | url = "https://github.com/yuin/goldmark"; 134 | rev = "v1.2.1"; 135 | sha256 = "12rsnsf65drcp0jfw2jl9w589vsn3pxdk1zh3v9q908iigngrcmy"; 136 | }; 137 | } 138 | { 139 | goPackagePath = "golang.org/x/crypto"; 140 | fetch = { 141 | type = "git"; 142 | url = "https://go.googlesource.com/crypto"; 143 | rev = "75b288015ac9"; 144 | sha256 = "18vlncvvs11ds3zaaziqjlg5s2vcwi3496nn6qv7p0dp94j5pwa2"; 145 | }; 146 | } 147 | { 148 | goPackagePath = "golang.org/x/mod"; 149 | fetch = { 150 | type = "git"; 151 | url = "https://go.googlesource.com/mod"; 152 | rev = "v0.3.0"; 153 | sha256 = "0ldgbx2zpprbsfn6p8pfgs4nn87gwbfcv2z0fa7n8alwsq2yw78q"; 154 | }; 155 | } 156 | { 157 | goPackagePath = "golang.org/x/net"; 158 | fetch = { 159 | type = "git"; 160 | url = "https://go.googlesource.com/net"; 161 | rev = "c89045814202"; 162 | sha256 = "1g3wxilwbcbf2xj20y3mpxh38jka4fyhl48akfqf00vr48zmx96x"; 163 | }; 164 | } 165 | { 166 | goPackagePath = "golang.org/x/sync"; 167 | fetch = { 168 | type = "git"; 169 | url = "https://go.googlesource.com/sync"; 170 | rev = "6e8e738ad208"; 171 | sha256 = "1avk27pszd5l5df6ff7j78wgla46ir1hhy2jwfl9a3c0ys602yx9"; 172 | }; 173 | } 174 | { 175 | goPackagePath = "golang.org/x/sys"; 176 | fetch = { 177 | type = "git"; 178 | url = "https://go.googlesource.com/sys"; 179 | rev = "85ca7c5b95cd"; 180 | sha256 = "1504qkgbhhm4f0bhk77v2r1lj6x171ay5m79alkg78wjb5cign5l"; 181 | }; 182 | } 183 | { 184 | goPackagePath = "golang.org/x/text"; 185 | fetch = { 186 | type = "git"; 187 | url = "https://go.googlesource.com/text"; 188 | rev = "v0.3.0"; 189 | sha256 = "0r6x6zjzhr8ksqlpiwm5gdd7s209kwk5p4lw54xjvz10cs3qlq19"; 190 | }; 191 | } 192 | { 193 | goPackagePath = "golang.org/x/tools"; 194 | fetch = { 195 | type = "git"; 196 | url = "https://go.googlesource.com/tools"; 197 | rev = "39188db58858"; 198 | sha256 = "1ydyylwqzjwijy4rdp2fmvnfh3s27896dx6g74r2wa6vbhisszvk"; 199 | }; 200 | } 201 | { 202 | goPackagePath = "golang.org/x/xerrors"; 203 | fetch = { 204 | type = "git"; 205 | url = "https://go.googlesource.com/xerrors"; 206 | rev = "5ec99f83aff1"; 207 | sha256 = "1dbzc3gmf2haazpv7cgmv97rq40g2xzwbglc17vas8dwhgwgwrzb"; 208 | }; 209 | } 210 | ] 211 | -------------------------------------------------------------------------------- /depsnix.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/orivej/go-nix/nix/eval" 5 | "github.com/orivej/go-nix/nix/parser" 6 | "log" 7 | "os" 8 | ) 9 | 10 | func loadDepsNix(filePath string) map[string]*Package { 11 | ret := make(map[string]*Package) 12 | 13 | stat, err := os.Stat(filePath) 14 | if err != nil { 15 | return ret 16 | } 17 | if stat.Size() == 0 { 18 | return ret 19 | } 20 | 21 | p, err := parser.ParseFile(filePath) 22 | if err != nil { 23 | log.Println("Failed reading deps.nix") 24 | return ret 25 | } 26 | 27 | evalResult := eval.ParseResult(p) 28 | for _, pkgAttrsExpr := range evalResult.(eval.List) { 29 | pkgAttrs, ok := pkgAttrsExpr.Eval().(eval.Set) 30 | if !ok { 31 | continue 32 | } 33 | fetch, ok := pkgAttrs[eval.Intern("fetch")].Eval().(eval.Set) 34 | if !ok { 35 | continue 36 | } 37 | 38 | goPackagePath, ok := pkgAttrs[eval.Intern("goPackagePath")].Eval().(string) 39 | if !ok { 40 | continue 41 | } 42 | 43 | url, ok := fetch[eval.Intern("url")].Eval().(string) 44 | if !ok { 45 | continue 46 | } 47 | rev, ok := fetch[eval.Intern("rev")].Eval().(string) 48 | if !ok { 49 | continue 50 | } 51 | sha256, ok := fetch[eval.Intern("sha256")].Eval().(string) 52 | if !ok { 53 | continue 54 | } 55 | 56 | ret[goPackagePath] = &Package{ 57 | GoPackagePath: goPackagePath, 58 | URL: url, 59 | Rev: rev, 60 | Sha256: sha256, 61 | } 62 | } 63 | 64 | return ret 65 | } 66 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/nix-community/vgo2nix 2 | 3 | require ( 4 | github.com/orivej/go-nix v0.0.0-20180830055821-dae45d921a44 5 | golang.org/x/mod v0.3.0 6 | golang.org/x/tools v0.0.0-20200904185747-39188db58858 7 | ) 8 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U= 2 | github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= 3 | github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo= 4 | github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= 5 | github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE= 6 | github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897 h1:p9Sln00KOTlrYkxI1zYWl1QLnEqAqEARBEYa8FQnQcY= 7 | github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= 8 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 9 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 10 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 11 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 12 | github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI= 13 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 14 | github.com/orivej/e v0.0.0-20180728214217-ac3492690fda h1:fqLgbcmo9qKecZOH8lByuxi9XXoIhNYBpRJEo4rDEUQ= 15 | github.com/orivej/e v0.0.0-20180728214217-ac3492690fda/go.mod h1:eOxOguJBxQH6q/o7CZvmR+fh5v1LHH1sfohtgISSSFA= 16 | github.com/orivej/go-nix v0.0.0-20180830055821-dae45d921a44 h1:XDJpMiCKWt8CIT2LE1QrF4DdrvI1WciSNUrnYtNewPo= 17 | github.com/orivej/go-nix v0.0.0-20180830055821-dae45d921a44/go.mod h1:4SkaXpoQ0tQ0OIkGqU8ByPLANmTTTU1iWPDz7YXatSA= 18 | github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= 19 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 20 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 21 | github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= 22 | github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= 23 | github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= 24 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 25 | github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 26 | github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= 27 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 28 | golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 29 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 30 | golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 31 | golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= 32 | golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= 33 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 34 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 35 | golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 36 | golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 37 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 38 | golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 39 | golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 40 | golang.org/x/sys v0.0.0-20180828065106-d99a578cf41b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 41 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 42 | golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= 43 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 44 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 45 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 46 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 47 | golang.org/x/tools v0.0.0-20200428211428-0c9eba77bc32 h1:Xvf3ZQTm5bjXPxhI7g+dwqsCqadK1rcNtwtszuatetk= 48 | golang.org/x/tools v0.0.0-20200428211428-0c9eba77bc32/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= 49 | golang.org/x/tools v0.0.0-20200904185747-39188db58858 h1:xLt+iB5ksWcZVxqc+g9K41ZHy+6MKWfXCDsjSThnsPA= 50 | golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE= 51 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 52 | golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 53 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 54 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= 55 | golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 56 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main // import "github.com/nix-community/vgo2nix" 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "flag" 7 | "fmt" 8 | "io" 9 | "math" 10 | "os" 11 | "os/exec" 12 | "regexp" 13 | "sort" 14 | "strings" 15 | 16 | "golang.org/x/mod/module" 17 | "golang.org/x/mod/semver" 18 | "golang.org/x/tools/go/vcs" 19 | ) 20 | 21 | type Package struct { 22 | GoPackagePath string 23 | URL string 24 | Rev string 25 | Sha256 string 26 | ModuleDir string 27 | } 28 | 29 | type PackageResult struct { 30 | Package *Package 31 | Error error 32 | } 33 | 34 | type modEntry struct { 35 | importPath string 36 | repo string 37 | rev string 38 | moduleDir string 39 | } 40 | 41 | const depNixFormat = ` { 42 | goPackagePath = "%s"; 43 | fetch = { 44 | type = "%s"; 45 | url = "%s"; 46 | rev = "%s"; 47 | sha256 = "%s"; 48 | moduleDir = "%s"; 49 | }; 50 | }` 51 | 52 | var versionNumber = regexp.MustCompile(`^v\d+`) 53 | 54 | func getModules() ([]*modEntry, error) { 55 | var entries []*modEntry 56 | 57 | var stderr bytes.Buffer 58 | cmd := exec.Command("go", "list", "-mod", "mod", "-json", "-m", "all") 59 | cmd.Stderr = &stderr 60 | cmd.Env = append(os.Environ(), 61 | "GO111MODULE=on", 62 | ) 63 | stdout, err := cmd.StdoutPipe() 64 | if err != nil { 65 | return nil, err 66 | } 67 | 68 | if err := cmd.Start(); err != nil { 69 | return nil, err 70 | } 71 | 72 | type goModReplacement struct { 73 | Path string 74 | Version string 75 | } 76 | 77 | type goMod struct { 78 | Path string 79 | Main bool 80 | Version string 81 | Replace *goModReplacement 82 | } 83 | 84 | var mods []goMod 85 | dec := json.NewDecoder(stdout) 86 | for { 87 | var mod goMod 88 | if err := dec.Decode(&mod); err == io.EOF { 89 | break 90 | } else if err != nil { 91 | return nil, err 92 | } 93 | 94 | if !mod.Main { 95 | mods = append(mods, mod) 96 | } 97 | } 98 | 99 | if err := cmd.Wait(); err != nil { 100 | return nil, fmt.Errorf("'go list -m all' failed with %s:\n%s", err, stderr.String()) 101 | } 102 | 103 | for _, mod := range mods { 104 | replacedPath := mod.Path 105 | version := mod.Version 106 | if mod.Replace != nil { 107 | replacedPath = mod.Replace.Path 108 | version = mod.Replace.Version 109 | } 110 | 111 | // find repo, and codeRoot 112 | repo, err := vcs.RepoRootForImportPath(replacedPath, false) 113 | if err != nil { 114 | return nil, err 115 | } 116 | 117 | // https://github.com/golang/go/blob/7bb6fed9b53494e9846689520b41b8e679bd121d/src/cmd/go/internal/modfetch/coderepo.go#L65 118 | pathPrefix := replacedPath 119 | if repo.Root != replacedPath { 120 | var ok bool 121 | pathPrefix, _, ok = module.SplitPathVersion(pathPrefix) 122 | if !ok { 123 | return nil, fmt.Errorf("invalid mod path: %s", replacedPath) 124 | } 125 | } 126 | 127 | // find submodule relative directory 128 | // https://github.com/golang/go/blob/7bb6fed9b53494e9846689520b41b8e679bd121d/src/cmd/go/internal/modfetch/coderepo.go#L74 129 | moduleDir := "" 130 | if pathPrefix != repo.Root { 131 | moduleDir = strings.TrimPrefix(pathPrefix, repo.Root+"/") 132 | } 133 | 134 | // convert version to git ref 135 | // https://github.com/golang/go/blob/7bb6fed9b53494e9846689520b41b8e679bd121d/src/cmd/go/internal/modfetch/coderepo.go#L656 136 | build := semver.Build(version) // +incompatible 137 | gitRef := strings.TrimSuffix(version, build) 138 | if strings.Count(gitRef, "-") >= 2 { 139 | // pseudo-version, use the commit hash 140 | gitRef = gitRef[strings.LastIndex(gitRef, "-")+1:] 141 | } else { 142 | if len(moduleDir) > 0 { 143 | // fix tag for submodule 144 | gitRef = moduleDir + "/" + gitRef 145 | } 146 | } 147 | 148 | fmt.Println(fmt.Sprintf("goPackagePath %s has rev: %s, module: %s", mod.Path, gitRef, moduleDir)) 149 | entries = append(entries, &modEntry{ 150 | importPath: mod.Path, 151 | repo: repo.Repo, 152 | rev: gitRef, 153 | moduleDir: moduleDir, 154 | }) 155 | } 156 | 157 | return entries, nil 158 | } 159 | 160 | func getPackages(keepGoing bool, numJobs int, prevDeps map[string]*Package) ([]*Package, error) { 161 | entries, err := getModules() 162 | if err != nil { 163 | return nil, err 164 | } 165 | 166 | processEntry := func(entry *modEntry) (*Package, error) { 167 | wrapError := func(err error) error { 168 | return fmt.Errorf("Error processing import path \"%s\": %v", entry.importPath, err) 169 | } 170 | 171 | if prevPkg, ok := prevDeps[entry.importPath]; ok { 172 | if prevPkg.URL == entry.repo && prevPkg.Rev == entry.rev { 173 | prevPkg.ModuleDir = entry.moduleDir 174 | return prevPkg, nil 175 | } 176 | } 177 | 178 | fmt.Println(fmt.Sprintf("Fetching %s %s", entry.importPath, entry.repo)) 179 | // The options for nix-prefetch-git need to match how buildGoPackage 180 | // calls fetchgit: 181 | // https://github.com/NixOS/nixpkgs/blob/8d8e56824de52a0c7a64d2ad2c4ed75ed85f446a/pkgs/development/go-modules/generic/default.nix#L54-L56 182 | // and fetchgit's defaults: 183 | // https://github.com/NixOS/nixpkgs/blob/8d8e56824de52a0c7a64d2ad2c4ed75ed85f446a/pkgs/build-support/fetchgit/default.nix#L15-L23 184 | jsonOut, err := exec.Command( 185 | "nix-prefetch-git", 186 | "--quiet", 187 | "--fetch-submodules", 188 | "--no-deepClone", 189 | "--url", entry.repo, 190 | "--rev", entry.rev).Output() 191 | if err != nil { 192 | exitError, ok := err.(*exec.ExitError) 193 | if ok { 194 | return nil, wrapError(fmt.Errorf("nix-prefetch-git --fetch-submodules --no-deepClone --url %s --rev %s failed:\n%s", 195 | entry.repo, 196 | entry.rev, 197 | exitError.Stderr)) 198 | } 199 | return nil, wrapError(fmt.Errorf("failed to execute nix-prefetch-git: %v", err)) 200 | } 201 | fmt.Println(fmt.Sprintf("Finished fetching %s", entry.importPath)) 202 | 203 | var resp map[string]interface{} 204 | if err := json.Unmarshal(jsonOut, &resp); err != nil { 205 | return nil, wrapError(err) 206 | } 207 | sha256 := resp["sha256"].(string) 208 | 209 | if sha256 == "0sjjj9z1dhilhpc8pq4154czrb79z9cm044jvn75kxcjv6v5l2m5" { 210 | return nil, wrapError(fmt.Errorf("Bad SHA256 for repo %s with rev: %s", entry.repo, entry.rev)) 211 | } 212 | 213 | return &Package{ 214 | GoPackagePath: entry.importPath, 215 | URL: entry.repo, 216 | Rev: entry.rev, 217 | Sha256: sha256, 218 | ModuleDir: entry.moduleDir, 219 | }, nil 220 | } 221 | 222 | worker := func(entries <-chan *modEntry, results chan<- *PackageResult) { 223 | for entry := range entries { 224 | pkg, err := processEntry(entry) 225 | result := &PackageResult{ 226 | Package: pkg, 227 | Error: err, 228 | } 229 | results <- result 230 | } 231 | } 232 | 233 | jobs := make(chan *modEntry, len(entries)) 234 | results := make(chan *PackageResult, len(entries)) 235 | for w := 1; w <= int(math.Min(float64(len(entries)), float64(numJobs))); w++ { 236 | go worker(jobs, results) 237 | } 238 | 239 | for _, entry := range entries { 240 | jobs <- entry 241 | } 242 | close(jobs) 243 | 244 | pkgsMap := make(map[string]*Package) 245 | for j := 1; j <= len(entries); j++ { 246 | result := <-results 247 | if result.Error != nil { 248 | if !keepGoing { 249 | return nil, result.Error 250 | } 251 | msg := fmt.Sprintf("Encountered error: %v", result.Error) 252 | fmt.Println(msg) 253 | continue 254 | } 255 | pkgsMap[result.Package.GoPackagePath] = result.Package 256 | } 257 | 258 | // Make output order stable 259 | var packages []*Package 260 | 261 | keys := make([]string, 0, len(pkgsMap)) 262 | for k := range pkgsMap { 263 | keys = append(keys, k) 264 | } 265 | sort.Strings(keys) 266 | 267 | for _, k := range keys { 268 | packages = append(packages, pkgsMap[k]) 269 | } 270 | 271 | return packages, nil 272 | } 273 | 274 | func main() { 275 | var keepGoing = flag.Bool("keep-going", false, "Whether to panic or not if a rev cannot be resolved (default \"false\")") 276 | var goDir = flag.String("dir", "./", "Go project directory") 277 | var out = flag.String("outfile", "deps.nix", "deps.nix output file (relative to project directory)") 278 | var in = flag.String("infile", "deps.nix", "deps.nix input file (relative to project directory)") 279 | var jobs = flag.Int("jobs", 20, "Number of parallel jobs") 280 | flag.Parse() 281 | 282 | err := os.Chdir(*goDir) 283 | if err != nil { 284 | panic(err) 285 | } 286 | 287 | // Load previous deps from deps.nix so we can reuse hashes for known revs 288 | prevDeps := loadDepsNix(*in) 289 | packages, err := getPackages(*keepGoing, *jobs, prevDeps) 290 | if err != nil { 291 | panic(err) 292 | } 293 | 294 | outfile, err := os.Create(*out) 295 | if err != nil { 296 | panic(err) 297 | } 298 | defer func() { 299 | if err := outfile.Close(); err != nil { 300 | panic(err) 301 | } 302 | }() 303 | 304 | write := func(line string) { 305 | bytes := []byte(line + "\n") 306 | if _, err := outfile.Write(bytes); err != nil { 307 | panic(err) 308 | } 309 | } 310 | 311 | write("# file generated from go.mod using vgo2nix (https://github.com/nix-community/vgo2nix)") 312 | write("[") 313 | for _, pkg := range packages { 314 | write(fmt.Sprintf(depNixFormat, 315 | pkg.GoPackagePath, "git", pkg.URL, 316 | pkg.Rev, pkg.Sha256, pkg.ModuleDir)) 317 | } 318 | write("]") 319 | 320 | fmt.Println(fmt.Sprintf("Wrote %s", *out)) 321 | } 322 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | with (import {}); 2 | 3 | mkShell rec { 4 | buildInputs = [ 5 | nix-prefetch-git 6 | go 7 | ] ++ lib.optionals stdenv.isDarwin [ 8 | darwin.apple_sdk.frameworks.Security 9 | ]; 10 | 11 | shellHook = '' 12 | unset GOPATH 13 | ''; 14 | } 15 | -------------------------------------------------------------------------------- /tests/run_tests: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env nix-shell 2 | #! nix-shell ./shell.nix -i python3 3 | import subprocess 4 | import tempfile 5 | import difflib 6 | import filecmp 7 | import os.path 8 | import shutil 9 | import sys 10 | import os 11 | 12 | 13 | TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) 14 | 15 | 16 | def run_testdir(testdir, workdir): 17 | for f in os.listdir(testdir): 18 | shutil.copy( 19 | os.path.join(testdir, f), 20 | os.path.join(workdir, f)) 21 | 22 | subprocess.run([ 23 | 'vgo2nix', 24 | '--dir', workdir, 25 | ]) 26 | 27 | deps_path = os.path.join(workdir, 'deps.nix') 28 | exp_path = os.path.join(workdir, 'expected.nix') 29 | 30 | if not filecmp.cmp( 31 | deps_path, 32 | exp_path, 33 | shallow=False): 34 | diff = difflib.unified_diff( 35 | open(exp_path).readlines(), 36 | open(deps_path).readlines(), 37 | fromfile='expected.nix', 38 | tofile='deps.nix') 39 | for line in diff: 40 | sys.stderr.write(line) 41 | exit(1) 42 | 43 | 44 | if __name__ == '__main__': 45 | for testdir in os.listdir(TESTS_DIR): 46 | testdir = os.path.join(TESTS_DIR, testdir) 47 | if not os.path.isdir(testdir): 48 | continue 49 | 50 | with tempfile.TemporaryDirectory() as workdir: 51 | run_testdir(testdir, workdir) 52 | -------------------------------------------------------------------------------- /tests/shell.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | 3 | let 4 | vgo2nix = import ../default.nix {}; 5 | 6 | in mkShell { 7 | buildInputs = [ 8 | python3 9 | vgo2nix 10 | ]; 11 | } 12 | -------------------------------------------------------------------------------- /tests/test_major_version/expected.nix: -------------------------------------------------------------------------------- 1 | # file generated from go.mod using vgo2nix (https://github.com/nix-community/vgo2nix) 2 | [ 3 | { 4 | goPackagePath = "github.com/cespare/xxhash/v2"; 5 | fetch = { 6 | type = "git"; 7 | url = "https://github.com/yihuang/test-golang-module-major-version"; 8 | rev = "4a13e4bfd5a9"; 9 | sha256 = "0i1bpw3v73jhwnpa8vv276qhy39fk6qhgyci0wng9mwr2pxfha5y"; 10 | moduleDir = ""; 11 | }; 12 | } 13 | { 14 | goPackagePath = "github.com/yihuang/test-golang-module-major-version"; 15 | fetch = { 16 | type = "git"; 17 | url = "https://github.com/yihuang/test-golang-module-major-version"; 18 | rev = "v1.0.1"; 19 | sha256 = "10gnzs3l8j6skyrfi2blvqx9b3l2bs2gdvrgjg7a9aiz6z7dkpvy"; 20 | moduleDir = ""; 21 | }; 22 | } 23 | { 24 | goPackagePath = "github.com/yihuang/test-golang-module-major-version/sub"; 25 | fetch = { 26 | type = "git"; 27 | url = "https://github.com/yihuang/test-golang-module-major-version"; 28 | rev = "sub/v1.0.2"; 29 | sha256 = "0g89fd75mhfyxgw2ip69idaf14586l9birq0kz59mdpak1ywr0k8"; 30 | moduleDir = "sub"; 31 | }; 32 | } 33 | { 34 | goPackagePath = "github.com/yihuang/test-golang-module-major-version/sub/v2"; 35 | fetch = { 36 | type = "git"; 37 | url = "https://github.com/yihuang/test-golang-module-major-version"; 38 | rev = "sub/v2.0.1"; 39 | sha256 = "026cfk2bpc7cyddabj8fcay3nysbj9zjam63jbq8psav4qwhwc2d"; 40 | moduleDir = "sub"; 41 | }; 42 | } 43 | { 44 | goPackagePath = "github.com/yihuang/test-golang-module-major-version/v2"; 45 | fetch = { 46 | type = "git"; 47 | url = "https://github.com/yihuang/test-golang-module-major-version"; 48 | rev = "v2.0.1"; 49 | sha256 = "026cfk2bpc7cyddabj8fcay3nysbj9zjam63jbq8psav4qwhwc2d"; 50 | moduleDir = ""; 51 | }; 52 | } 53 | { 54 | goPackagePath = "gopkg.in/check.v1"; 55 | fetch = { 56 | type = "git"; 57 | url = "https://gopkg.in/check.v1"; 58 | rev = "20d25e280405"; 59 | sha256 = "0k1m83ji9l1a7ng8a7v40psbymxasmssbrrhpdv2wl4rhs0nc3np"; 60 | moduleDir = ""; 61 | }; 62 | } 63 | { 64 | goPackagePath = "gopkg.in/yaml.v2"; 65 | fetch = { 66 | type = "git"; 67 | url = "https://gopkg.in/yaml.v2"; 68 | rev = "v2.3.0"; 69 | sha256 = "1md0hlyd9s6myv3663i9l59y74n4xjazifmmyxn43g86fgkc5lzj"; 70 | moduleDir = ""; 71 | }; 72 | } 73 | ] 74 | -------------------------------------------------------------------------------- /tests/test_major_version/go.mod: -------------------------------------------------------------------------------- 1 | module testmod 2 | 3 | require github.com/yihuang/test-golang-module-major-version v1.0.1 4 | require github.com/yihuang/test-golang-module-major-version/v2 v2.0.1 5 | require github.com/yihuang/test-golang-module-major-version/sub v1.0.2 6 | require github.com/yihuang/test-golang-module-major-version/sub/v2 v2.0.1 7 | require ( 8 | github.com/cespare/xxhash/v2 v2.1.1 9 | gopkg.in/yaml.v2 v2.3.0 10 | ) 11 | 12 | replace github.com/cespare/xxhash/v2 v2.1.1 => github.com/yihuang/test-golang-module-major-version/v2 v2.0.2-0.20200924181748-4a13e4bfd5a9 13 | -------------------------------------------------------------------------------- /tests/test_major_version/go.sum: -------------------------------------------------------------------------------- 1 | github.com/yihuang/test-golang-module-major-version v1.0.1 h1:/k3OIPYLrQymj44jPgwG6v2JUEqsClgohLNsnnoujxk= 2 | github.com/yihuang/test-golang-module-major-version v1.0.1/go.mod h1:6ffZEJfhUE+kNfJqTGgm162S5pSCL8pOfJRTJwT1cUU= 3 | github.com/yihuang/test-golang-module-major-version/sub v1.0.1 h1:J7EEv0ogIPqeaZpK/59St9aPiS1Fdi0cwDCvIJH/eaM= 4 | github.com/yihuang/test-golang-module-major-version/sub v1.0.1/go.mod h1:03uOGLsMBIDw1AHgKu7tZyRWSzlMou2bNEi99gUqD4Y= 5 | github.com/yihuang/test-golang-module-major-version/sub v1.0.2 h1:yaZ6dUjX5Urt7so1Q/OU3eNzGLC8WR70buuH0fcSTdc= 6 | github.com/yihuang/test-golang-module-major-version/sub v1.0.2/go.mod h1:03uOGLsMBIDw1AHgKu7tZyRWSzlMou2bNEi99gUqD4Y= 7 | github.com/yihuang/test-golang-module-major-version/sub/v2 v2.0.1 h1:OzYeUqx0m4ctMJgdjl5+OD5ZGH9N4X8i9uC5Ibx3l9A= 8 | github.com/yihuang/test-golang-module-major-version/sub/v2 v2.0.1/go.mod h1:/IrwjSq8jNEebG7aFnJbdgcSyyldSG23VDZzCePZZi0= 9 | github.com/yihuang/test-golang-module-major-version/v2 v2.0.1 h1:uW41SEo7xYdcK3IiRXVoWeZQbJWK81GKC7pGGZEhlbo= 10 | github.com/yihuang/test-golang-module-major-version/v2 v2.0.1/go.mod h1:aBzLwyu2rt20DK0DbRBUKOLPiRfQ47OhZUE4KNs32DI= 11 | github.com/yihuang/test-golang-module-major-version/v2 v2.0.2-0.20200924181748-4a13e4bfd5a9 h1:1MtOSTQvrqLEBdqQgBDxUFcnQR5wmbMBIfjPkZz2pfA= 12 | github.com/yihuang/test-golang-module-major-version/v2 v2.0.2-0.20200924181748-4a13e4bfd5a9/go.mod h1:aBzLwyu2rt20DK0DbRBUKOLPiRfQ47OhZUE4KNs32DI= 13 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 14 | gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU= 15 | gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= 16 | -------------------------------------------------------------------------------- /tests/test_major_version/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | 6 | replaced "github.com/cespare/xxhash/v2" 7 | v1 "github.com/yihuang/test-golang-module-major-version" 8 | v1_sub "github.com/yihuang/test-golang-module-major-version/sub" 9 | v2_sub "github.com/yihuang/test-golang-module-major-version/sub/v2" 10 | v2 "github.com/yihuang/test-golang-module-major-version/v2" 11 | "gopkg.in/yaml.v2" 12 | ) 13 | 14 | func main() { 15 | fmt.Println(v1.Test(), v2.Test(), v1_sub.Test(), v2_sub.Test(), replaced.Test()) 16 | fmt.Println(yaml.Marshal(1)) 17 | } 18 | -------------------------------------------------------------------------------- /tests/test_package/expected.nix: -------------------------------------------------------------------------------- 1 | # file generated from go.mod using vgo2nix (https://github.com/nix-community/vgo2nix) 2 | [ 3 | { 4 | goPackagePath = "github.com/alecthomas/assert"; 5 | fetch = { 6 | type = "git"; 7 | url = "https://github.com/alecthomas/assert"; 8 | rev = "405dbfeb8e38"; 9 | sha256 = "1l567pi17k593nrd1qlbmiq8z9jy3qs60px2a16fdpzjsizwqx8l"; 10 | moduleDir = ""; 11 | }; 12 | } 13 | { 14 | goPackagePath = "github.com/alecthomas/colour"; 15 | fetch = { 16 | type = "git"; 17 | url = "https://github.com/alecthomas/colour"; 18 | rev = "60882d9e2721"; 19 | sha256 = "0iq566534gbzkd16ixg7fk298wd766821vvs80838yifx9yml5vs"; 20 | moduleDir = ""; 21 | }; 22 | } 23 | { 24 | goPackagePath = "github.com/alecthomas/kingpin"; 25 | fetch = { 26 | type = "git"; 27 | url = "https://github.com/alecthomas/kingpin"; 28 | rev = "v2.2.6"; 29 | sha256 = "0mndnv3hdngr3bxp7yxfd47cas4prv98sqw534mx7vp38gd88n5r"; 30 | moduleDir = ""; 31 | }; 32 | } 33 | { 34 | goPackagePath = "github.com/alecthomas/repr"; 35 | fetch = { 36 | type = "git"; 37 | url = "https://github.com/alecthomas/repr"; 38 | rev = "117648cd9897"; 39 | sha256 = "05v1rgzdqc8razf702laagrvhvx68xd9yxxmzd3dyz0d6425pdrp"; 40 | moduleDir = ""; 41 | }; 42 | } 43 | { 44 | goPackagePath = "github.com/alecthomas/template"; 45 | fetch = { 46 | type = "git"; 47 | url = "https://github.com/alecthomas/template"; 48 | rev = "a0175ee3bccc"; 49 | sha256 = "0qjgvvh26vk1cyfq9fadyhfgdj36f1iapbmr5xp6zqipldz8ffxj"; 50 | moduleDir = ""; 51 | }; 52 | } 53 | { 54 | goPackagePath = "github.com/alecthomas/units"; 55 | fetch = { 56 | type = "git"; 57 | url = "https://github.com/alecthomas/units"; 58 | rev = "2efee857e7cf"; 59 | sha256 = "1j65b91qb9sbrml9cpabfrcf07wmgzzghrl7809hjjhrmbzri5bl"; 60 | moduleDir = ""; 61 | }; 62 | } 63 | { 64 | goPackagePath = "github.com/davecgh/go-spew"; 65 | fetch = { 66 | type = "git"; 67 | url = "https://github.com/davecgh/go-spew"; 68 | rev = "v1.1.1"; 69 | sha256 = "0hka6hmyvp701adzag2g26cxdj47g21x6jz4sc6jjz1mn59d474y"; 70 | moduleDir = ""; 71 | }; 72 | } 73 | { 74 | goPackagePath = "github.com/mattn/go-isatty"; 75 | fetch = { 76 | type = "git"; 77 | url = "https://github.com/mattn/go-isatty"; 78 | rev = "v0.0.3"; 79 | sha256 = "06w45aqz2a6yrk25axbly2k5wmsccv8cspb94bfmz4izvw8h927n"; 80 | moduleDir = ""; 81 | }; 82 | } 83 | { 84 | goPackagePath = "github.com/orivej/e"; 85 | fetch = { 86 | type = "git"; 87 | url = "https://github.com/orivej/e"; 88 | rev = "ac3492690fda"; 89 | sha256 = "11jizr28kfkr6zscjxg95pqi6cjp08aqnhs41sdhc98nww78ilkr"; 90 | moduleDir = ""; 91 | }; 92 | } 93 | { 94 | goPackagePath = "github.com/orivej/go-nix"; 95 | fetch = { 96 | type = "git"; 97 | url = "https://github.com/orivej/go-nix"; 98 | rev = "dae45d921a44"; 99 | sha256 = "17hfmsz8hs3h2d5c06j1bvbw8ijrhzm3iz911z5zydsl4x7y0cgy"; 100 | moduleDir = ""; 101 | }; 102 | } 103 | { 104 | goPackagePath = "github.com/pkg/profile"; 105 | fetch = { 106 | type = "git"; 107 | url = "https://github.com/pkg/profile"; 108 | rev = "v1.2.1"; 109 | sha256 = "0blqmvgqvdbqmh3fp9pfdxc9w1qfshrr0zy9whj0sn372bw64qnr"; 110 | moduleDir = ""; 111 | }; 112 | } 113 | { 114 | goPackagePath = "github.com/pmezard/go-difflib"; 115 | fetch = { 116 | type = "git"; 117 | url = "https://github.com/pmezard/go-difflib"; 118 | rev = "v1.0.0"; 119 | sha256 = "0c1cn55m4rypmscgf0rrb88pn58j3ysvc2d0432dp3c6fqg6cnzw"; 120 | moduleDir = ""; 121 | }; 122 | } 123 | { 124 | goPackagePath = "github.com/sergi/go-diff"; 125 | fetch = { 126 | type = "git"; 127 | url = "https://github.com/sergi/go-diff"; 128 | rev = "v1.0.0"; 129 | sha256 = "0swiazj8wphs2zmk1qgq75xza6m19snif94h2m6fi8dqkwqdl7c7"; 130 | moduleDir = ""; 131 | }; 132 | } 133 | { 134 | goPackagePath = "github.com/stretchr/testify"; 135 | fetch = { 136 | type = "git"; 137 | url = "https://github.com/stretchr/testify"; 138 | rev = "v1.2.2"; 139 | sha256 = "0dlszlshlxbmmfxj5hlwgv3r22x0y1af45gn1vd198nvvs3pnvfs"; 140 | moduleDir = ""; 141 | }; 142 | } 143 | { 144 | goPackagePath = "golang.org/x/sys"; 145 | fetch = { 146 | type = "git"; 147 | url = "https://go.googlesource.com/sys"; 148 | rev = "d99a578cf41b"; 149 | sha256 = "10q9xx4pmnq92qn6ff4xp7n1hx766wvw2rf7pqcd6rx5plgwz8cm"; 150 | moduleDir = ""; 151 | }; 152 | } 153 | { 154 | goPackagePath = "golang.org/x/tools"; 155 | fetch = { 156 | type = "git"; 157 | url = "https://go.googlesource.com/tools"; 158 | rev = "ded554d0681e"; 159 | sha256 = "04rlq9hc3ccww9sbsrl48fl6wbjprb136rqxyr7dmgfj444aml56"; 160 | moduleDir = ""; 161 | }; 162 | } 163 | ] 164 | -------------------------------------------------------------------------------- /tests/test_package/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/nix-community/vgo2nix 2 | 3 | require ( 4 | github.com/orivej/go-nix v0.0.0-20180830055821-dae45d921a44 5 | golang.org/x/tools v0.0.0-20180723204246-ded554d0681e 6 | ) 7 | -------------------------------------------------------------------------------- /tests/test_package/go.sum: -------------------------------------------------------------------------------- 1 | github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= 2 | github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= 3 | github.com/alecthomas/kingpin v2.2.6+incompatible/go.mod h1:59OFYbFVLKQKq+mqrL6Rw5bR0c3ACQaawgXx0QYndlE= 4 | github.com/alecthomas/repr v0.0.0-20180818092828-117648cd9897/go.mod h1:xTS7Pm1pD1mvyM075QCDSRqH6qRLXylzS24ZTpRiSzQ= 5 | github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= 6 | github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= 7 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 8 | github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= 9 | github.com/orivej/e v0.0.0-20180728214217-ac3492690fda h1:fqLgbcmo9qKecZOH8lByuxi9XXoIhNYBpRJEo4rDEUQ= 10 | github.com/orivej/e v0.0.0-20180728214217-ac3492690fda/go.mod h1:eOxOguJBxQH6q/o7CZvmR+fh5v1LHH1sfohtgISSSFA= 11 | github.com/orivej/go-nix v0.0.0-20180830055821-dae45d921a44 h1:XDJpMiCKWt8CIT2LE1QrF4DdrvI1WciSNUrnYtNewPo= 12 | github.com/orivej/go-nix v0.0.0-20180830055821-dae45d921a44/go.mod h1:4SkaXpoQ0tQ0OIkGqU8ByPLANmTTTU1iWPDz7YXatSA= 13 | github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA= 14 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 15 | github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= 16 | github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= 17 | golang.org/x/sys v0.0.0-20180828065106-d99a578cf41b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 18 | golang.org/x/tools v0.0.0-20180723204246-ded554d0681e h1:MdemAmHdS4ocpCJfN4Ysk8qwrIWKDssMCJlUDuprxuw= 19 | golang.org/x/tools v0.0.0-20180723204246-ded554d0681e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 20 | -------------------------------------------------------------------------------- /tests/test_replace_url/expected.nix: -------------------------------------------------------------------------------- 1 | # file generated from go.mod using vgo2nix (https://github.com/nix-community/vgo2nix) 2 | [ 3 | { 4 | goPackagePath = "golang.org/x/text"; 5 | fetch = { 6 | type = "git"; 7 | url = "https://github.com/golang/text"; 8 | rev = "v0.3.2"; 9 | sha256 = "0flv9idw0jm5nm8lx25xqanbkqgfiym6619w575p7nrdh0riqwqh"; 10 | moduleDir = ""; 11 | }; 12 | } 13 | { 14 | goPackagePath = "golang.org/x/tools"; 15 | fetch = { 16 | type = "git"; 17 | url = "https://go.googlesource.com/tools"; 18 | rev = "90fa682c2a6e"; 19 | sha256 = "03ic2xsy51jw9749wl7gszdbz99iijbd2bckgygl6cm9w5m364ak"; 20 | moduleDir = ""; 21 | }; 22 | } 23 | ] 24 | -------------------------------------------------------------------------------- /tests/test_replace_url/go.mod: -------------------------------------------------------------------------------- 1 | module testmodule 2 | 3 | require golang.org/x/text v0.3.2 4 | 5 | replace golang.org/x/text => github.com/golang/text v0.3.2 6 | -------------------------------------------------------------------------------- /tests/test_replace_url/go.sum: -------------------------------------------------------------------------------- 1 | github.com/golang/text v0.3.2 h1:vDAeTQXl8YUdGoj2vMsMnzHi1xMJJ9S7iwnTBFL/pkA= 2 | github.com/golang/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 3 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 4 | -------------------------------------------------------------------------------- /tests/test_replace_url/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import _ "golang.org/x/text" 4 | 5 | func main() { 6 | } 7 | -------------------------------------------------------------------------------- /tests/test_replace_version/expected.nix: -------------------------------------------------------------------------------- 1 | # file generated from go.mod using vgo2nix (https://github.com/nix-community/vgo2nix) 2 | [ 3 | { 4 | goPackagePath = "github.com/coreos/go-systemd"; 5 | fetch = { 6 | type = "git"; 7 | url = "https://github.com/coreos/go-systemd"; 8 | rev = "v22.0.0"; 9 | sha256 = "0p4sb2fxxm2j1xny2l4fkq4kwj74plvh600gih8nyniqzannhrdx"; 10 | moduleDir = ""; 11 | }; 12 | } 13 | { 14 | goPackagePath = "github.com/godbus/dbus/v5"; 15 | fetch = { 16 | type = "git"; 17 | url = "https://github.com/godbus/dbus"; 18 | rev = "v5.0.3"; 19 | sha256 = "1bkc904073k807yxg6mvqaxrr6ammmhginr9p54jfb55mz3hfw3s"; 20 | moduleDir = ""; 21 | }; 22 | } 23 | ] 24 | -------------------------------------------------------------------------------- /tests/test_replace_version/go.mod: -------------------------------------------------------------------------------- 1 | module testmodule 2 | 3 | require github.com/coreos/go-systemd v0.0.0-00010101000000-000000000000 4 | 5 | replace github.com/coreos/go-systemd => github.com/coreos/go-systemd/v22 v22.0.0 6 | -------------------------------------------------------------------------------- /tests/test_replace_version/go.sum: -------------------------------------------------------------------------------- 1 | github.com/coreos/go-systemd/v22 v22.0.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= 2 | github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= 3 | -------------------------------------------------------------------------------- /tests/test_reporoot/expected.nix: -------------------------------------------------------------------------------- 1 | # file generated from go.mod using vgo2nix (https://github.com/nix-community/vgo2nix) 2 | [ 3 | { 4 | goPackagePath = "github.com/ugorji/go"; 5 | fetch = { 6 | type = "git"; 7 | url = "https://github.com/ugorji/go"; 8 | rev = "v1.1.2"; 9 | sha256 = "0fq4k5239w29qv587a95ivzmdf5jnbhdmc4y2ny87nw3i3qmgsj4"; 10 | moduleDir = ""; 11 | }; 12 | } 13 | { 14 | goPackagePath = "github.com/ugorji/go/codec"; 15 | fetch = { 16 | type = "git"; 17 | url = "https://github.com/ugorji/go"; 18 | rev = "8fd0f8d918c8"; 19 | sha256 = "0fq4k5239w29qv587a95ivzmdf5jnbhdmc4y2ny87nw3i3qmgsj4"; 20 | moduleDir = "codec"; 21 | }; 22 | } 23 | ] 24 | -------------------------------------------------------------------------------- /tests/test_reporoot/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/nix-community/vgo2nix/tests/test_reporoot 2 | 3 | require github.com/ugorji/go/codec v0.0.0-20190126102652-8fd0f8d918c8 4 | -------------------------------------------------------------------------------- /tests/test_reporoot/go.sum: -------------------------------------------------------------------------------- 1 | github.com/ugorji/go v1.1.2 h1:JON3E2/GPW2iDNGoSAusl1KDf5TRQ8k8q7Tp097pZGs= 2 | github.com/ugorji/go v1.1.2/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ= 3 | github.com/ugorji/go/codec v0.0.0-20190126102652-8fd0f8d918c8 h1:X8lhf4a2HZiqw4DKNWz9aFZdssVV69au98QlhPXrEp8= 4 | github.com/ugorji/go/codec v0.0.0-20190126102652-8fd0f8d918c8/go.mod h1:iT03XoTwV7xq/+UGwKO3UbC1nNNlopQiY61beSdrtOA= 5 | --------------------------------------------------------------------------------