Skip to content

shell: separate posix-shells from bash #7107

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Noodlez1232
Copy link
Contributor

@Noodlez1232 Noodlez1232 commented May 21, 2025

Description

Creates a posix-compliant .profile and .shinit usable from any posix-compliant shell. This is great for runtime scripts to have their variables set without having to import programs.enable.bash

For backwards compatibility, it is enabled by default only if programs.enable.bash is enabled.

This commit also changes bash's .profile to be .bash_profile, once again, to keep them separate, since bash is not posix compliant, its profile should not be included in the normal .profile.

fixes: #5474
fixes: #6412

Checklist

  • Change is backwards compatible.

  • Code formatted with nix fmt or
    nix-shell -p treefmt nixfmt-rfc-style keep-sorted --run treefmt.

  • Code tested through nix-shell --pure tests -A run.all
    or nix build --reference-lock-file flake.lock ./tests#test-all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

@rycee

Creates a posix-compliant `.profile` and `.shinit` usable from any
posix-compliant shell. This is great for runtime scripts to have their
variables set without having to import `programs.enable.bash`

For backwards compatibility, it is on by default if
`programs.enable.bash` is on.

This commit also changes bash's `.profile` to be `.bash_profile`, once
again, to keep them separate, since bash is not posix compliant, its
profile should not be included in the normal `.profile`.

fixes: nix-community#5474
fixes: nix-community#6412
@github-actions github-actions bot added the shell label May 21, 2025
@Noodlez1232
Copy link
Contributor Author

This should be ready to go, but there is a couple questions I have about it:

  1. Is the import of .bashrc required in .bash_profile
  2. Should this be default enabled for stateVersion 25.11? Right now it's only enabled by default if bash is enabled (for backwards compatibility)

@Noodlez1232
Copy link
Contributor Author

Noodlez1232 commented May 21, 2025

Oh and also I did test the POSIX side of it with two different shells:

  1. Bash in posix mode (invoked using sh)
  2. Dash, since it itself is a posix compliant shell.

And it worked perfectly for me without breaking actual bash support.

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