feat: add prebuilt Nix package (#622)

This commit is contained in:
Kevin Yue authored and GitHub committed 2026-06-21 11:57:57 +08:00
1 parent ae4cbedd3b
commit 536a43773f
11 files changed
+248 -71

No files matched your search

+58
View File
@@ -0,0 +1,58 @@
use std::{
env,
path::{Path, PathBuf},
};
use crate::constants::{GP_AUTH_BINARY, GP_CLIENT_BINARY, GP_GUI_BINARY, GP_GUI_HELPER_BINARY, GP_SERVICE_BINARY};
pub fn gpclient() -> PathBuf {
resolve("GP_CLIENT_BINARY", "gpclient", GP_CLIENT_BINARY)
}
pub fn gpservice() -> PathBuf {
resolve("GP_SERVICE_BINARY", "gpservice", GP_SERVICE_BINARY)
}
pub fn gpauth() -> PathBuf {
resolve("GP_AUTH_BINARY", "gpauth", GP_AUTH_BINARY)
}
pub fn gpgui() -> PathBuf {
resolve("GP_GUI_BINARY", "gpgui", GP_GUI_BINARY)
}
pub fn gpgui_helper() -> PathBuf {
resolve("GP_GUI_HELPER_BINARY", "gpgui-helper", GP_GUI_HELPER_BINARY)
}
fn resolve(env_key: &str, binary_name: &str, default_path: &str) -> PathBuf {
env::var_os(env_key)
.filter(|value| !value.is_empty())
.map(PathBuf::from)
.or_else(|| sibling_binary(binary_name))
.unwrap_or_else(|| PathBuf::from(default_path))
}
fn sibling_binary(binary_name: &str) -> Option<PathBuf> {
let current_exe = env::current_exe().ok()?;
let bin_dir = current_exe.parent()?;
let binary = bin_dir.join(binary_name);
is_file(&binary).then_some(binary)
}
fn is_file(path: &Path) -> bool {
path.is_file()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_path_is_used_when_no_sibling_exists() {
let path = resolve("GP_TEST_BINARY", "missing-gp-test-binary", "/usr/bin/gp-test");
assert_eq!(path, PathBuf::from("/usr/bin/gp-test"));
}
}
+1
View File
@@ -1 +1,2 @@
pub mod binary_paths;
pub mod constants;
+8 -5
View File
@@ -1,7 +1,7 @@
use std::process::Stdio;
use std::{path::PathBuf, process::Stdio};
use anyhow::bail;
use common::constants::GP_AUTH_BINARY;
use common::binary_paths;
use tokio::process::Command;
use crate::{auth::SamlAuthResult, credential::Credential, os_profile::OsProfile};
@@ -113,8 +113,11 @@ impl<'a> SamlAuthLauncher<'a> {
/// Launch the authenticator binary as the current user or SUDO_USER if available.
pub async fn launch(self) -> anyhow::Result<Credential> {
let program = self.auth_executable.unwrap_or(GP_AUTH_BINARY);
let mut auth_cmd = Command::new(program);
let program = self
.auth_executable
.map(PathBuf::from)
.unwrap_or_else(binary_paths::gpauth);
let mut auth_cmd = Command::new(&program);
auth_cmd.arg(self.server);
if self.gateway {
@@ -174,7 +177,7 @@ impl<'a> SamlAuthLauncher<'a> {
let child = match child {
Ok(child) => child,
Err(err) => {
bail!("Failed to spawn {}: {}", program, err);
bail!("Failed to spawn {}: {}", program.display(), err);
}
};
@@ -1,7 +1,7 @@
use std::{collections::HashMap, path::PathBuf, process::Stdio};
use anyhow::bail;
use common::constants::GP_GUI_HELPER_BINARY;
use common::binary_paths;
use log::info;
use tokio::{io::AsyncWriteExt, process::Command};
@@ -17,7 +17,7 @@ pub struct GuiHelperLauncher<'a> {
impl<'a> GuiHelperLauncher<'a> {
pub fn new(api_key: &'a [u8]) -> Self {
Self {
program: GP_GUI_HELPER_BINARY.into(),
program: binary_paths::gpgui_helper(),
envs: None,
api_key,
gui_version: None,
+2 -2
View File
@@ -5,7 +5,7 @@ use std::{
};
use anyhow::bail;
use common::constants::GP_GUI_BINARY;
use common::binary_paths;
use log::info;
use tokio::{io::AsyncWriteExt, process::Command};
@@ -25,7 +25,7 @@ impl<'a> GuiLauncher<'a> {
pub fn new(version: &'a str, api_key: &'a [u8]) -> Self {
Self {
version,
program: GP_GUI_BINARY.into(),
program: binary_paths::gpgui(),
api_key,
minimized: false,
envs: None,
+2 -2
View File
@@ -4,7 +4,7 @@ use std::{
process::{ExitStatus, Stdio},
};
use common::constants::GP_SERVICE_BINARY;
use common::binary_paths;
use tokio::process::Command;
use super::command_traits::CommandExt;
@@ -26,7 +26,7 @@ impl Default for ServiceLauncher<'_> {
impl<'a> ServiceLauncher<'a> {
pub fn new() -> Self {
Self {
program: GP_SERVICE_BINARY.into(),
program: binary_paths::gpservice(),
minimized: false,
env_file: None,
log_file: None,