Git Product home page Git Product logo

dep2nix's Introduction

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
nix-env -i nix-prefetch-git    (this step might not be needed anymore soon)

Using dep2nix

cd yourproject   (contains the Gopkg.lock)

dep2nix
Found 14 libraries to process: 
github.com/Masterminds/semver github.com/Masterminds/vcs github.com/armon/go-radix github.com/boltdb/bolt github.com/golang/dep github.com/golang/protobuf github.com/jmank88/nuts github.com/nightlyone/lockfile github.com/pelletier/go-toml github.com/pkg/errors github.com/sdboyer/constext golang.org/x/net golang.org/x/sync golang.org/x/sys 

* 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.

Todo(s) left

  • integrate into nixpkgs, add nix-prefetch-url as dependency for this tool

    • https://blog.golang.org/generate

        joachim@lenovo-t530 ~/D/p/n/nixpkgs> git grep 'go generate'
        pkgs/applications/networking/gopher/gopherclient/default.nix:    PATH="$(pwd):$PATH" go generate ${goPackagePath}
        pkgs/applications/version-management/git-lfs/1.nix:      go generate ./commands
        pkgs/applications/version-management/git-lfs/default.nix:    go generate ./commands
        pkgs/development/interpreters/joker/default.nix:  preBuild = "go generate ./...";
        pkgs/development/tools/continuous-integration/drone/default.nix:    go generate github.com/drone/drone/server/template
        pkgs/development/tools/continuous-integration/drone/default.nix:    go generate github.com/drone/drone/store/datastore/ddl
        pkgs/development/tools/go2nix/default.nix:  preBuild = ''go generate ./...'';
        pkgs/development/tools/kube-aws/default.nix:    go generate ./core/controlplane/config
        pkgs/development/tools/kube-aws/default.nix:    go generate ./core/nodepool/config
        pkgs/development/tools/kube-aws/default.nix:    go generate ./core/root/config
        pkgs/servers/monitoring/mtail/default.nix:  preBuild = "go generate -x ./go/src/github.com/google/mtail/vm/";
      
  • add Flags:

  • check to not overwrite the deps.nix if already there

  • help

  • also write 'incomplete' deps.nix (with 1 exit code and warning) if dependencies using nix-prefetch-url fail

  • test with leaps

  • blog this

dep2nix's People

Contributors

qknight avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.