about summary refs log tree commit diff
path: root/nixpkgs/pkgs/servers/etcd
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/servers/etcd')
-rw-r--r--nixpkgs/pkgs/servers/etcd/3.4.nix34
-rw-r--r--nixpkgs/pkgs/servers/etcd/3.5/default.nix86
-rwxr-xr-xnixpkgs/pkgs/servers/etcd/3.5/update.sh68
3 files changed, 188 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/servers/etcd/3.4.nix b/nixpkgs/pkgs/servers/etcd/3.4.nix
new file mode 100644
index 000000000000..597cad35021b
--- /dev/null
+++ b/nixpkgs/pkgs/servers/etcd/3.4.nix
@@ -0,0 +1,34 @@
+{ lib, buildGoModule, fetchFromGitHub }:
+
+buildGoModule rec {
+  pname = "etcd";
+  version = "3.4.28";
+
+  src = fetchFromGitHub {
+    owner = "etcd-io";
+    repo = "etcd";
+    rev = "v${version}";
+    hash = "sha256-M0iD05Wk3pC56kGKeIb0bfMUpy9idMKin0+DYhBo/cw=";
+  };
+
+  vendorHash = "sha256-DbDIz/cbXqYHaGqNqP+wYpuiaFiZYElRXmQwBXnCbMk=";
+
+  buildPhase = ''
+    patchShebangs .
+    ./build
+    ./functional/build
+  '';
+
+  doCheck = false;
+
+  installPhase = ''
+    install -Dm755 bin/* bin/functional/cmd/* -t $out/bin
+  '';
+
+  meta = with lib; {
+    description = "Distributed reliable key-value store for the most critical data of a distributed system";
+    license = licenses.asl20;
+    homepage = "https://etcd.io/";
+    maintainers = with maintainers; [ offline ];
+  };
+}
diff --git a/nixpkgs/pkgs/servers/etcd/3.5/default.nix b/nixpkgs/pkgs/servers/etcd/3.5/default.nix
new file mode 100644
index 000000000000..43f47aa0eaa1
--- /dev/null
+++ b/nixpkgs/pkgs/servers/etcd/3.5/default.nix
@@ -0,0 +1,86 @@
+{ lib, buildGoModule, fetchFromGitHub, symlinkJoin, nixosTests, k3s }:
+
+let
+  version = "3.5.12";
+  etcdSrcHash = "sha256-Z2WXNzFJYfRQCldUspQjUR5NyUzCCINycuEXWaTn4vU=";
+  etcdServerVendorHash = "sha256-S5cEIV4hKRjn9JFEKWBiSEPytHtVacsSnG6T8dofgyk=";
+  etcdUtlVendorHash = "sha256-Vgp44Kg6zUDYVJU6SiYd8ZEcAWqKPPTsqYafcfk89Cc=";
+  etcdCtlVendorHash = "sha256-PZLsekZzwlGzccCirNk9uUj70Ue5LMDs6LMWBI9yivs=";
+
+  src = fetchFromGitHub {
+    owner = "etcd-io";
+    repo = "etcd";
+    rev = "v${version}";
+    hash = etcdSrcHash;
+  };
+
+  CGO_ENABLED = 0;
+
+  meta = with lib; {
+    description = "Distributed reliable key-value store for the most critical data of a distributed system";
+    license = licenses.asl20;
+    homepage = "https://etcd.io/";
+    maintainers = with maintainers; [ endocrimes offline superherointj ];
+    platforms = platforms.darwin ++ platforms.linux;
+  };
+
+  etcdserver = buildGoModule rec {
+    pname = "etcdserver";
+
+    inherit CGO_ENABLED meta src version;
+
+    vendorHash = etcdServerVendorHash;
+
+    modRoot = "./server";
+
+    preInstall = ''
+      mv $GOPATH/bin/{server,etcd}
+    '';
+
+    # We set the GitSHA to `GitNotFound` to match official build scripts when
+    # git is unavailable. This is to avoid doing a full Git Checkout of etcd.
+    # User facing version numbers are still available in the binary, just not
+    # the sha it was built from.
+    ldflags = [ "-X go.etcd.io/etcd/api/v3/version.GitSHA=GitNotFound" ];
+  };
+
+  etcdutl = buildGoModule rec {
+    pname = "etcdutl";
+
+    inherit CGO_ENABLED meta src version;
+
+    vendorHash = etcdUtlVendorHash;
+
+    modRoot = "./etcdutl";
+  };
+
+  etcdctl = buildGoModule rec {
+    pname = "etcdctl";
+
+    inherit CGO_ENABLED meta src version;
+
+    vendorHash = etcdCtlVendorHash;
+
+    modRoot = "./etcdctl";
+  };
+in
+symlinkJoin {
+  name = "etcd-${version}";
+
+  inherit meta version;
+
+  passthru = {
+    inherit etcdserver etcdutl etcdctl;
+    tests = {
+      inherit (nixosTests) etcd etcd-cluster;
+      k3s = k3s.passthru.tests.etcd;
+    };
+    updateScript = ./update.sh;
+  };
+
+  paths = [
+    etcdserver
+    etcdutl
+    etcdctl
+  ];
+}
diff --git a/nixpkgs/pkgs/servers/etcd/3.5/update.sh b/nixpkgs/pkgs/servers/etcd/3.5/update.sh
new file mode 100755
index 000000000000..329161188e39
--- /dev/null
+++ b/nixpkgs/pkgs/servers/etcd/3.5/update.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env nix-shell
+#!nix-shell -i bash -p curl gnugrep gnused jq nix-prefetch
+
+set -x -eu -o pipefail
+
+ETCD_VERSION_MAJOR_MINOR=`basename "$PWD"`
+
+ETCD_PKG_NAME=etcd_$(echo $ETCD_VERSION_MAJOR_MINOR | sed 's/[.]/_/g')
+NIXPKGS_PATH="$(git rev-parse --show-toplevel)"
+ETCD_PATH="$(dirname "$0")"
+
+OLD_VERSION="$(nix-instantiate --eval -E "with import $NIXPKGS_PATH {}; \
+    $ETCD_PKG_NAME.version or (builtins.parseDrvName $ETCD_PKG_NAME.name).version" | tr -d '"')"
+
+LATEST_TAG=$(curl ${GITHUB_TOKEN:+" -u \":$GITHUB_TOKEN\""} --silent https://api.github.com/repos/etcd-io/etcd/releases \
+    | jq -r 'map(.tag_name)' | grep $ETCD_VERSION_MAJOR_MINOR | sed 's|[", ]||g' | sort -rV | head -n1)
+
+LATEST_VERSION=$(echo ${LATEST_TAG} | sed 's/^v//')
+
+if [ ! "$OLD_VERSION" = "$LATEST_VERSION" ]; then
+    echo "Attempting to update etcd from $OLD_VERSION to $LATEST_VERSION"
+    ETCD_SRC_HASH=$(nix-prefetch-url --quiet --unpack https://github.com/etcd-io/etcd/archive/refs/tags/${LATEST_TAG}.tar.gz)
+    ETCD_SRC_HASH=$(nix hash to-sri --type sha256 $ETCD_SRC_HASH)
+
+    setKV () {
+        sed -i "s|$1 = \".*\"|$1 = \"${2:-}\"|" "$ETCD_PATH/default.nix"
+    }
+
+    setKV version $LATEST_VERSION
+    setKV etcdSrcHash $ETCD_SRC_HASH
+
+    getAndSetVendorHash () {
+        local EMPTY_HASH="sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=" # Hash from lib.fakeHash
+        local VENDOR_HASH=$EMPTY_HASH
+        local PKG_KEY=$1
+        local INNER_PKG=$2
+
+        setKV $PKG_KEY $EMPTY_HASH
+
+        set +e
+        VENDOR_HASH=$(nix-prefetch -I nixpkgs=$NIXPKGS_PATH "{ sha256 }: \
+            (import $NIXPKGS_PATH/. {}).$ETCD_PKG_NAME.passthru.$INNER_PKG.goModules.overrideAttrs (_: { vendorHash = sha256; })")
+        set -e
+
+        if [ -n "${VENDOR_HASH:-}" ]; then
+            setKV $PKG_KEY $VENDOR_HASH
+        else
+            echo "Update failed. $PKG_KEY is empty."
+            exit 1
+        fi
+    }
+
+    getAndSetVendorHash etcdServerVendorHash etcdserver
+    getAndSetVendorHash etcdUtlVendorHash etcdutl
+    getAndSetVendorHash etcdCtlVendorHash etcdctl
+
+    # `git` flag here is to be used by local maintainers to speed up the bump process
+    if [ $# -eq 1 ] && [ "$1" = "git" ]; then
+        git switch -c "package-$ETCD_PKG_NAME-$LATEST_VERSION"
+        git add "$ETCD_PATH"/default.nix
+        git commit -m "$ETCD_PKG_NAME: $OLD_VERSION -> $LATEST_VERSION
+
+Release: https://github.com/etcd-io/etcd/releases/tag/v$LATEST_VERSION"
+    fi
+
+else
+    echo "etcd is already up-to-date at $OLD_VERSION"
+fi