From 90f823adcdabdd527127364ea62a0693934e67ba Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Wed, 7 Oct 2026 18:28:11 +0800 Subject: [PATCH] ci: verify Nix packages within the Build workflow --- .github/workflows/build.yaml | 116 ++++++++++++++++++++++- .github/workflows/nix.yaml | 176 ----------------------------------- flake.nix | 35 +++---- nix/ci.nix | 47 ++++++++++ nix/tests/native-runtime.nix | 11 +-- 5 files changed, 180 insertions(+), 205 deletions(-) delete mode 100644 .github/workflows/nix.yaml create mode 100644 nix/ci.nix diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3981b2f..868868e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -363,6 +363,118 @@ jobs: gpgui-source/*.bin.tar.xz gpgui-source/*.bin.tar.xz.sha256 + nix-source: + needs: [build-gpgui] + strategy: + fail-fast: false + matrix: + platform: + - runner: ubuntu-latest + system: x86_64-linux + artifact_arch: amd64 + - runner: ubuntu-24.04-arm + system: aarch64-linux + artifact_arch: ubuntu-24.04-arm + runs-on: ${{ matrix.platform.runner }} + name: nix-source (${{ matrix.platform.system }}) + env: + NIX_SYSTEM: ${{ matrix.platform.system }} + NIXPKGS: locked + steps: + - name: Checkout source and dependencies + uses: actions/checkout@v6 + with: + token: ${{ secrets.GH_PAT }} + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} + submodules: recursive + path: gp + - name: Download current GUI artifact + uses: actions/download-artifact@v8 + with: + name: artifact-gpgui-${{ matrix.platform.artifact_arch }} + path: nix-artifacts/gui + - name: Install Nix + uses: cachix/install-nix-action@v31 + - name: Configure current source and GUI inputs + run: | + echo "GP_SOURCE=$PWD/gp" >> "$GITHUB_ENV" + gui_archive=$(find "$PWD/nix-artifacts/gui" -name '*.bin.tar.xz' -type f) + test -f "$gui_archive" + echo "GP_GUI_ARCHIVE=$gui_archive" >> "$GITHUB_ENV" + - name: Build source package + run: | + nix build --impure --file gp/nix/ci.nix source \ + --extra-experimental-features "nix-command flakes" --print-build-logs + bash gp/scripts/tests/nix-desktop-authorization.sh result + - name: Test source runtime in NixOS + if: matrix.platform.system == 'x86_64-linux' + run: | + nix build --impure --file gp/nix/ci.nix runtime-source \ + --extra-experimental-features "nix-command flakes" --print-build-logs + + nix-prebuilt: + needs: [build-gp, build-gpgui] + strategy: + fail-fast: false + matrix: + platform: + - runner: ubuntu-latest + system: x86_64-linux + artifact_arch: amd64 + - runner: ubuntu-24.04-arm + system: aarch64-linux + artifact_arch: ubuntu-24.04-arm + nixpkgs: [locked, nixos-25.11, nixos-26.05, nixpkgs-unstable] + runs-on: ${{ matrix.platform.runner }} + name: nix-prebuilt (${{ matrix.platform.system }}, ${{ matrix.nixpkgs }}) + env: + NIX_SYSTEM: ${{ matrix.platform.system }} + NIXPKGS: ${{ matrix.nixpkgs }} + steps: + - name: Checkout packaging and tests + uses: actions/checkout@v6 + with: + token: ${{ secrets.GH_PAT }} + ref: ${{ github.event_name == 'workflow_dispatch' && inputs.gp_branch || github.ref }} + submodules: recursive + path: gp + - name: Download current Linux binary artifact + uses: actions/download-artifact@v8 + with: + name: artifact-gp-binary-${{ matrix.platform.artifact_arch }} + path: nix-artifacts/binaries + - name: Download current GUI artifact + uses: actions/download-artifact@v8 + with: + name: artifact-gpgui-${{ matrix.platform.artifact_arch }} + path: nix-artifacts/gui + - name: Install Nix + uses: cachix/install-nix-action@v31 + - name: Configure current artifact inputs + run: | + echo "GP_SOURCE=$PWD/gp" >> "$GITHUB_ENV" + binary_archive=$(find "$PWD/nix-artifacts/binaries" -name '*.bin.tar.xz' -type f) + gui_archive=$(find "$PWD/nix-artifacts/gui" -name '*.bin.tar.xz' -type f) + test -f "$binary_archive" + test -f "$gui_archive" + echo "GP_BINARY_ARCHIVE=$binary_archive" >> "$GITHUB_ENV" + echo "GP_GUI_ARCHIVE=$gui_archive" >> "$GITHUB_ENV" + - name: Build package through host NixOS module + run: | + nix build --impure --file gp/nix/ci.nix module \ + --extra-experimental-features "nix-command flakes" --print-build-logs + bash gp/scripts/tests/nix-desktop-authorization.sh result + - name: Build standalone prebuilt package + if: matrix.nixpkgs == 'locked' + run: | + nix build --impure --file gp/nix/ci.nix prebuilt \ + --extra-experimental-features "nix-command flakes" --print-build-logs + - name: Test prebuilt runtime in NixOS + if: matrix.nixpkgs == 'locked' && matrix.platform.system == 'x86_64-linux' + run: | + nix build --impure --file gp/nix/ci.nix runtime-prebuilt \ + --extra-experimental-features "nix-command flakes" --print-build-logs + trigger-gpgui-macos: if: ${{ startsWith(github.ref, 'refs/tags/') || (github.event_name == 'workflow_dispatch' && inputs.build_macos) }} permissions: @@ -689,6 +801,8 @@ jobs: attestations: write artifact-metadata: write needs: + - nix-source + - nix-prebuilt - tarball - tarball-offline - build-gp @@ -719,7 +833,7 @@ jobs: result = data["result"] if result in {"failure", "cancelled"}: failed.append(f"{name}: {result}") - elif name in {"build-gp", "build-docker-image"} and result == "skipped" and is_tag: + elif name in {"build-gp", "build-docker-image", "nix-prebuilt"} and result == "skipped" and is_tag: continue elif name in {"build-gpgui-frontend", "build-bsd"} and result == "skipped" and not bsd_matrix_enabled: continue diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml deleted file mode 100644 index 0da0578..0000000 --- a/.github/workflows/nix.yaml +++ /dev/null @@ -1,176 +0,0 @@ -name: Nix - -on: - workflow_dispatch: - pull_request: - paths: - - "flake.nix" - - "flake.lock" - - "nix/**" - - "scripts/tests/nix-desktop-authorization.sh" - - ".github/workflows/nix.yaml" - push: - branches: - - main - paths: - - "flake.nix" - - "flake.lock" - - "nix/**" - - "scripts/tests/nix-desktop-authorization.sh" - - ".github/workflows/nix.yaml" - -permissions: - contents: read - -jobs: - source-package: - name: source-package (${{ matrix.platform.system }}) - strategy: - fail-fast: false - matrix: - platform: - - runner: ubuntu-latest - system: x86_64-linux - - runner: ubuntu-24.04-arm - system: aarch64-linux - runs-on: ${{ matrix.platform.runner }} - steps: - - name: Checkout source and dependencies - uses: actions/checkout@v6 - with: - submodules: recursive - - - name: Install Nix - uses: cachix/install-nix-action@v31 - - - name: Build current source package - run: | - nix build "git+file://$PWD?submodules=1#fromSource" \ - --extra-experimental-features "nix-command flakes" \ - --print-build-logs - - - name: Inspect source package - run: | - test -x result/bin/gpclient - test -x result/bin/gpauth - test -x result/bin/gpservice - test -x result/libexec/gpclient/gp-hip-script-installer - test ! -e result/libexec/gpclient/gp-hip-runner - test ! -e result/libexec/gpclient/hipreport.sh - - standalone-package: - name: standalone-package (${{ matrix.platform.system }}) - strategy: - fail-fast: false - matrix: - platform: - - runner: ubuntu-latest - system: x86_64-linux - - runner: ubuntu-24.04-arm - system: aarch64-linux - runs-on: ${{ matrix.platform.runner }} - steps: - - name: Checkout GlobalProtect-openconnect - uses: actions/checkout@v6 - - - name: Install Nix - uses: cachix/install-nix-action@v31 - - - name: Build standalone prebuilt package - run: | - nix build .#prebuilt \ - --extra-experimental-features "nix-command flakes" \ - --print-build-logs - - - name: Inspect prebuilt package - run: | - test -x result/bin/gpclient - test -x result/bin/gpauth - test -x result/bin/gpservice - test -x result/bin/gpgui-helper - test -x result/bin/gpgui - - - name: Verify desktop authorization runs on the host - run: bash scripts/tests/nix-desktop-authorization.sh result - - native-runtime: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - package: [prebuilt, source] - steps: - - uses: actions/checkout@v6 - with: - submodules: recursive - - uses: cachix/install-nix-action@v31 - - name: Test native runtime in NixOS - run: | - nix build "git+file://$PWD?submodules=1#checks.x86_64-linux.native-runtime-${{ matrix.package }}" \ - --extra-experimental-features "nix-command flakes" \ - --print-build-logs - - nixos-module: - name: nixos-module (${{ matrix.platform.system }}, ${{ matrix.nixpkgs }}) - strategy: - fail-fast: false - matrix: - platform: - - runner: ubuntu-latest - system: x86_64-linux - - runner: ubuntu-24.04-arm - system: aarch64-linux - nixpkgs: - - nixos-25.11 - - nixos-26.05 - - nixpkgs-unstable - runs-on: ${{ matrix.platform.runner }} - steps: - - name: Checkout GlobalProtect-openconnect - uses: actions/checkout@v6 - - - name: Install Nix - uses: cachix/install-nix-action@v31 - - - name: Build package through host NixOS module - env: - NIXPKGS_URL: github:NixOS/nixpkgs/${{ matrix.nixpkgs }} - NIX_SYSTEM: ${{ matrix.platform.system }} - run: | - nix build \ - --impure \ - --extra-experimental-features "nix-command flakes" \ - --print-build-logs \ - --expr ' - let - gp = builtins.getFlake (toString ./.); - hostNixpkgs = - builtins.getFlake (builtins.getEnv "NIXPKGS_URL"); - - hostSystem = hostNixpkgs.lib.nixosSystem { - system = builtins.getEnv "NIX_SYSTEM"; - modules = [ - gp.nixosModules.default - { - programs.globalprotect-openconnect.enable = true; - system.stateVersion = "25.11"; - } - ]; - }; - - package = - hostSystem.config.programs.globalprotect-openconnect.package; - in - assert builtins.elem package - hostSystem.config.environment.systemPackages; - assert hostSystem.config.services.ayatana-indicators.enable; - package - ' - - - name: Inspect module package - run: | - test -x result/bin/gpclient - test -x result/bin/gpauth - test -x result/bin/gpservice - test -x result/bin/gpgui-helper - test -x result/bin/gpgui diff --git a/flake.nix b/flake.nix index 3ab62a6..fabc7b1 100644 --- a/flake.nix +++ b/flake.nix @@ -96,14 +96,14 @@ gappsWrapperArgs+=( --prefix PATH : "/run/wrappers/bin:${lib.makeBinPath runtimeTools}" --set GP_COMMAND_PATH "${lib.makeBinPath runtimeTools}" - --set GP_VPNC_SCRIPT "$out/libexec/gpclient/vpnc-script" - --set GP_CLIENT_BINARY "$out/bin/gpclient" - --set GP_SERVICE_BINARY "$out/bin/gpservice" - --set GP_AUTH_BINARY "$out/bin/gpauth" - --set GP_GUI_BINARY "$out/bin/gpgui" - --set GP_GUI_HELPER_BINARY "$out/bin/gpgui-helper" - --set GP_VPNC_SCRIPT_INSTALLER_BINARY "$out/libexec/gpclient/gp-vpnc-script-installer" - --set GP_HIP_SCRIPT_INSTALLER_BINARY "$out/libexec/gpclient/gp-hip-script-installer" + --set-default GP_VPNC_SCRIPT "$out/libexec/gpclient/vpnc-script" + --set-default GP_CLIENT_BINARY "$out/bin/gpclient" + --set-default GP_SERVICE_BINARY "$out/bin/gpservice" + --set-default GP_AUTH_BINARY "$out/bin/gpauth" + --set-default GP_GUI_BINARY "$out/bin/gpgui" + --set-default GP_GUI_HELPER_BINARY "$out/bin/gpgui-helper" + --set-default GP_VPNC_SCRIPT_INSTALLER_BINARY "$out/libexec/gpclient/gp-vpnc-script-installer" + --set-default GP_HIP_SCRIPT_INSTALLER_BINARY "$out/libexec/gpclient/gp-hip-script-installer" ) ''; @@ -170,7 +170,7 @@ EOF ''; - fromSource = naersk'.buildPackage { + fromSource = lib.makeOverridable ({ gui ? gpgui }: naersk'.buildPackage { inherit pname version; src = assert lib.assertMsg (builtins.pathExists (src + "/crates/openconnect/deps/openconnect/configure.ac") @@ -243,7 +243,7 @@ done # Copy the prebuilt gpgui binary to the output bin directory - cp ${gpgui}/gpgui $out/bin/gpgui + cp ${gui}/gpgui $out/bin/gpgui chmod +x $out/bin/gpgui cp -r packaging/files/usr/share $out/share @@ -255,13 +255,13 @@ ${rewriteVpncScriptToolPaths} ${rewriteSourceInstallPaths} ''; - }; + }) {}; - prebuilt = pkgs.stdenv.mkDerivation { + prebuilt = lib.makeOverridable ({ binaries ? binaryPackage, gui ? gpgui }: pkgs.stdenv.mkDerivation { inherit pname; version = releaseVersion; - src = binaryPackage; + src = binaries; dontBuild = true; nativeBuildInputs = with pkgs; [ @@ -285,7 +285,7 @@ cp -r artifacts/usr/lib $out/lib fi - install -Dm755 ${gpgui}/gpgui $out/bin/gpgui + install -Dm755 ${gui}/gpgui $out/bin/gpgui ${rewriteVpncScriptToolPaths} ${rewriteSourceInstallPaths} @@ -293,7 +293,7 @@ runHook postInstall ''; - }; + }) {}; in { @@ -352,11 +352,6 @@ default = fromSource; }; - checks = lib.optionalAttrs (system == "x86_64-linux") { - native-runtime-prebuilt = import ./nix/tests/native-runtime.nix { inherit pkgs; package = prebuilt; }; - native-runtime-source = import ./nix/tests/native-runtime.nix { inherit pkgs; package = fromSource; }; - }; - apps.default = { type = "app"; program = "${self.packages.${system}.default}/bin/gpclient"; diff --git a/nix/ci.nix b/nix/ci.nix new file mode 100644 index 0000000..756e15b --- /dev/null +++ b/nix/ci.nix @@ -0,0 +1,47 @@ +let + source = builtins.getEnv "GP_SOURCE"; + system = builtins.getEnv "NIX_SYSTEM"; + nixpkgsRef = builtins.getEnv "NIXPKGS"; + gp = builtins.getFlake ("git+file://" + source + "?submodules=1"); + nixpkgs = if nixpkgsRef == "locked" then gp.inputs.nixpkgs + else builtins.getFlake ("github:NixOS/nixpkgs/" + nixpkgsRef); + pkgs = import nixpkgs { inherit system; }; + unpack = name: variable: + let + archive = builtins.path { + path = builtins.toPath (builtins.getEnv variable); + inherit name; + }; + in pkgs.runCommand name { nativeBuildInputs = [ pkgs.libarchive ]; } '' + mkdir -p "$out" + bsdtar --extract --file ${archive} --directory "$out" --strip-components 1 + ''; + binaries = unpack "gp-ci-binaries" "GP_BINARY_ARCHIVE"; + gui = unpack "gp-ci-gui" "GP_GUI_ARCHIVE"; + sourcePackage = gp.packages.${system}.fromSource.override { inherit gui; }; + prebuiltPackage = gp.packages.${system}.prebuilt.override { inherit binaries gui; }; + hostSystem = nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + gp.nixosModules.default + ({ options, ... }: { + programs.globalprotect-openconnect = { + enable = true; + package = options.programs.globalprotect-openconnect.package.default.override { + inherit binaries gui; + }; + }; + system.stateVersion = "25.11"; + }) + ]; + }; + modulePackage = hostSystem.config.programs.globalprotect-openconnect.package; +in { + source = sourcePackage; + prebuilt = prebuiltPackage; + module = assert builtins.elem modulePackage hostSystem.config.environment.systemPackages; + assert hostSystem.config.services.ayatana-indicators.enable; + modulePackage; + runtime-source = import ./tests/native-runtime.nix { inherit pkgs; package = sourcePackage; }; + runtime-prebuilt = import ./tests/native-runtime.nix { inherit pkgs; package = prebuiltPackage; }; +} diff --git a/nix/tests/native-runtime.nix b/nix/tests/native-runtime.nix index 9ed8bc5..3513012 100644 --- a/nix/tests/native-runtime.nix +++ b/nix/tests/native-runtime.nix @@ -25,11 +25,6 @@ let pathlib.Path("/tmp/gp-gui-ready").write_text(str(os.getpid())) sys.stdin.buffer.read() ''; - testPackage = package.overrideAttrs (old: { - postInstall = (old.postInstall or "") + '' - install -m755 ${guiProbe} $out/bin/gpgui - ''; - }); hostCollector = pkgs.writeShellScriptBin "clamscan" '' echo 'ClamAV 1.4.0/27123/Mon Oct 7 00:00:00 2026' ''; @@ -37,7 +32,7 @@ in pkgs.testers.runNixOSTest { name = "gp-native-runtime-${package.pname}"; nodes.machine = { - environment.systemPackages = [ testPackage hostCollector ]; + environment.systemPackages = [ package hostCollector ]; users.users.alice = { isNormalUser = true; uid = 1000; }; security.polkit.enable = true; security.polkit.extraConfig = '' @@ -58,13 +53,13 @@ pkgs.testers.runNixOSTest { machine.start() machine.wait_for_unit("polkit.service") - package = "${testPackage}" + package = "${package}" def as_alice(command): return machine.succeed("su - alice -c " + shlex.quote(command)) # Exercise real host pkexec, private credential pipes and launcher cancellation. - command = package + "/bin/gpclient --lock-file /tmp/gp-client.lock launch-gui" + command = "GP_GUI_BINARY=${guiProbe} " + package + "/bin/gpclient --lock-file /tmp/gp-client.lock launch-gui" as_alice(command + " > /tmp/gp-client-output 2>&1 & echo $! > /tmp/gp-client-pid") machine.wait_until_succeeds("test -s /tmp/gp-gui-ready") service_pid = machine.succeed("cut -d: -f1 /var/run/gpservice.lock").strip()