Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(desktop): include the PostHog key in Tauri release builds (#8003)
Eric Hayes735264f15d58
diff --git a/.github/workflows/build_appimage_on_tag.yml b/.github/workflows/build_appimage_on_tag.ymlindex d1000552c5..7c2678408a 100644--- a/.github/workflows/build_appimage_on_tag.yml+++ b/.github/workflows/build_appimage_on_tag.yml@@ -8,6 +8,10 @@ name: Build AppImagedescription: Git ref to check out and buildrequired: truetype: string+ secrets:+ POSTHOG_API_KEY:+ description: PostHog project API key inlined into the desktop bundle+ required: truejobs:build-appimage:name: Build AppImage@@ -47,6 +51,12 @@ jobs:- name: Build AppImage with Nixrun: |set -euo pipefail++ # Vite inlines this into the bundle at build time; without it the shipped+ # desktop app never initializes PostHog and every feature flag reads as off.+ # `--impure` below is what lets Nix evaluation see it.+ : "${VITE_POSTHOG_API_KEY:?must be set from the POSTHOG_API_KEY secret so desktop feature flags work}"+restart_nix_daemon() {echo "::warning::Restarting nix-daemon before retrying AppImage build."sudo systemctl restart nix-daemon.service 2>/dev/null || true@@ -76,8 +86,12 @@ jobs:# Nix daemon can otherwise run unsandboxed under /nix/var/nix/builds,# where linuxdeploy sees host libraries/tools and can fail with only# `failed to run linuxdeploy` in Tauri's default output.+ # --impure only relaxes *evaluation* purity, so the frontend derivation can+ # read VITE_POSTHOG_API_KEY from the environment; the build sandbox below is+ # unaffected.nix build \"${fallback_args[@]}" \+ --impure \--option sandbox true \--option sandbox-build-dir /build \--option download-attempts 10 \@@ -97,6 +111,8 @@ jobs:sleep $((attempt * 10))doneshell: bash+ env:+ VITE_POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}- name: Collect AppImage artifactrun: |set -euo pipefaildiff --git a/.github/workflows/build_desktop_on_tag.yml b/.github/workflows/build_desktop_on_tag.ymlindex 87908488c5..803adba126 100644--- a/.github/workflows/build_desktop_on_tag.yml+++ b/.github/workflows/build_desktop_on_tag.yml@@ -110,6 +110,12 @@ jobs:- name: Build AppImage with Nixrun: |set -euo pipefail++ # Vite inlines this into the bundle at build time; without it the shipped+ # desktop app never initializes PostHog and every feature flag reads as off.+ # `--impure` below is what lets Nix evaluation see it.+ : "${VITE_POSTHOG_API_KEY:?must be set from the POSTHOG_API_KEY secret so desktop feature flags work}"+restart_nix_daemon() {echo "::warning::Restarting nix-daemon before retrying AppImage build."sudo systemctl restart nix-daemon.service 2>/dev/null || true@@ -139,8 +145,12 @@ jobs:# Nix daemon can otherwise run unsandboxed under /nix/var/nix/builds,# where linuxdeploy sees host libraries/tools and can fail with only# `failed to run linuxdeploy` in Tauri's default output.+ # --impure only relaxes *evaluation* purity, so the frontend derivation can+ # read VITE_POSTHOG_API_KEY from the environment; the build sandbox below is+ # unaffected.nix build \"${fallback_args[@]}" \+ --impure \--option sandbox true \--option sandbox-build-dir /build \--option download-attempts 10 \@@ -160,6 +170,8 @@ jobs:sleep $((attempt * 10))doneshell: bash+ env:+ VITE_POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}- name: Collect AppImage artifactrun: |set -euo pipefail@@ -331,6 +343,13 @@ jobs:run: |set -euo pipefail+ # Vite inlines this into the bundle at build time; without it the shipped+ # desktop app never initializes PostHog and every feature flag reads as off.+ # Everything below is already `--impure`, which is what lets Nix evaluation+ # see it — including the path-info pass, so the recorded cache roots match+ # what the builds produce.+ : "${VITE_POSTHOG_API_KEY:?must be set from the POSTHOG_API_KEY secret so desktop feature flags work}"+# Record the derivations before building so completed dependencies can be saved# even if a later compilation or packaging step fails.nix path-info --derivation --impure \@@ -343,6 +362,8 @@ jobs:nix build --impure --option sandbox false --print-build-logs \".#packages.aarch64-darwin.tauri-desktop-dmg"shell: bash+ env:+ VITE_POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}- name: Prune and save macOS Nix build dependenciesif: '!cancelled() && steps.nix-cache.outcome == ''success'''run: |diff --git a/.github/workflows/build_dmg_on_tag.yml b/.github/workflows/build_dmg_on_tag.ymlindex 8fdd374f00..da46f20bb0 100644--- a/.github/workflows/build_dmg_on_tag.yml+++ b/.github/workflows/build_dmg_on_tag.yml@@ -8,6 +8,10 @@ name: Build macOS DMGdescription: Git ref to check out and buildrequired: truetype: string+ secrets:+ POSTHOG_API_KEY:+ description: PostHog project API key inlined into the desktop bundle+ required: truejobs:build-dmg:name: Build macOS DMG@@ -152,6 +156,13 @@ jobs:run: |set -euo pipefail+ # Vite inlines this into the bundle at build time; without it the shipped+ # desktop app never initializes PostHog and every feature flag reads as off.+ # Everything below is already `--impure`, which is what lets Nix evaluation+ # see it — including the path-info pass, so the recorded cache roots match+ # what the builds produce.+ : "${VITE_POSTHOG_API_KEY:?must be set from the POSTHOG_API_KEY secret so desktop feature flags work}"+# Record the derivations before building so completed dependencies can be saved# even if a later compilation or packaging step fails.nix path-info --derivation --impure \@@ -164,6 +175,8 @@ jobs:nix build --impure --option sandbox false --print-build-logs \".#packages.aarch64-darwin.tauri-desktop-dmg"shell: bash+ env:+ VITE_POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }}- name: Prune and save macOS Nix build dependenciesif: '!cancelled() && steps.nix-cache.outcome == ''success'''run: |diff --git a/nix/tauri-desktop.nix b/nix/tauri-desktop.nixindex b3fd4fc948..a1e8c4ad5c 100644--- a/nix/tauri-desktop.nix+++ b/nix/tauri-desktop.nix@@ -30,6 +30,18 @@};gitRev = inputs.self.shortRev or inputs.self.dirtyShortRev or "unknown";+ # Vite inlines `import.meta.env.VITE_*` at build time, so the desktop+ # bundle only reaches PostHog — and therefore only resolves feature+ # flags — when this key is present while the frontend derivation builds.+ # Evaluation is pure by default and `builtins.getEnv` then returns "", so+ # the release workflows export the key and build with `--impure` (see+ # `xtask_workflows/.../scripts/build_appimage.sh` and `build_dmg.sh`).+ # An empty value stays a warning-free flag-less build: that is what ad-hoc+ # local `nix build .#tauri-desktop-*` runs get. The value is a PostHog+ # *project* key, public by design — it ships inside every web and mobile+ # bundle already — so embedding it in the derivation is not a new exposure.+ posthogApiKey = builtins.getEnv "VITE_POSTHOG_API_KEY";+rustToolchain = fenix.packages.${system}.fromToolchainFile {file = ../rust-toolchain.toml;sha256 = "sha256-qqF33vNuAdU5vua96VKVIwuc43j4EFeEXbjQ6+l4mO4=";@@ -119,6 +131,10 @@dontConfigure = true;+ # Vite reads prefixed variables straight off the build environment, the+ # same way `just build-prod` picks them up in the web and Android jobs.+ VITE_POSTHOG_API_KEY = posthogApiKey;+buildPhase = ''runHook preBuild@@ -144,6 +160,16 @@BUNDLE_BUILD_NUMBER=${toString desktopRelease.bundleBuild} MIN_NATIVE_BUILD=0 bun scripts/write-bundle-manifest.mjs)+ # A supplied key that never reaches the bundle means PostHog — and+ # every feature flag behind it — is silently off in the shipped app.+ # Fail the build instead, the way the signed DMG fails on a missing+ # signing identity.+ if [ -n "''${VITE_POSTHOG_API_KEY:-}" ] \+ && ! grep -rqF -- "$VITE_POSTHOG_API_KEY" apps/web/dist; then+ echo "VITE_POSTHOG_API_KEY was set but Vite did not inline it into apps/web/dist" >&2+ exit 1+ fi+runHook postBuild'';diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/build_appimage_on_tag.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/build_appimage_on_tag.rsindex e492052c6b..b6b4614827 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/build_appimage_on_tag.rs+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/build_appimage_on_tag.rs@@ -1,30 +1,50 @@//! `Build AppImage` — reusable workflow that builds the Tauri desktop AppImage//! via Nix. Called from [`super::build_desktop_on_tag`].+use std::collections::HashMap;+use gh_workflow::{Event, Job, Level, Permissions, Run, Step, Workflow, WorkflowCall, WorkflowCallInput,+ WorkflowCallSecret,};-use crate::workflows::{runners, steps};+use crate::workflows::{runners, steps, vars};/// Tag pattern for desktop release builds (CalVer: `v2026.6.23.1`)./// Shared with the DMG workflow and the parent orchestrator.pub const DESKTOP_TAG_PATTERN: &str = "v[0-9]*";+/// Secrets a caller must forward to the reusable desktop build workflows. A+/// called workflow cannot read repository secrets on its own, and the desktop+/// bundle is built with PostHog's key inlined, so the key has to arrive here.+/// The parent orchestrator inlines these jobs instead, and reads the secret+/// directly.+pub fn desktop_build_secrets() -> HashMap<String, WorkflowCallSecret> {+ HashMap::from([(+ "POSTHOG_API_KEY".to_string(),+ WorkflowCallSecret {+ description: "PostHog project API key inlined into the desktop bundle".into(),+ required: true,+ },+ )])+}+/// Build the reusable workflow.pub fn build_appimage() -> Workflow {Workflow::new("Build AppImage")- .on(- Event::default().workflow_call(WorkflowCall::default().add_input(- "ref",- WorkflowCallInput {- description: "Git ref to check out and build".into(),- required: true,- input_type: "string".into(),- default: None,- },- )),- )+ .on(Event::default().workflow_call(+ WorkflowCall::default()+ .add_input(+ "ref",+ WorkflowCallInput {+ description: "Git ref to check out and build".into(),+ required: true,+ input_type: "string".into(),+ default: None,+ },+ )+ .secrets(desktop_build_secrets()),+ )).add_job("build-appimage", build_appimage_job("${{ inputs.ref }}"))}@@ -75,6 +95,7 @@ fn nix_build_appimage() -> Step<Run> {Step::new("Build AppImage with Nix").run(include_str!("scripts/build_appimage.sh")).shell("bash")+ .add_env(("VITE_POSTHOG_API_KEY", vars::POSTHOG_API_KEY))}fn collect_appimage() -> Step<Run> {diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/build_dmg_on_tag.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/build_dmg_on_tag.rsindex a71bb98479..078a0badb5 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/build_dmg_on_tag.rs+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/build_dmg_on_tag.rs@@ -13,17 +13,19 @@ const NIX_CACHE_SIZE_GB: u16 = 100;/// Build the reusable workflow.pub fn build_dmg() -> Workflow {Workflow::new("Build macOS DMG")- .on(- Event::default().workflow_call(WorkflowCall::default().add_input(- "ref",- WorkflowCallInput {- description: "Git ref to check out and build".into(),- required: true,- input_type: "string".into(),- default: None,- },- )),- )+ .on(Event::default().workflow_call(+ WorkflowCall::default()+ .add_input(+ "ref",+ WorkflowCallInput {+ description: "Git ref to check out and build".into(),+ required: true,+ input_type: "string".into(),+ default: None,+ },+ )+ .secrets(build_appimage_on_tag::desktop_build_secrets()),+ )).add_job("build-dmg", build_dmg_job("${{ inputs.ref }}"))}@@ -86,6 +88,7 @@ fn nix_build_dmg() -> Step<Run> {Step::new("Build DMG with Nix").run(include_str!("scripts/build_dmg.sh")).shell("bash")+ .add_env(("VITE_POSTHOG_API_KEY", vars::POSTHOG_API_KEY))}fn configure_nix_cache() -> Step<Run> {diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_appimage.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_appimage.shindex 1a6f62766d..aa05640808 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_appimage.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_appimage.sh@@ -1,4 +1,10 @@set -euo pipefail++# Vite inlines this into the bundle at build time; without it the shipped+# desktop app never initializes PostHog and every feature flag reads as off.+# `--impure` below is what lets Nix evaluation see it.+: "${VITE_POSTHOG_API_KEY:?must be set from the POSTHOG_API_KEY secret so desktop feature flags work}"+restart_nix_daemon() {echo "::warning::Restarting nix-daemon before retrying AppImage build."sudo systemctl restart nix-daemon.service 2>/dev/null || true@@ -28,8 +34,12 @@ build_appimage() {# Nix daemon can otherwise run unsandboxed under /nix/var/nix/builds,# where linuxdeploy sees host libraries/tools and can fail with only# `failed to run linuxdeploy` in Tauri's default output.+ # --impure only relaxes *evaluation* purity, so the frontend derivation can+ # read VITE_POSTHOG_API_KEY from the environment; the build sandbox below is+ # unaffected.nix build \"${fallback_args[@]}" \+ --impure \--option sandbox true \--option sandbox-build-dir /build \--option download-attempts 10 \diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_dmg.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_dmg.shindex ca46f3e50f..c778df5ab3 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_dmg.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/build_dmg.sh@@ -1,5 +1,12 @@set -euo pipefail+# Vite inlines this into the bundle at build time; without it the shipped+# desktop app never initializes PostHog and every feature flag reads as off.+# Everything below is already `--impure`, which is what lets Nix evaluation+# see it — including the path-info pass, so the recorded cache roots match+# what the builds produce.+: "${VITE_POSTHOG_API_KEY:?must be set from the POSTHOG_API_KEY secret so desktop feature flags work}"+# Record the derivations before building so completed dependencies can be saved# even if a later compilation or packaging step fails.nix path-info --derivation --impure \