Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Environment shell aliases #886

Open
alecandido opened this issue Feb 26, 2024 · 2 comments
Open

Environment shell aliases #886

alecandido opened this issue Feb 26, 2024 · 2 comments

Comments

@alecandido
Copy link

alecandido commented Feb 26, 2024

The content of environment.shellAliases is treated in a (at least) inconsistent way.

For Bash, it ends up in /etc/bashrc:

environment.etc."bashrc".text = ''
# /etc/bashrc: DO NOT EDIT -- this file has been generated automatically.
# This file is read for interactive shells.
[ -r "/etc/bashrc_$TERM_PROGRAM" ] && . "/etc/bashrc_$TERM_PROGRAM"
# Only execute this file once per shell.
if [ -n "$__ETC_BASHRC_SOURCED" -o -n "$NOSYSBASHRC" ]; then return; fi
__ETC_BASHRC_SOURCED=1
# Don't execute this file when running in a pure nix-shell.
if [ "$IN_NIX_SHELL" = "pure" ]; then return; fi
if [ -z "$__NIX_DARWIN_SET_ENVIRONMENT_DONE" ]; then
. ${config.system.build.setEnvironment}
fi
# Return early if not running interactively, but after basic nix setup.
[[ $- != *i* ]] && return
# Make bash check its window size after a process completes
shopt -s checkwinsize
${config.system.build.setAliases.text}

while for ZSH, it's put in /etc/zprofile:
environment.etc."zprofile".text = ''
# /etc/zprofile: DO NOT EDIT -- this file has been generated automatically.
# This file is read for login shells.
# Only execute this file once per shell.
if [ -n "$__ETC_ZPROFILE_SOURCED" ]; then return; fi
__ETC_ZPROFILE_SOURCED=1
${concatStringsSep "\n" zshVariables}
${config.system.build.setAliases.text}

(for both, only first and last lines are relevant)

Personally, I spend most of the time in a non-login shell, so it is a bit annoying to not have aliases defined there.
However, I'm not sure what is the most suitable recommendation, and whether you could abuse(?) zshenv for this purpose.
But I'm pretty sure it would make sense to have it consistent on the two shells.

@alecandido
Copy link
Author

@madsbv
Copy link

madsbv commented Apr 24, 2024

Note that Home-Manager also sets aliases in the user's zshrc:
https://github.com/nix-community/home-manager/blob/bfa7c06436771e3a0c666ccc6ee01e815d4c33aa/modules/programs/zsh.nix#L666

Personally, this caused quite a bit of confusion for me since Zellij seems to launch shells as interactive, non-login shells, so Home-Manager defined aliases worked as expected but Nix-Darwin defined aliases did not.

I think it makes semantically more sense to put aliases in zshrc, and that would bring consistency with NixOS and Home-Manager as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants