{ inputs = { flake-utils.url = "github:numtide/flake-utils"; naersk.url = "github:nix-community/naersk"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; rust-overlay.url = "github:oxalica/rust-overlay"; }; outputs = { self, flake-utils, naersk, nixpkgs, rust-overlay, }: flake-utils.lib.eachDefaultSystem ( system: let pkgs = (import nixpkgs) { inherit system; overlays = [ (import rust-overlay) ]; }; inherit (pkgs) lib; cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); pname = "globalprotect-openconnect"; version = cargoToml.workspace.package.version; releaseTag = "snapshot"; toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; naersk' = pkgs.callPackage naersk { cargo = toolchain; rustc = toolchain; }; src = pkgs.fetchzip { url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/${releaseTag}/globalprotect-openconnect-${version}.tar.gz"; hash = "sha256-FVovTNkVzAQHdkpKAmLpdauALnxJqzKIY6uTJYSpA8k="; }; cpu = pkgs.stdenv.hostPlatform.parsed.cpu.name; gpguiHashes = { x86_64 = "sha256-72EmKF1EZx45ohU0TAGSQcuacjFqoHancHSQoMCXWEg="; aarch64 = "sha256-Kl7WUkeMVz1qJg8m0o/22rs1TVZP8EV1d6MvyouW7Xw="; }; gpgui = pkgs.fetchzip { url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/${releaseTag}/gpgui_${cpu}.bin.tar.xz"; hash = gpguiHashes.${cpu}; }; binaryHashes = { x86_64 = "sha256-NwZmlVW/+GSyed3R7xnejxb+8NzfVgBYvPhqiRaag0E="; aarch64 = "sha256-WmsN2/8sdW39eqOsKHBs5wwFfAjQgTY3tOe6If5+SNg="; }; binaryPackage = pkgs.fetchzip { url = "https://github.com/yuezk/GlobalProtect-openconnect/releases/download/${releaseTag}/globalprotect-openconnect_${version}_${cpu}.bin.tar.xz"; hash = binaryHashes.${cpu}; }; linuxRuntimeDependencies = with pkgs; [ glib-networking libayatana-appindicator ]; linuxBuildInputs = with pkgs; [ libxml2 zlib lz4 gnutls p11-kit nettle gmp ] ++ lib.optionals stdenv.isLinux [ glib gtk3 libsoup_3 webkitgtk_4_1 glib-networking openssl libsecret libayatana-appindicator ]; rewriteSourceInstallPaths = '' substituteInPlace $out/share/applications/gpgui.desktop \ --replace-fail /usr/bin/gpclient $out/bin/gpclient substituteInPlace $out/libexec/gpclient/hipreport.sh \ --replace-fail /usr/bin/gpclient $out/bin/gpclient substituteInPlace $out/share/polkit-1/actions/com.yuezk.gpgui.policy \ --replace-fail /usr/bin/gpservice $out/bin/gpservice if [ -f $out/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down ]; then substituteInPlace $out/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down \ --replace-fail /usr/bin/gpclient $out/bin/gpclient fi ''; rewriteHostInstallPaths = '' substituteInPlace $out/share/applications/gpgui.desktop \ --replace-fail /usr/bin/gpclient $out/bin/gpclient substituteInPlace $out/share/polkit-1/actions/com.yuezk.gpgui.policy \ --replace-fail /usr/bin/gpservice $out/bin/gpservice if [ -f $out/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down ]; then substituteInPlace $out/lib/NetworkManager/dispatcher.d/pre-down.d/gpclient.down \ --replace-fail /usr/bin/gpclient $out/bin/gpclient fi ''; installNixosPolkitRule = '' chmod u+w $out/share $out/share/polkit-1 2>/dev/null || true install -d $out/share/polkit-1/rules.d cat > $out/share/polkit-1/rules.d/49-gpgui.rules < $out/bin/gpclient <<'EOF' #!${pkgs.runtimeShell} set -eu gpclient_fhs='${prebuiltCommands.gpclient}/bin/gpclient' gpservice_public='@gpservice_public@' if [ "''${1:-}" = "launch-gui" ]; then shift auth_data= minimized= for arg in "$@"; do case "$arg" in --minimized) minimized=--minimized ;; --*) ;; *) auth_data=$arg ;; esac done if [ -z "$auth_data" ]; then if [ -n "''${XDG_DATA_HOME:-}" ]; then data_home=$XDG_DATA_HOME elif [ -n "''${HOME:-}" ]; then data_home=$HOME/.local/share else data_home=/tmp fi log_dir="$data_home/gpclient" mkdir -p "$log_dir" log_file="$log_dir/gpclient.log" env_file=$(mktemp) env > "$env_file" printf 'GP_LOG_FILE=%s\n' "$log_file" >> "$env_file" pkexec_bin=/run/wrappers/bin/pkexec if [ ! -x "$pkexec_bin" ]; then pkexec_bin=pkexec fi set +e if [ -n "$minimized" ]; then "$pkexec_bin" --user root "$gpservice_public" --minimized --env-file "$env_file" 2>"$log_file" else "$pkexec_bin" --user root "$gpservice_public" --env-file "$env_file" 2>"$log_file" fi status=$? set -e rm -f "$env_file" exit "$status" fi set -- launch-gui "$@" fi exec "$gpclient_fhs" "$@" EOF substituteInPlace $out/bin/gpclient \ --replace-fail '@gpservice_public@' "$out/bin/gpservice" chmod +x $out/bin/gpclient cat > $out/bin/gpservice <<'EOF' #!${pkgs.runtimeShell} set -eu exec '@gpservice_fhs@' "$@" EOF substituteInPlace $out/bin/gpservice \ --replace-fail '@gpservice_fhs@' '${prebuiltCommands.gpservice}/bin/gpservice' chmod +x $out/bin/gpservice ln -s ${prebuiltCommands.gpauth}/bin/gpauth $out/bin/gpauth ln -s ${prebuiltCommands.gpgui}/bin/gpgui $out/bin/gpgui ln -s ${prebuiltCommands."gpgui-helper"}/bin/gpgui-helper $out/bin/gpgui-helper cp -r ${prebuiltFiles}/libexec $out/libexec cp -r ${prebuiltFiles}/share $out/share if [ -d ${prebuiltFiles}/lib ]; then cp -r ${prebuiltFiles}/lib $out/lib fi ${rewriteHostInstallPaths} ${installNixosPolkitRule} runHook postInstall ''; }; in { # For `nix build` packages = { fromSource = fromSource; } // lib.optionalAttrs pkgs.stdenv.isLinux { default = prebuilt; prebuilt = prebuilt; } // lib.optionalAttrs (!pkgs.stdenv.isLinux) { default = fromSource; }; apps.default = { type = "app"; program = "${self.packages.${system}.default}/bin/gpclient"; }; # For `nix develop`: not fully set up yet devShell = pkgs.mkShell { nativeBuildInputs = with pkgs; [ rustc cargo ]; }; } ); }