From b32002710b67de837495036308cf0c27c3effcad Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 21 Jun 2026 20:08:19 +0800 Subject: [PATCH] fix: support NixOS prebuilt GUI package --- .github/workflows/build.yaml | 5 ++- README.md | 10 +++++ .../gpapi/src/process/desktop_session_env.rs | 41 ++++++++++--------- flake.nix | 19 ++++++--- 4 files changed, 48 insertions(+), 27 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 6b120f9..b1b2727 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -348,10 +348,13 @@ jobs: test -x result/bin/gpservice test -x result/bin/gpgui-helper test -x result/bin/gpgui + test ! -L result/bin/gpservice head -n1 result/bin/gpclient | grep '^#!' + head -n1 result/bin/gpservice | grep '^#!' grep -q '/run/wrappers/bin/pkexec' result/bin/gpclient grep -q 'gpservice_public=.*/bin/gpservice' result/bin/gpclient - ! grep -q '@gpservice_public@\|\$out/bin/gpservice' result/bin/gpclient + grep -q 'exec .*/bin/gpservice' result/bin/gpservice + ! grep -q '@gpservice_public@\|@gpservice_fhs@\|\$out/bin/gpservice' result/bin/gpclient result/bin/gpservice ! grep -R '/usr/bin/gp' result/share diff --git a/README.md b/README.md index 94ac488..1292d86 100644 --- a/README.md +++ b/README.md @@ -234,8 +234,11 @@ Add the flake input and package to your `flake.nix`: modules = [ ./configuration.nix { + services.ayatana-indicators.enable = true; + environment.systemPackages = [ globalprotect-openconnect.packages.${system}.default + nixpkgs.legacyPackages.${system}.gnomeExtensions.appindicator ]; } ]; @@ -248,6 +251,13 @@ Apply: ```bash sudo nixos-rebuild switch +loginctl terminate-user "$USER" +``` + +After logging back in to GNOME, enable AppIndicator support if needed: + +```bash +gnome-extensions enable appindicatorsupport@rgcjonas.gmail.com ``` ### Official Docker Image diff --git a/crates/gpapi/src/process/desktop_session_env.rs b/crates/gpapi/src/process/desktop_session_env.rs index 6cf72fa..33ec7b5 100644 --- a/crates/gpapi/src/process/desktop_session_env.rs +++ b/crates/gpapi/src/process/desktop_session_env.rs @@ -33,41 +33,28 @@ mod platform { let session_env = collect(user_id); for key in DESKTOP_SESSION_ENV { - if let Some(value) = env_value(key).or_else(|| session_env.get(*key).cloned()) { + if let Some(value) = desktop_env_value(&session_env, key) { command.env(key, value); } } - let runtime_dir = env_value("XDG_RUNTIME_DIR") - .or_else(|| session_env.get("XDG_RUNTIME_DIR").cloned()) - .unwrap_or_else(|| format!("/run/user/{user_id}")); + let runtime_dir = + desktop_env_value(&session_env, "XDG_RUNTIME_DIR").unwrap_or_else(|| format!("/run/user/{user_id}")); command.env("XDG_RUNTIME_DIR", &runtime_dir); - if env_value("DBUS_SESSION_BUS_ADDRESS") - .or_else(|| session_env.get("DBUS_SESSION_BUS_ADDRESS").cloned()) - .is_none() - { + if desktop_env_value(&session_env, "DBUS_SESSION_BUS_ADDRESS").is_none() { command.env("DBUS_SESSION_BUS_ADDRESS", format!("unix:path={runtime_dir}/bus")); } - if env_value("XDG_DATA_HOME") - .or_else(|| session_env.get("XDG_DATA_HOME").cloned()) - .is_none() - { + if desktop_env_value(&session_env, "XDG_DATA_HOME").is_none() { command.env("XDG_DATA_HOME", home_dir.join(".local/share")); } - if env_value("XDG_CONFIG_HOME") - .or_else(|| session_env.get("XDG_CONFIG_HOME").cloned()) - .is_none() - { + if desktop_env_value(&session_env, "XDG_CONFIG_HOME").is_none() { command.env("XDG_CONFIG_HOME", home_dir.join(".config")); } - if env_value("XDG_DATA_DIRS") - .or_else(|| session_env.get("XDG_DATA_DIRS").cloned()) - .is_none() - { + if desktop_env_value(&session_env, "XDG_DATA_DIRS").is_none() { command.env("XDG_DATA_DIRS", default_xdg_data_dirs()); } } @@ -160,6 +147,10 @@ mod platform { non_empty(env::var(key).ok()) } + fn desktop_env_value(session_env: &HashMap, key: &str) -> Option { + session_env.get(key).cloned().or_else(|| env_value(key)) + } + fn non_empty(value: Option) -> Option { value.filter(|value| !value.trim().is_empty()) } @@ -203,6 +194,16 @@ mod platform { assert_eq!(non_empty(Some(" ".to_string())), None); assert_eq!(non_empty(Some("value".to_string())), Some("value".to_string())); } + + #[test] + fn desktop_env_value_prefers_collected_user_session() { + let env = HashMap::from([("XDG_DATA_DIRS".to_string(), "/run/current-system/sw/share".to_string())]); + + assert_eq!( + desktop_env_value(&env, "XDG_DATA_DIRS"), + Some("/run/current-system/sw/share".to_string()) + ); + } } } diff --git a/flake.nix b/flake.nix index c845438..1b5a2dc 100644 --- a/flake.nix +++ b/flake.nix @@ -63,7 +63,7 @@ linuxRuntimeDependencies = with pkgs; [ glib-networking - libappindicator-gtk3 + libayatana-appindicator ]; linuxBuildInputs = @@ -85,7 +85,7 @@ glib-networking openssl libsecret - libappindicator-gtk3 + libayatana-appindicator ]; rewriteSourceInstallPaths = '' @@ -207,9 +207,7 @@ name = binaryName; targetPkgs = pkgs: - [ - prebuiltFiles - ] + [ prebuiltFiles ] ++ linuxBuildInputs ++ linuxRuntimeDependencies; runScript = "/usr/bin/${binaryName}"; @@ -307,7 +305,16 @@ substituteInPlace $out/bin/gpclient \ --replace-fail '@gpservice_public@' "$out/bin/gpservice" chmod +x $out/bin/gpclient - ln -s ${prebuiltCommands.gpservice}/bin/gpservice $out/bin/gpservice + + 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