Skip to content

Commit

Permalink
Added dependency tracking and pinning using the "dep" tool
Browse files Browse the repository at this point in the history
- Added go2nix in order to make installation in deployments-repo easy
- Added shell.nix which has all necessary build tools and dep tools
- Updated README.md with procedures for building, update-pinning and creating a nix-derivation
  • Loading branch information
Johan Thomsen committed Apr 3, 2018
1 parent cd06825 commit 15ddcb9
Show file tree
Hide file tree
Showing 7 changed files with 238 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@

# Default binary output file name
/morph

# vendor cache dir
/vendor

# go2nix outfiles
/default.nix
/deps.nix
60 changes: 60 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
# for detailed Gopkg.toml documentation.
#
# required = ["github.com/user/thing/cmd/thing"]
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
#
# [[constraint]]
# name = "github.com/user/project"
# version = "1.0.0"
#
# [[constraint]]
# name = "github.com/user/project2"
# branch = "dev"
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/gobwas/glob"
version = "0.2.3"

[[constraint]]
branch = "master"
name = "golang.org/x/crypto"

[[constraint]]
name = "gopkg.in/alecthomas/kingpin.v2"
version = "2.2.6"

[prune]
go-tests = true
unused-packages = true
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@

## Nix shell

All commands mentioned below is available in the nix-shell, if you run `nix-shell` with working dir = project root.

## Go dependencies

Run `dep ensure -vendor-only` to (re-)install pinned dependencies in vendor-dir

Gopkg.toml specifies at which branch/tag each dependency is requested to be at.
Gopkg.lock specifies a concrete revision each dependency is pinned at.

If you want to bump dependencies to newest commit, run `dep ensure -update`, this will change Gopkg.lock, which has to be git-committed.

If you make larger changes to the code base, you can delete both Gopkg.toml and Gopkg.lock and run `dep init` followed by `dep ensure` to create a fresh set of dependency tracking files. **don't forget to test** afterwards.

## Assets

Run `go-bindata -pkg assets -o assets/assets.go data/` after updating files from data/

## Building the project with pinned dependencies

$ `nix-shell`

$ `dep ensure -vendor-only`

$ `go build`

*Your GOPATH must be set in your local environment, however /vendor is used exclusively for dependency resolution.*


## Building a nix derivation

$ `nix-shell`

$ `dep ensure -vendor-only`

$ `go2nix save`

*Produces "default.nix" and "deps.nix" which can be copied to the deployments repo*
48 changes: 48 additions & 0 deletions go2nix-deps.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# This file was generated by https://github.com/kamilchm/go2nix v2.0-dev
[
{
goPackagePath = "github.com/Masterminds/semver";
fetch = {
type = "git";
url = "https://github.com/Masterminds/semver";
rev = "517734cc7d6470c0d07130e40fd40bdeb9bcd3fd";
sha256 = "1625b5sxpmlz60jw67j1ljfcc09d4lhxg3z6gc4am8s2rrdgwij6";
};
}
{
goPackagePath = "github.com/Masterminds/vcs";
fetch = {
type = "git";
url = "https://github.com/Masterminds/vcs";
rev = "3084677c2c188840777bff30054f2b553729d329";
sha256 = "1062m73h0pp5d0574lf6px4jsjgywnsbkw50inxx3zal5r185ydm";
};
}
{
goPackagePath = "github.com/pelletier/go-buffruneio";
fetch = {
type = "git";
url = "https://github.com/pelletier/go-buffruneio";
rev = "c37440a7cf42ac63b919c752ca73a85067e05992";
sha256 = "0l83p1gg6g5mmhmxjisrhfimhbm71lwn1r2w7d6siwwqm9q08sd2";
};
}
{
goPackagePath = "github.com/pelletier/go-toml";
fetch = {
type = "git";
url = "https://github.com/pelletier/go-toml";
rev = "5ccdfb18c776b740aecaf085c4d9a2779199c279";
sha256 = "1jl44j58y62rhnwkzw3mvcj725gdyzs45pq4ga81qqxwqxs3czsq";
};
}
{
goPackagePath = "golang.org/x/tools";
fetch = {
type = "git";
url = "https://go.googlesource.com/tools";
rev = "e6cb469339aef5b7be0c89de730d5f3cc8e47e50";
sha256 = "16q3ibisbzq8rx4irhzl2lw4nwr62x9ryv446kgic8ww3p30rlf9";
};
}
]
25 changes: 25 additions & 0 deletions go2nix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This file was generated by https://github.com/kamilchm/go2nix v2.0-dev
{ pkgs, stdenv, buildGoPackage, fetchFromGitHub, ... }:
with import <nixpkgs> {};

buildGoPackage rec {
name = "go2nix-unstable-${version}";
version = "0.2-dev";

goPackagePath = "github.com/kamilchm/go2nix";
subPackages = [ "cmd/go2nix" ];

src = fetchFromGitHub {
owner = "kamilchm";
repo = "go2nix";
rev = "6cd52450c74f013a7e7c284526b3983dd918b070";
sha256 = "1bazkn7f5pydcqsvqg8yfx56h4162i2sya8q835ssc8bbp5y8as6";
};

goDeps = ./go2nix-deps.nix;

meta = {
homepage = "https://github.com/kamilchm/go2nix";
description = "Reproducible builds and development environment for Go";
};
}
17 changes: 17 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ pkgs ? (import <nixpkgs> {}) }:

let
go2nix_v2 = pkgs.callPackage ./go2nix.nix {};
in
# Change to mkShell once that hits stable!
pkgs.stdenv.mkDerivation {
name = "morph-build-env";

buildInputs = with pkgs; [
go2nix_v2
go-bindata
nix-prefetch-git
dep
bashInteractive
];
}

0 comments on commit 15ddcb9

Please sign in to comment.