Skip to content

[Feature Request] Always reorder PATH in hm-session-vars.sh #8790

@proski

Description

@proski

Module Name

home

Requested Feature

I'm using home-manager with bash on macOS. When I started using tmux, things started breaking subtly in my coding projects. It turned out /usr/bin got in front of PATH, replacing GNU Make 4.4.1 with GNU Make 3.81 for the make command.

tmux runs login shell by default. set-option -g default-command bash in tmux configuration fixed the issue for now. Whether tmux has a good default is debatable, but let's see how home-manager can do a better job respecting the user preferences.

As it stands now, .bash_profile sources .profile, which sources the hm-session-vars.sh script that only sets variable once. That's OK for most variables, but not for PATH.

If a login shell is run as a descendant of another login shell, changes to PATH made in system-wide files are not counteracted by hm-session-vars.sh as __HM_SESS_VARS_SOURCED is still set.

What I believe should be happening:

Regardless of __HM_SESS_VARS_SOURCED, hm-session-vars.sh should prepend the directories specified in home.sessionPath and nix-specific directories such as ~/.nix-profile/bin. If they are found later in PATH, the duplicates should be removed.

Then __HM_SESS_VARS_SOURCED is checked. Other variables are only set once.

Current Limitations

The goal is to provide robust behavior when other software (shells, system-wide shell configuration, terminal multiplexers) is not playing well together.

Can some other software reorder PATH? Perhaps. However, home-manager is expected to do its part to ensure that at least the home.sessionPath setting is robust.

An alternative solution would be to reorder PATH in a separate script sourced from .bashrc - that would protect against even worse offenders that prepend directories to PATH in non-login shells.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions