From 779ab65e984326152244b3b281060e8f450d139f Mon Sep 17 00:00:00 2001 From: zimbatm Date: Mon, 19 Feb 2024 12:24:16 +0100 Subject: [PATCH] vouch: remove duplication If we want to maintain multiple versions of packages, how do we reduce the duplication of definitions? --- pkgs/vouch/builder.nix | 43 +++++++++++++++++++++++++++++++++++++++++ pkgs/vouch/default.nix | 39 ++++++++++++++----------------------- pkgs/vouch/unstable.nix | 39 ++++++++++++++----------------------- 3 files changed, 71 insertions(+), 50 deletions(-) create mode 100644 pkgs/vouch/builder.nix diff --git a/pkgs/vouch/builder.nix b/pkgs/vouch/builder.nix new file mode 100644 index 00000000..3c8ddb9e --- /dev/null +++ b/pkgs/vouch/builder.nix @@ -0,0 +1,43 @@ +{ + buildGoModule, + mcl, + bls, +}: let + builder = { + version, + src, + vendorHash, + }: overrides: let + originalAttrs = { + inherit version src vendorHash; + + pname = "vouch"; + + runVend = true; + + buildInputs = [mcl bls]; + + doCheck = false; + + meta = { + description = "An Ethereum 2 multi-node validator client"; + homepage = "https://github.com/attestantio/vouch"; + mainProgram = "vouch"; + platforms = ["x86_64-linux"]; + }; + + passthru.mkPackage = builder; + }; + + overridesType = builtins.typeOf overrides; + + buildAttrs = + if overridesType == "set" + then originalAttrs // overrides + else if overridesType == "lambda" + then originalAttrs // (overrides originalAttrs) + else throw "unsupported type '${overridesType}' for the overrides"; + in + buildGoModule buildAttrs; +in + builder diff --git a/pkgs/vouch/default.nix b/pkgs/vouch/default.nix index cbbbefef..e53f3241 100644 --- a/pkgs/vouch/default.nix +++ b/pkgs/vouch/default.nix @@ -1,31 +1,20 @@ { - buildGoModule, + callPackage, fetchFromGitHub, mcl, bls, -}: -buildGoModule rec { - pname = "vouch"; - version = "1.7.6"; +}: let + mkVouch = callPackage ./builder.nix {inherit mcl bls;}; +in + mkVouch rec { + version = "1.7.6"; - src = fetchFromGitHub { - owner = "attestantio"; - repo = pname; - rev = "v${version}"; - hash = "sha256-zno/8uUkejS0zqOijGZdzknafavbvCU72uj/44on1f8="; - }; + src = fetchFromGitHub { + owner = "attestantio"; + repo = "vouch"; + rev = "v${version}"; + hash = "sha256-zno/8uUkejS0zqOijGZdzknafavbvCU72uj/44on1f8="; + }; - runVend = true; - vendorHash = "sha256-zNHLg/nIKvIbMZtyDANxEQ04dygFHxwrM3JJkD1zcjo="; - - buildInputs = [mcl bls]; - - doCheck = false; - - meta = { - description = "An Ethereum 2 multi-node validator client"; - homepage = "https://github.com/attestantio/vouch"; - mainProgram = "vouch"; - platforms = ["x86_64-linux"]; - }; -} + vendorHash = "sha256-zNHLg/nIKvIbMZtyDANxEQ04dygFHxwrM3JJkD1zcjo="; + } {} diff --git a/pkgs/vouch/unstable.nix b/pkgs/vouch/unstable.nix index b987b780..57f7db2d 100644 --- a/pkgs/vouch/unstable.nix +++ b/pkgs/vouch/unstable.nix @@ -1,31 +1,20 @@ { - buildGoModule, + callPackage, fetchFromGitHub, mcl, bls, -}: -buildGoModule rec { - pname = "vouch"; - version = "1.8.0-beta.3"; +}: let + mkVouch = callPackage ./builder.nix {inherit mcl bls;}; +in + mkVouch rec { + version = "1.8.0-beta.3"; - src = fetchFromGitHub { - owner = "attestantio"; - repo = pname; - rev = "v${version}"; - hash = "sha256-CK6cLXJYMQL+ZRv8bYabgQ0GeDWK8Jcek6d/Wow2LI0="; - }; + src = fetchFromGitHub { + owner = "attestantio"; + repo = "vouch"; + rev = "v${version}"; + hash = "sha256-CK6cLXJYMQL+ZRv8bYabgQ0GeDWK8Jcek6d/Wow2LI0="; + }; - runVend = true; - vendorHash = "sha256-Mp+RA2L4mOe089ceyKh3m5Q8zLsdwyx6geMFrqbn5Dk="; - - buildInputs = [mcl bls]; - - doCheck = false; - - meta = { - description = "An Ethereum 2 multi-node validator client"; - homepage = "https://github.com/attestantio/vouch"; - mainProgram = "vouch"; - platforms = ["x86_64-linux"]; - }; -} + vendorHash = "sha256-Mp+RA2L4mOe089ceyKh3m5Q8zLsdwyx6geMFrqbn5Dk="; + } {}