Skip to content

nixcloud/dep2nix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dep2nix

dep2nix converts a Gopkgs.lock file into a deps.nix file which is understood by nixpkgs's go abstraction thanks to go2nix effort.

In other words: For go projects using golang dep already, it is fairly trivial to get these projects to compile with Nix/NixOS.

Usage

Installation

git clone https://github.com/nixcloud/dep2nix
cd dep2nix
nix-env -f default.nix -i dep2nix

Using dep2nix

cd yourproject   (contains the Gopkg.lock)

dep2nix [-i Gopkg.lock] [-o deps.nix]
Found 14 projects to process.
* Processing: "github.com/Masterminds/semver"
* Processing: "github.com/Masterminds/vcs"
* Processing: "github.com/armon/go-radix"
* Processing: "github.com/boltdb/bolt"
* Processing: "github.com/golang/dep"
* Processing: "github.com/golang/protobuf"
* Processing: "github.com/jmank88/nuts"
* Processing: "github.com/nightlyone/lockfile"
* Processing: "github.com/pelletier/go-toml"
* Processing: "github.com/pkg/errors"
* Processing: "github.com/sdboyer/constext"
* Processing: "golang.org/x/net"
* Processing: "golang.org/x/sync"
* Processing: "golang.org/x/sys"

-> Wrote deps.nix, everything fine!

dep2nix has created a deps.nix file similar to the one originally created by go2nix tool. If you wonder how to compile your GO based project with nixpkgs just look into the source code of this project itself at https://github.com/nixcloud/dep2nix

Note: It is good practice to keep the Gopkg.lock, Gopkg.toml as well as the deps.nix in the GIT repository of your project.

Using dep

nix-shell -p go dep
cd yourproject
dep init
dep2nix

Issues

Building the source

On one test machine dep2nix wouldn't build with the error that lockfile had a 'wrong' sha256:

{
  goPackagePath  = "github.com/nightlyone/lockfile";
  fetch = {
    type = "git";
    url = "https://github.com/nightlyone/lockfile";
    rev =  "6a197d5ea61168f2ac821de2b7f011b250904900";
    sha256 = "0z3bdl5hb7nq2pqx7zy0r47bcdvjw0y11jjphv7k0s09ahlnac29";
  };
}

But running nix-prefetch-git --url https://github.com/nightlyone/lockfile --rev 6a197d5ea61168f2ac821de2b7f011b250904900 showed it was actually correct.

After running nix-build it showed the /nix/store/krjm0nanydmyyddx222vn443hq13fsis-dep2nix.drv target and then this call:

nix-store --delete /nix/store/krjm0nanydmyyddx222vn443hq13fsis-dep2nix.drv

Resets the complete build artifacts and afterwards it was working. No clue what is going on there...

nix-prefetch-git

returns bogus for not existent git repos as golang.org/x/net for example, this needs to return at least erropr code != 0

golang dep (git repo hash extension)

License

See LICENSE file.

About

Using golang/dep to create a deps.nix file for go projects to package them for nixpkgs.

Resources

License

Stars

Watchers

Forks

Packages

No packages published