From 1b488ba6962576525a4590619ad1e49ae0277261 Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Sun, 21 Jun 2026 14:32:13 +0800 Subject: [PATCH] fix: launch NixOS GUI service outside FHS env --- .github/workflows/build.yaml | 2 ++ flake.nix | 66 +++++++++++++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 600269a..0c7df42 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -348,6 +348,8 @@ jobs: test -x result/bin/gpservice test -x result/bin/gpgui-helper test -x result/bin/gpgui + head -n1 result/bin/gpclient | grep '^#!' + grep -q '/run/wrappers/bin/pkexec' result/bin/gpclient ! grep -R '/usr/bin/gp' result/share diff --git a/flake.nix b/flake.nix index fafaaae..0e6317a 100644 --- a/flake.nix +++ b/flake.nix @@ -240,7 +240,71 @@ runHook preInstall mkdir -p $out/bin - ln -s ${prebuiltCommands.gpclient}/bin/gpclient $out/bin/gpclient + cat > $out/bin/gpclient <<'EOF' + #!${pkgs.runtimeShell} + set -eu + + gpclient_fhs='${prebuiltCommands.gpclient}/bin/gpclient' + gpservice_fhs='${prebuiltCommands.gpservice}/bin/gpservice' + + 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_fhs" --minimized --env-file "$env_file" 2>"$log_file" + else + "$pkexec_bin" --user root "$gpservice_fhs" --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 + chmod +x $out/bin/gpclient ln -s ${prebuiltCommands.gpservice}/bin/gpservice $out/bin/gpservice ln -s ${prebuiltCommands.gpauth}/bin/gpauth $out/bin/gpauth ln -s ${prebuiltCommands.gpgui}/bin/gpgui $out/bin/gpgui