zhaofengli / nix-homebrew

Homebrew installation manager for nix-darwin
MIT License
277 stars 13 forks source link

enable shell integration #39

Closed dezren39 closed 2 weeks ago

dezren39 commented 1 month ago

fixes: #14

i considered a 'shell' attrset that had the per-shell enabled stuff in that, but decided to start simpler. there's at least one example like this in nixpkgs for the 'foot' program.

https://github.com/NixOS/nixpkgs/blob/ee8bdf4f09fdb4809ff8f2202decbfd02450edc3/nixos/modules/programs/foot/default.nix#L83

i left the integration enabled by default for all 3 main shell programs. i figure it's more common to want the commands that not.

i also considered that the content of brew shellenv could easily be generated from the prefix and other info already within the module.

If you would prefer that route I can rework this, I think as-is does work fine though and it aligns with some homebrew instructions.

per homebrew docs, homebrew stuff is installed in front of the existing nix path which should prevent brew programs from failing in strange ways.

Example content of my brew shellenv command output:

export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew/Library/.homebrew-is-managed-by-nix";
PATH="/opt/homebrew/bin:/opt/homebrew/sbin:/Users/drewry.pope/.nix-profile/bin:/etc/profiles/per-user/drewry.pope/bin:/run/current-system/sw/bin:/nix/var/nix/profiles/default/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin"; export PATH;
[ -z "${MANPATH-}" ] || export MANPATH=":${MANPATH#:}";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";

Definitely could generate this ourselves if we wanted.

I'm not sure if manpath and infopath are correct for nix.

testing done: i opened each shell and saw that 'cowsay' was accessible.

AVGVSTVS96 commented 3 weeks ago

Are you sure zsh.interactiveShellInit and bash.interactiveShellInit exist as home-manager options? I can't get it to work in my config, I can only find fish.interactiveShellInit in home-manager options search and manual