Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Refactor flake and overlay
Browse files Browse the repository at this point in the history
- Move added packages into their own files
- Expose legacyPackages, overlay, and overlays attr in flake output
- Use protobuf3_15 instead of override
- Add devShell to overlay
  • Loading branch information
jonringer committed Oct 21, 2021
1 parent db8ae6a commit edabcd5
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 145 deletions.
24 changes: 12 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
inputs.flake-utils.url = "github:numtide/flake-utils";

outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
localOverlay = import ./nix/overlay.nix;
overlays = [ localOverlay ];
in flake-utils.lib.eachDefaultSystem (system:
let
overlay = (import ./nix/overlay.nix) nixpkgs;

pkgs = import nixpkgs {
inherit system;
overlays = [ overlay ];
};

waypoint = pkgs.callPackage ./nix/waypoint.nix {
inherit pkgs;
inherit system overlays;
};
in {
devShell = waypoint.shell;
}
);
legacyPackages = pkgs;
inherit (pkgs) devShell;
}) // {
# platform independent attrs
overlay = final: prev: (nixpkgs.lib.composeManyExtensions overlays) final prev;
inherit overlays;
};
}
17 changes: 17 additions & 0 deletions nix/go-changelog.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ buildGoModule, fetchFromGitHub }:

buildGoModule rec {
pname = "go-changelog";
version = "56335215ce3a8676ba7153be7c444daadcb132c7";

src = fetchFromGitHub {
owner = "hashicorp";
repo = "go-changelog";
rev = "56335215ce3a8676ba7153be7c444daadcb132c7";
sha256 = "0z6ysz4x1rim09g9knbc5x5mrasfk6mzsi0h7jn8q4i035y1gg2j";
};

vendorSha256 = "1pahh64ayr885kv9rd5i4vh4a6hi1w583wch9n1ncvnckznzsdbg";

subPackages = [ "cmd/changelog-build" ];
}
23 changes: 23 additions & 0 deletions nix/go-mockery.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{ buildGoModule, fetchFromGitHub }:

buildGoModule rec {
pname = "go-mockery";
version = "1.1.2";

src = fetchFromGitHub {
owner = "vektra";
repo = "mockery";
rev = "v${version}";
sha256 = "16yqhr92n5s0svk31yy3k42764fas694mnqqcny633yi0wqb876a";
};

buildFlagsArray = ''
-ldflags=
-s -w -X github.com/vektra/mockery/mockery.SemVer=${version}
'';

modSha256 = "0wyzfmhk7plazadbi26rzq3w9cmvqz2dd5jsl6kamw53ps5yh536";
vendorSha256 = "0fai4hs3q822dg36a2zrxb191f71xdpafapn6ymi1w9dx68navcb";

subPackages = [ "cmd/mockery" ];
}
16 changes: 16 additions & 0 deletions nix/go-protobuf-json.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ buildGoModule, fetchFromGitHub }:

buildGoModule rec {
pname = "go-protobuf-json";
version = "069933b8c8344593ed8905d46d59c6647c886f47";

src = fetchFromGitHub {
owner = "mitchellh";
repo = "protoc-gen-go-json";
rev = "069933b8c8344593ed8905d46d59c6647c886f47";
sha256 = "1q5s2pfdxxzvdqghmbw3y2w5nl7wa4x15ngahfarjhahwqsbfsx4";
};

modSha256 = "01wrk2qhrh74nkv6davfifdz7jq6fcl3snn4w2g7vr8p0incdlcf";
vendorSha256 = "1hx31gr3l2f0nc8316c9ipmk1xx435g732msr5b344rcfcfrlaxh";
}
18 changes: 18 additions & 0 deletions nix/go-protobuf.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ buildGoModule, fetchFromGitHub }:

buildGoModule rec {
pname = "go-protobuf";
version = "1.5.2";

src = fetchFromGitHub {
owner = "golang";
repo = "protobuf";
rev = "v${version}";
sha256 = "1mh5fyim42dn821nsd3afnmgscrzzhn3h8rag635d2jnr23r1zhk";
};

modSha256 = "0lnk2zpl6y9vnq6h3l42ssghq6iqvmixd86g2drpa4z8xxk116wf";
vendorSha256 = "1qbndn7k0qqwxqk4ynkjrih7f7h56z1jq2yd62clhj95rca67hh9";

subPackages = [ "protoc-gen-go" ];
}
22 changes: 22 additions & 0 deletions nix/go-tools.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ buildGoModule, fetchFromGitHub }:

buildGoModule rec {
pname = "go-tools";
version = "35839b7038afa36a6c000733552daa1f5ce1e838";

src = fetchFromGitHub {
owner = "golang";
repo = "tools";
rev = "35839b7038afa36a6c000733552daa1f5ce1e838";
sha256 = "1gnqf62s7arqk807gadp4rd2diz1g0v2khwv9wsb50y8k9k4dfqs";
};

modSha256 = "1pijbkp7a9n2naicg21ydii6xc0g4jm5bw42lljwaks7211ag8k9";
vendorSha256 = "0i2fhaj2fd8ii4av1qx87wjkngip9vih8v3i9yr3h28hkq68zkm5";

subPackages = [ "cmd/stringer" ];

# This has to be enabled because the stringer tests recompile itself
# so it needs a valid reference to `go`
allowGoReference = true;
}
100 changes: 8 additions & 92 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
@@ -1,100 +1,16 @@
nixpkgs: final: prev: {
final: prev: {
# This is the pinned protoc version we have for this project.
protobufPin = prev.callPackage (
nixpkgs + "/pkgs/development/libraries/protobuf/generic-v3.nix"
) {
version = "3.15.8";
sha256 = "1q3k8axhq6g8fqczmd6kbgzpdplrrgygppym4x1l99lzhplx9rqv";
};
protobufPin = prev.protobuf3_15;

go-protobuf = prev.buildGoModule rec {
pname = "go-protobuf";
version = "v1.5.2";
devShell = final.callPackage ./waypoint.nix { };

src = prev.fetchFromGitHub {
owner = "golang";
repo = "protobuf";
rev = "v1.5.2";
sha256 = "1mh5fyim42dn821nsd3afnmgscrzzhn3h8rag635d2jnr23r1zhk";
};
go-protobuf = prev.callPackage ./go-protobuf.nix { };

modSha256 = "0lnk2zpl6y9vnq6h3l42ssghq6iqvmixd86g2drpa4z8xxk116wf";
vendorSha256 = "1qbndn7k0qqwxqk4ynkjrih7f7h56z1jq2yd62clhj95rca67hh9";
go-protobuf-json = prev.callPackage ./go-protobuf-json.nix { };

subPackages = [ "protoc-gen-go" ];
};
go-tools = prev.callPackage ./go-tools.nix { };

go-protobuf-json = prev.buildGoModule rec {
pname = "go-protobuf-json";
version = "069933b8c8344593ed8905d46d59c6647c886f47";
go-mockery = prev.callPackage ./go-mockery.nix { };

src = prev.fetchFromGitHub {
owner = "mitchellh";
repo = "protoc-gen-go-json";
rev = "069933b8c8344593ed8905d46d59c6647c886f47";
sha256 = "1q5s2pfdxxzvdqghmbw3y2w5nl7wa4x15ngahfarjhahwqsbfsx4";
};

modSha256 = "01wrk2qhrh74nkv6davfifdz7jq6fcl3snn4w2g7vr8p0incdlcf";
vendorSha256 = "1hx31gr3l2f0nc8316c9ipmk1xx435g732msr5b344rcfcfrlaxh";
};

go-tools = prev.buildGoModule rec {
pname = "go-tools";
version = "35839b7038afa36a6c000733552daa1f5ce1e838";

src = prev.fetchFromGitHub {
owner = "golang";
repo = "tools";
rev = "35839b7038afa36a6c000733552daa1f5ce1e838";
sha256 = "1gnqf62s7arqk807gadp4rd2diz1g0v2khwv9wsb50y8k9k4dfqs";
};

modSha256 = "1pijbkp7a9n2naicg21ydii6xc0g4jm5bw42lljwaks7211ag8k9";
vendorSha256 = "0i2fhaj2fd8ii4av1qx87wjkngip9vih8v3i9yr3h28hkq68zkm5";

subPackages = [ "cmd/stringer" ];

# This has to be enabled because the stringer tests recompile itself
# so it needs a valid reference to `go`
allowGoReference = true;
};

go-mockery = prev.buildGoModule rec {
pname = "go-mockery";
version = "1.1.2";

src = prev.fetchFromGitHub {
owner = "vektra";
repo = "mockery";
rev = "v${version}";
sha256 = "16yqhr92n5s0svk31yy3k42764fas694mnqqcny633yi0wqb876a";
};

buildFlagsArray = ''
-ldflags=
-s -w -X github.com/vektra/mockery/mockery.SemVer=${version}
'';

modSha256 = "0wyzfmhk7plazadbi26rzq3w9cmvqz2dd5jsl6kamw53ps5yh536";
vendorSha256 = "0fai4hs3q822dg36a2zrxb191f71xdpafapn6ymi1w9dx68navcb";

subPackages = [ "cmd/mockery" ];
};

go-changelog = prev.buildGoModule rec {
pname = "go-changelog";
version = "56335215ce3a8676ba7153be7c444daadcb132c7";

src = prev.fetchFromGitHub {
owner = "hashicorp";
repo = "go-changelog";
rev = "56335215ce3a8676ba7153be7c444daadcb132c7";
sha256 = "0z6ysz4x1rim09g9knbc5x5mrasfk6mzsi0h7jn8q4i035y1gg2j";
};

vendorSha256 = "1pahh64ayr885kv9rd5i4vh4a6hi1w583wch9n1ncvnckznzsdbg";

subPackages = [ "cmd/changelog-build" ];
};
go-changelog = prev.callPackage ./go-changelog.nix { };
}
116 changes: 75 additions & 41 deletions nix/waypoint.nix
Original file line number Diff line number Diff line change
@@ -1,47 +1,81 @@
{ pkgs }: {
shell = pkgs.mkShell rec {
name = "waypoint";
{ lib
, stdenv
, autoconf
, autogen
, automake
, docker-compose
, doctl
, go
, go-bindata
, go-changelog
, go-mockery
, go-protobuf
, go-protobuf-json
, go-tools
, grpcurl
, kubectl
, libpng
, libtool
, minikube
, mkShell
, nasm
, nodejs-16_x
, pkg-config
, postgresql_12
, protobufPin
, protoc-gen-doc
, zlib
}:

buildInputs = [
pkgs.docker-compose
pkgs.go
pkgs.go-bindata
pkgs.grpcurl
pkgs.nodejs-16_x
pkgs.postgresql_12
pkgs.protoc-gen-doc
mkShell rec {
name = "waypoint";

# Custom packages
pkgs.protobufPin
pkgs.go-protobuf
pkgs.go-protobuf-json
pkgs.go-tools
pkgs.go-mockery
pkgs.go-changelog
packages = [
docker-compose
go
go-bindata
grpcurl
nodejs-16_x
postgresql_12
protoc-gen-doc

# For testing
pkgs.doctl
pkgs.kubectl
] ++ (with pkgs; [
# Needed for website/
pkgconfig autoconf automake libtool nasm autogen zlib libpng
]) ++ (if pkgs.stdenv.isLinux then [
# On Linux we use minikube as the primary k8s testing platform
pkgs.minikube
] else []);
# Custom packages, added to overlay
protobufPin
go-protobuf
go-protobuf-json
go-tools
go-mockery
go-changelog

# workaround for npm/gulp dep compilation
# https://github.com/imagemin/optipng-bin/issues/108
shellHook = ''
LD=$CC
'';
# For testing
doctl
kubectl

# Extra env vars
PGHOST = "localhost";
PGPORT = "5432";
PGDATABASE = "noop";
PGUSER = "postgres";
PGPASSWORD = "postgres";
DATABASE_URL = "postgresql://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}?sslmode=disable";
};
# Needed for website/
autoconf
autogen
automake
libpng
libtool
nasm
pkg-config
zlib
] ++ lib.optionals stdenv.isLinux [
# On Linux we use minikube as the primary k8s testing platform
minikube
];

# workaround for npm/gulp dep compilation
# https://github.com/imagemin/optipng-bin/issues/108
shellHook = ''
LD=$CC
'';

# Extra env vars
PGHOST = "localhost";
PGPORT = "5432";
PGDATABASE = "noop";
PGUSER = "postgres";
PGPASSWORD = "postgres";
DATABASE_URL = "postgresql://${PGUSER}:${PGPASSWORD}@${PGHOST}:${PGPORT}/${PGDATABASE}?sslmode=disable";
}

0 comments on commit edabcd5

Please sign in to comment.