From 6ac38abf29cc60f2e4c7b405692dfa0b03afe60d Mon Sep 17 00:00:00 2001 From: "Adam C. Stephens" Date: Mon, 31 Mar 2025 17:17:52 -0400 Subject: [PATCH 1/2] nixos/tests/envoy: migrate to runTests --- nixos/tests/all-tests.nix | 5 +- nixos/tests/envoy.nix | 108 +++++++++++++++++++------------------- 2 files changed, 57 insertions(+), 56 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 3fc31d6f5909..ac99791699b2 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -407,7 +407,10 @@ in enlightenment = handleTest ./enlightenment.nix { }; env = handleTest ./env.nix { }; envfs = handleTest ./envfs.nix { }; - envoy = handleTest ./envoy.nix { }; + envoy = runTest { + imports = [ ./envoy.nix ]; + _module.args.envoyPackage = pkgs.envoy; + }; ergo = handleTest ./ergo.nix { }; ergochat = handleTest ./ergochat.nix { }; eris-server = handleTest ./eris-server.nix { }; diff --git a/nixos/tests/envoy.nix b/nixos/tests/envoy.nix index d669b2bb718f..6cbf782a421f 100644 --- a/nixos/tests/envoy.nix +++ b/nixos/tests/envoy.nix @@ -1,62 +1,60 @@ -import ./make-test-python.nix ( - { pkgs, lib, ... }: - { - name = "envoy"; - meta = with pkgs.lib.maintainers; { - maintainers = [ cameronnemo ]; - }; +{ envoyPackage, lib, ... }: +{ + name = envoyPackage.pname; - nodes.machine = - { pkgs, ... }: - { - services.envoy.enable = true; - services.envoy.settings = { - admin = { - access_log_path = "/dev/null"; - address = { - socket_address = { - protocol = "TCP"; - address = "127.0.0.1"; - port_value = 80; - }; - }; + meta = with lib.maintainers; { + maintainers = [ cameronnemo ]; + }; + + nodes.machine = { + services.envoy.enable = true; + services.envoy.package = envoyPackage; + services.envoy.settings = { + admin = { + access_log_path = "/dev/null"; + address = { + socket_address = { + protocol = "TCP"; + address = "127.0.0.1"; + port_value = 80; }; - static_resources = { - listeners = [ ]; - clusters = [ ]; - }; - }; - specialisation = { - withoutConfigValidation.configuration = - { ... }: - { - services.envoy = { - requireValidConfig = false; - settings.admin.access_log_path = lib.mkForce "/var/log/envoy/access.log"; - }; - }; }; }; + static_resources = { + listeners = [ ]; + clusters = [ ]; + }; + }; + specialisation = { + withoutConfigValidation.configuration = + { ... }: + { + services.envoy = { + requireValidConfig = false; + settings.admin.access_log_path = lib.mkForce "/var/log/envoy/access.log"; + }; + }; + }; + }; - testScript = - { nodes, ... }: - let - specialisations = "${nodes.machine.system.build.toplevel}/specialisation"; - in - '' - machine.start() + testScript = + { nodes, ... }: + let + specialisations = "${nodes.machine.system.build.toplevel}/specialisation"; + in + '' + machine.start() - with subtest("envoy.service starts and responds with ready"): - machine.wait_for_unit("envoy.service") - machine.wait_for_open_port(80) - machine.wait_until_succeeds("curl -fsS localhost:80/ready") + with subtest("envoy.service starts and responds with ready"): + machine.wait_for_unit("envoy.service") + machine.wait_for_open_port(80) + machine.wait_until_succeeds("curl -fsS localhost:80/ready") - with subtest("envoy.service works with config path not available at eval time"): - machine.succeed('${specialisations}/withoutConfigValidation/bin/switch-to-configuration test') - machine.wait_for_unit("envoy.service") - machine.wait_for_open_port(80) - machine.wait_until_succeeds("curl -fsS localhost:80/ready") - machine.succeed('test -f /var/log/envoy/access.log') - ''; - } -) + with subtest("envoy.service works with config path not available at eval time"): + machine.succeed('${specialisations}/withoutConfigValidation/bin/switch-to-configuration test') + machine.wait_for_unit("envoy.service") + machine.wait_for_open_port(80) + machine.wait_until_succeeds("curl -fsS localhost:80/ready") + machine.succeed('test -f /var/log/envoy/access.log') + ''; +} From b2f768a31c56788a1a6a108e428b04fdad69cc07 Mon Sep 17 00:00:00 2001 From: "Adam C. Stephens" Date: Mon, 31 Mar 2025 17:17:52 -0400 Subject: [PATCH 2/2] envoy-bin: init at 1.33.2 --- nixos/tests/all-tests.nix | 4 ++ pkgs/by-name/en/envoy-bin/package.nix | 77 +++++++++++++++++++++++++++ pkgs/by-name/en/envoy-bin/update.sh | 32 +++++++++++ 3 files changed, 113 insertions(+) create mode 100644 pkgs/by-name/en/envoy-bin/package.nix create mode 100755 pkgs/by-name/en/envoy-bin/update.sh diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index ac99791699b2..ed86de0b19fb 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -411,6 +411,10 @@ in imports = [ ./envoy.nix ]; _module.args.envoyPackage = pkgs.envoy; }; + envoy-bin = runTest { + imports = [ ./envoy.nix ]; + _module.args.envoyPackage = pkgs.envoy-bin; + }; ergo = handleTest ./ergo.nix { }; ergochat = handleTest ./ergochat.nix { }; eris-server = handleTest ./eris-server.nix { }; diff --git a/pkgs/by-name/en/envoy-bin/package.nix b/pkgs/by-name/en/envoy-bin/package.nix new file mode 100644 index 000000000000..9379db80d7ad --- /dev/null +++ b/pkgs/by-name/en/envoy-bin/package.nix @@ -0,0 +1,77 @@ +{ + lib, + stdenv, + autoPatchelfHook, + fetchurl, + makeWrapper, + nixosTests, + versionCheckHook, +}: +let + version = "1.33.2"; + inherit (stdenv.hostPlatform) system; + throwSystem = throw "envoy-bin is not available for ${system}."; + + plat = + { + aarch64-linux = "aarch_64"; + x86_64-linux = "x86_64"; + } + .${system} or throwSystem; + + hash = + { + aarch64-linux = "sha256-gew2iaghIu/wymgMSBdvTTUbb5iBp5zJ2QeKb7Swtqg="; + x86_64-linux = "sha256-vS/4fF78lf14gNcQkV9XPBqrTZxV2NqIbc2R30P610E="; + } + .${system} or throwSystem; +in +stdenv.mkDerivation { + pname = "envoy-bin"; + inherit version; + + src = fetchurl { + url = "https://github.com/envoyproxy/envoy/releases/download/v${version}/envoy-${version}-linux-${plat}"; + inherit hash; + }; + + nativeBuildInputs = [ autoPatchelfHook ]; + buildInputs = [ makeWrapper ]; + + dontUnpack = true; + dontBuild = true; + + installPhase = '' + runHook preInstall + mkdir -p $out/bin + install -m755 $src $out/bin/envoy + runHook postInstall + ''; + + nativeInstallCheckInputs = [ versionCheckHook ]; + doInstallCheck = true; + versionCheckProgram = "${placeholder "out"}/bin/envoy"; + versionCheckProgramArg = "--version"; + + passthru = { + tests.envoy-bin = nixosTests.envoy-bin; + + updateScript = ./update.sh; + }; + + meta = { + homepage = "https://envoyproxy.io"; + changelog = "https://github.com/envoyproxy/envoy/releases/tag/v${version}"; + description = "Cloud-native edge and service proxy"; + license = lib.licenses.asl20; + sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; + maintainers = with lib.maintainers; [ + adamcstephens + ]; + mainProgram = "envoy"; + platforms = [ + "x86_64-linux" + "aarch64-linux" + ]; + }; +} diff --git a/pkgs/by-name/en/envoy-bin/update.sh b/pkgs/by-name/en/envoy-bin/update.sh new file mode 100755 index 000000000000..df32827256aa --- /dev/null +++ b/pkgs/by-name/en/envoy-bin/update.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p curl gnused gawk nix-prefetch common-updater-scripts jq + +set -euo pipefail + +ROOT="$(dirname "$(readlink -f "$0")")" +NIX_DRV="$ROOT/package.nix" +if [ ! -f "$NIX_DRV" ]; then + echo "ERROR: cannot find package.nix in $ROOT" + exit 1 +fi + +fetch_arch() { + VER="$1" + ARCH="$2" + URL="https://github.com/envoyproxy/envoy/releases/download/v${VER}/envoy-${VER}-linux-${ARCH}" + nix hash convert --to sri --hash-algo sha256 "$(nix-prefetch-url --type sha256 "$URL")" +} + +replace_hash() { + sed -i "s#$1 = \"sha256-.\{44\}\"#$1 = \"$2\"#" "$NIX_DRV" +} + +VER=$(list-git-tags --url=https://github.com/envoyproxy/envoy | rg 'v[0-9\.]*$' | sed -e 's/^v//' | sort -V | tail -n 1) + +LINUX_X64_HASH=$(fetch_arch "$VER" "x86_64") +LINUX_AARCH64_HASH=$(fetch_arch "$VER" "aarch_64") + +sed -i "s/version = \".*\"/version = \"$VER\"/" "$NIX_DRV" + +replace_hash "x86_64-linux" "$LINUX_X64_HASH" +replace_hash "aarch64-linux" "$LINUX_AARCH64_HASH"