From 4c7ec25d3859311c0e00664b7a19fc734dc2d604 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Sun, 16 Mar 2025 07:32:33 +0700 Subject: [PATCH] fix(nix/darwin): Fix sessionVariables is being not passed to GUI apps unless it's opened via terminal --- nix/users/ziro/darwin.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/nix/users/ziro/darwin.nix b/nix/users/ziro/darwin.nix index 24aff85..068e8cb 100644 --- a/nix/users/ziro/darwin.nix +++ b/nix/users/ziro/darwin.nix @@ -33,6 +33,23 @@ MOZ_ALLOW_DOWNGRADE = 1; }; + # Pass sessionVariables to GUI apps with launchctl + # + # REF: https://github.com/nix-community/home-manager/pull/5801/commits/dbe54a48a0bc9942289f6a5d8a751ed3be065c81 + launchd.agents.launchctl-setenv = let + launchctl-setenv = pkgs.writeShellScriptBin "launchctl-setenv" + (concatStringsSep "\n" (mapAttrsToList + (name: val: "/bin/launchctl setenv ${name} ${toString val}") + config.home.sessionVariables)); + in { + enable = true; + config = { + ProgramArguments = [ "${launchctl-setenv}/bin/launchctl-setenv" ]; + KeepAlive.SuccessfulExit = false; + RunAtLoad = true; + }; + }; + home.activation.applications = let env = pkgs.buildEnv { name = "home-applications";