Skip to content

Use a dedicated configuration directory path for all-users profiles on non-windows systems. #25748

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 3 commits into
base: master
Choose a base branch
from

Conversation

dviererbe
Copy link

@dviererbe dviererbe commented Jul 11, 2025

PR Summary

PowerShell should search in a dedicated directory (other than the installation directory) for the all-users profile to adhere to the Filesystem Hierarchy Standard (FHS).

PR Context

Currently the all-users profiles are stored in the installation directory. Unix-based systems and derivatives mostly follow recommendations of the FHS. The FHS recommends to place configuration files into the /etc directory.

For example, here are the locations of the system wide configuration files of other popular shells:

  • bash(1): /etc/bash.bashrc (Debian/Ubuntu) or /etc/bashrc (RedHat/Fedora)
  • zsh(1): /etc/zshrc
  • fish(1): /etc/fish/config.fish

I took inspiration from where NuGet is locating its system-wide configuration, see NuGet config file locations:

This commit introduces the environment variable POWERSHELL_COMMON_APPLICATION_DATA.
If this variable is neither null nor empty, then this location is used. This allows distros that do not follow the FHS to customize the location.

  • On Windows PowerShell keeps using the installation directory.
  • On macOS PowerShell uses the /Library/Application Support/PowerShell directory.
  • Otherwise PowerShell uses /etc/opt/powershell.

This change is also needed to make the all-users profile usable when installing powershell via a snap, see canonical/powershell-snaps#14

Fixes: #20336, #25007

PR Checklist

@dviererbe
Copy link
Author

@microsoft-github-policy-service agree company="Canonical Ltd."

@microsoft-github-policy-service microsoft-github-policy-service bot added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Jul 14, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept Stale labels Aug 8, 2025
@dviererbe dviererbe marked this pull request as ready for review August 8, 2025 12:02
Currently the all-users profiles are stored in the
installation directory. Unix-based systems and
derivatives mostly follow recommendations of the
Filesystem Hierarchy Standard [FHS]. The FHS
recommends to place configuration files into the
/etc directory.

For example, here are the locations of the system
wide configuration files of other popular shells:
- bash(1): /etc/bash.bashrc (Debian/Ubuntu) or
           /etc/bashrc (RedHat/Fedora)
- zsh(1):  /etc/zshrc
- fish(1): /etc/fish/config.fish

I took inspiration from where NuGet is locating its
system-wide configuration, see [NuGet config file locations]:

This commit introduces the environment variable
`POWERSHELL_COMMON_APPLICATION_DATA`.
If this variable is neither null nor empty, then
this location is used. This allows distros that do
not follow the FHS to customize the location.

On Windows PowerShell keeps using the installation directory.
On macOS PowerShell uses the `/Library/Application Support/PowerShell` directory.
Otherwise PowerShell uses `/etc/opt/powershell`.

[FHS]: https://refspecs.linuxfoundation.org/FHS_3.0/fhs/index.html
[NuGet config file locations]: https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior#config-file-locations-and-uses

Fixes: PowerShell#20336, PowerShell#25007
Signed-off-by: Dominik Viererbe <dominik.viererbe@canonical.com>
"IO.Path" instead of "io.path"

Signed-off-by: Dominik Viererbe <dominik.viererbe@canonical.com>
Signed-off-by: Dominik Viererbe <dominik.viererbe@canonical.com>
@dviererbe dviererbe force-pushed the feat/SeparateAllUsersFolderPath branch from 5705b00 to 00393a6 Compare August 8, 2025 12:04
@dviererbe
Copy link
Author

Rebased onto master

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

Successfully merging this pull request may close these issues.

AllUsers profile directories READ-ONLY (PS 7.3.7, WSL2, Ubuntu 22.04)
1 participant