diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml new file mode 100644 index 0000000..06d28b6 --- /dev/null +++ b/.github/workflows/nix.yaml @@ -0,0 +1,118 @@ +name: Nix + +on: + pull_request: + paths: + - "flake.nix" + - "flake.lock" + - "nix/**" + - ".github/workflows/nix.yaml" + push: + branches: + - main + paths: + - "flake.nix" + - "flake.lock" + - "nix/**" + - ".github/workflows/nix.yaml" + +permissions: + contents: read + +jobs: + 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 + + 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/.github/workflows/update-flake-hashes.yaml b/.github/workflows/update-flake-hashes.yaml index c76d68a..ad6c1d0 100644 --- a/.github/workflows/update-flake-hashes.yaml +++ b/.github/workflows/update-flake-hashes.yaml @@ -55,21 +55,17 @@ jobs: strategy: fail-fast: false matrix: - include: - - runner: ubuntu-latest + runner: + - ubuntu-latest + - ubuntu-24.04-arm + nixpkgs: + - locked + - nixos-25.11 + - nixos-26.05 + - nixpkgs-unstable + exclude: + - runner: ubuntu-24.04-arm nixpkgs: locked - - runner: ubuntu-latest - nixpkgs: nixos-25.11 - - runner: ubuntu-latest - nixpkgs: nixos-26.05 - - runner: ubuntu-latest - nixpkgs: nixpkgs-unstable - - runner: ubuntu-24.04-arm - nixpkgs: nixos-25.11 - - runner: ubuntu-24.04-arm - nixpkgs: nixos-26.05 - - runner: ubuntu-24.04-arm - nixpkgs: nixpkgs-unstable name: validate-nix-prebuilt (${{ matrix.nixpkgs }}, ${{ matrix.runner }}) runs-on: ${{ matrix.runner }} steps: diff --git a/.gitignore b/.gitignore index f64b65f..6d553be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +.DS_Store /target .pnpm-store .env diff --git a/README.md b/README.md index 62fd02f..5166236 100644 --- a/README.md +++ b/README.md @@ -240,16 +240,16 @@ This repository includes a flake for NixOS integration. #### Installation Steps -Add the flake input and package to your `flake.nix`: +Add the flake input and NixOS module to your `flake.nix`: + +The module builds the package with your NixOS configuration's `pkgs`, so the +GlobalProtect GUI and the system use the same Nixpkgs dependency versions. ```nix { inputs = { # ... other inputs - globalprotect-openconnect = { - url = "github:yuezk/GlobalProtect-openconnect"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + globalprotect-openconnect.url = "github:yuezk/GlobalProtect-openconnect"; }; outputs = { self, nixpkgs, globalprotect-openconnect, ... }: @@ -262,11 +262,11 @@ Add the flake input and package to your `flake.nix`: modules = [ ./configuration.nix + globalprotect-openconnect.nixosModules.default { - services.ayatana-indicators.enable = true; + programs.globalprotect-openconnect.enable = true; environment.systemPackages = [ - globalprotect-openconnect.packages.${system}.default nixpkgs.legacyPackages.${system}.gnomeExtensions.appindicator ]; } diff --git a/flake.nix b/flake.nix index ba2e2b8..9274861 100644 --- a/flake.nix +++ b/flake.nix @@ -20,13 +20,10 @@ nixpkgs, rust-overlay, }: - flake-utils.lib.eachDefaultSystem ( - system: + let + mkPackageSet = + pkgs: let - pkgs = (import nixpkgs) { - inherit system; - overlays = [ (import rust-overlay) ]; - }; inherit (pkgs) lib; cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); @@ -399,6 +396,49 @@ ''; }; in + { + inherit fromSource prebuilt; + }; + + nixosModule = + { + config, + lib, + pkgs, + ... + }: + let + cfg = config.programs.globalprotect-openconnect; + in + { + options.programs.globalprotect-openconnect = { + enable = lib.mkEnableOption "GlobalProtect-openconnect"; + + package = lib.mkOption { + type = lib.types.package; + # Use the NixOS module's package set so WebKit and graphics + # dependencies match the rest of the system. + default = (mkPackageSet pkgs).prebuilt; + description = "GlobalProtect-openconnect package to install."; + }; + }; + + config = lib.mkIf cfg.enable { + environment.systemPackages = [ cfg.package ]; + services.ayatana-indicators.enable = lib.mkDefault true; + }; + }; + in + (flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = (import nixpkgs) { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + inherit (pkgs) lib; + inherit (mkPackageSet pkgs) fromSource prebuilt; + in { # For `nix build` packages = { @@ -425,5 +465,8 @@ ]; }; } - ); + )) + // { + nixosModules.default = nixosModule; + }; }