1
Fork 0
mirror of https://github.com/thegeneralist01/config.git synced 2026-05-30 08:37:01 +02:00
config/modules/common/shell/default.nix
TheGeneralist 44b56d6fcf
fix macOS local terminals not exec-ing nu
The SSH_TTY guard was too broad — it broke local terminal sessions on
macOS. Use platform-specific conditions: Darwin omits the SSH_TTY check
(always exec nu unless IDE/skip), Linux keeps it (only exec nu for
interactive SSH, leaving non-interactive sessions like Codex in zsh).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-16 17:16:35 +01:00

90 lines
2 KiB
Nix

{
config,
lib,
...
}:
let
inherit (lib)
attrsToList
catAttrs
const
flatten
getAttr
mapAttrsToList
mkOption
sortOn
toInt
unique
;
mkConst =
value:
mkOption {
default = value;
readOnly = true;
};
mkValue =
default:
mkOption {
inherit default;
};
in
{
environment.shells =
config.home-manager.users
|> mapAttrsToList (const <| getAttr "shellsByPriority")
|> flatten
|> unique;
home-manager.sharedModules = [
(
homeArgs:
let
config' = homeArgs.config;
in
{
options.shells = mkValue { };
options.shellsByPriority = mkConst (
config'.shells |> attrsToList |> sortOn ({ name, ... }: toInt name) |> catAttrs "value"
);
options.variablesMap = mkConst {
HOME = config'.home.homeDirectory;
USER = config'.home.username;
XDG_CACHE_HOME = config'.xdg.cacheHome;
XDG_CONFIG_HOME = config'.xdg.configHome;
XDG_DATA_HOME = config'.xdg.dataHome;
XDG_STATE_HOME = config'.xdg.stateHome;
};
}
)
(
homeArgs:
let
config' = homeArgs.config;
nuExecCondition =
if config.isDarwin then
''[ -z "$INTELLIJ_ENVIRONMENT_READER" ] && [ -z "$skip" ]''
else
''[ -z "$INTELLIJ_ENVIRONMENT_READER" ] && [ -z "$skip" ] && [ -n "$SSH_TTY" ]'';
in
{
home.file.".zshrc".text = # zsh
''
export PATH="$HOME/.local/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/etc/profiles/per-user/$USER/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin''${PATH:+:}''${PATH}"
source ${config'.home.sessionVariablesPackage}/etc/profile.d/hm-session-vars.sh
if ${nuExecCondition}; then
SHELL='${lib.getExe <| lib.head config'.shellsByPriority}' exec "$SHELL"
fi
'';
}
)
];
}