kamilchm / go2nix

Reproducible builds and development environment for Go
MIT License
94 stars 17 forks source link

How do you use this? #11

Closed chris-martin closed 8 years ago

chris-martin commented 8 years ago

With the Haskell infrastructure, I check out a project and run cabal2nix . > projectname.nix.

So for Go, I tried the same thing. I cloned btcd, and then

$ nix-shell -p go2nix --command 'go2nix save'
2016/04/23 10:38:23 No GOPATH set, can't find dependencies

Okay, so it doesn't look in the present working directory by default?

$ env GOPATH=$PWD nix-shell -p go2nix --command 'go2nix save'
2016/04/23 10:39:19 Current dir /home/chris/git/btcd is outside of GOPATH(/home/chris/git/btcd). Can't get current package name

Is that a bug? It says a directory is outside of itself.

(I'm gussing this would be clear if I were already more familiar with building Go projects, but I haven't used Go before.)

kamilchm commented 8 years ago

As I mention in https://github.com/NixOS/nixpkgs/pull/14904#issuecomment-214195812 it's just a PoC and I working on major rework on common-libs branch. So there's no docs here :/ and I plan to write about usage when I settle with implementation. But it should be usable right now generating derivations with complete dependency set. First, you need to setup you Go environment with proper GOPATH https://github.com/golang/go/wiki/GOPATH. Then try to do:

$ go get -u github.com/btcsuite/btcd/...
$ cd $GOPATH/src/github.com/btcsuite/btcd
$ go2nix save

It should produce complete default.nix that you can build or include somewhere in nixpkgs. Simple cloning won't work, because go get download all dependencies that needs to be present before generating nix derivation. This is how most Go projects manage its dependencies.

kamilchm commented 8 years ago

buildGoPackage can use json files for dependencies like in https://github.com/NixOS/nixpkgs/blob/7d02cc1dd50766058b2ec2c6d3a741d96db5d27b/doc/languages-frameworks/go.xml and go2nix master supports this new format. README.md was updated too.