From edabcd59ff2b8f1cfdc5bf4424cec5ed72850f73 Mon Sep 17 00:00:00 2001 From: Jonathan Ringer Date: Thu, 21 Oct 2021 15:44:17 -0700 Subject: [PATCH] Refactor flake and overlay - 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 --- flake.nix | 24 ++++---- nix/go-changelog.nix | 17 ++++++ nix/go-mockery.nix | 23 ++++++++ nix/go-protobuf-json.nix | 16 ++++++ nix/go-protobuf.nix | 18 ++++++ nix/go-tools.nix | 22 ++++++++ nix/overlay.nix | 100 +++------------------------------ nix/waypoint.nix | 116 +++++++++++++++++++++++++-------------- 8 files changed, 191 insertions(+), 145 deletions(-) create mode 100644 nix/go-changelog.nix create mode 100644 nix/go-mockery.nix create mode 100644 nix/go-protobuf-json.nix create mode 100644 nix/go-protobuf.nix create mode 100644 nix/go-tools.nix diff --git a/flake.nix b/flake.nix index 446bed689cd..0fa2475a6e3 100644 --- a/flake.nix +++ b/flake.nix @@ -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; + }; } diff --git a/nix/go-changelog.nix b/nix/go-changelog.nix new file mode 100644 index 00000000000..a1b7bfdb796 --- /dev/null +++ b/nix/go-changelog.nix @@ -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" ]; +} diff --git a/nix/go-mockery.nix b/nix/go-mockery.nix new file mode 100644 index 00000000000..c408aa7e3d1 --- /dev/null +++ b/nix/go-mockery.nix @@ -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" ]; +} diff --git a/nix/go-protobuf-json.nix b/nix/go-protobuf-json.nix new file mode 100644 index 00000000000..5bb02918ad3 --- /dev/null +++ b/nix/go-protobuf-json.nix @@ -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"; +} diff --git a/nix/go-protobuf.nix b/nix/go-protobuf.nix new file mode 100644 index 00000000000..6ddcbf34574 --- /dev/null +++ b/nix/go-protobuf.nix @@ -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" ]; +} diff --git a/nix/go-tools.nix b/nix/go-tools.nix new file mode 100644 index 00000000000..fa1c3dc589a --- /dev/null +++ b/nix/go-tools.nix @@ -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; +} diff --git a/nix/overlay.nix b/nix/overlay.nix index 256e52c4923..3c672037431 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -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 { }; } diff --git a/nix/waypoint.nix b/nix/waypoint.nix index d57a02103c0..102a50dd2ef 100644 --- a/nix/waypoint.nix +++ b/nix/waypoint.nix @@ -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"; }