Open Th3Whit3Wolf opened 3 years ago
Home Manager only changes files in a user's home directory. Changing things globally is outside the scope of HM and will probably never be implemented.
Technically, you can probably make a dummy configuration where the homeDirectory
is /etc
, use an empty configuration and only write files using home.files
(e.g. home.files."zsh/zshenv".text = "ZDOTDIR=something"
).
Home Manager only changes files in a user's home directory. Changing things globally is outside the scope of HM and will probably never be implemented.
That's what I figured, I put the snippet their really for anyone who wasn't familiar with the solution.
Technically, you can probably make a dummy configuration where the homeDirectory is /etc, use an empty configuration and only write files using home.files (e.g. home.files."zsh/zshenv".text = "ZDOTDIR=something").
I think I'd prefer be able to set a boolean to not create ~/.zshenv
I think this maybe possible using systemd.user.sessionVariables
Home manager creates a ~/.zshenv unnecessarily, cluttering the home directory.
It only happens if zsh
itself is enabled, and even then only if you
oh-my-zsh
Running rg zshenv
, rg oh-my-zsh
, rg envExtra
on the repo does not show any other relevant results.
Did you enable any of the above?
@fricklerhandwerk yes I use an XDG Compliant directory for my configs. I have renamed the issue to reflect that.
I might be missing something here, but as far as I remember ~/.zshenv
is necessary to set ZDOTDIR environment variable in the first place, otherwise how zsh will know where config files are located?
@uvNikita when I get some free time I'm going to try to set it with systemd user environment variables. I could be wrong but I believe they are set by logind and before zsh
@uvNikita wouldn't it be possible via sessionVariables ?
@teto I don't think so, because, unless I'm missing something, those variables are set via zshrc
:
@teto @uvNikita hm-sessiom-vars.sh contains variables set by home. sessionVariablesExtra
I think systemd.user.sessionVariables
might work
@Th3Whit3Wolf I haven't tried it, but seems like environment.d
(which is generated from systemd.user.sessionVariables
) is used to set environment for services only(?):
Configuration files in the environment.d/ directories contain lists of environment variable assignments for services started by the systemd user instance.
https://www.freedesktop.org/software/systemd/man/environment.d.html#Description
So it might work for graphical sessions if they would be started as systemd services, but I don't think it would work for something like ssh sessions.
I haven't tried it either. But I know it is the recommended way to set user environment variables under wayland.
I think it may be worth exploring use of environment.d for possible introduction in the next release cycle but it has to be done with care, we'd want to avoid problems like in https://github.com/nix-community/home-manager/issues/1999.
Oh, and ideally it should be considered in NixOS as well so that we avoid having an impedance mismatch between NixOS and HM.
Yes, and let's not forget that systemd
is not the only mechanism out there. We have a substantial user base on Darwin, for which #1999 also applies.
Thank you for your contribution! I marked this issue as stale due to inactivity. If this remains inactive for another 7 days, I will close this issue. Please read the relevant sections below before commenting.
* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you have nothing of substance to add, please refrain from commenting and allow the bot close the issue. Also, don't be afraid to manually close an issue, even if it holds valuable information.
Closed issues stay in the system for people to search, read, cross-reference, or even reopen--nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.
Not completed
Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.
* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.
For anyone interested, you can work around this right now (in my case I have hm as a NixOS module):
clean-zsh.nix
{ config, ... }:
let
xdgConfig = config.home-manager.users.YOUR_USERNAME.xdg
in
{
environment.etc."zshenv".text = ''
source ${xdgConfig.configHome}/zsh/.zshenv
'';
home-manager.users.YOUR_USERNAME = {
home.file.".zshenv".enable = false;
zsh = {
dotDir = ".config/zsh";
history.path = "${xdgConfig.stateHome}/zsh/history";
};
};
}
configuration.nix
{ ... }:
{
imports = [ ./clean-zsh.nix ];
}
I got a more elaborate version of this here
Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.
* If this is resolved, please consider closing it so that the maintainers know not to focus on this. * If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
* If you are also experiencing this issue, please add details of your situation to help with the debugging process. * If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.
Issue description
Home manager creates a
~/.zshenv
unnecessarily, cluttering the home directory.https://github.com/nix-community/home-manager/blob/a759143ae130e68b8c0ce867c28b3e006f9920e0/modules/programs/zsh.nix#L407-L417
it would be nice to either have an option to not create this file or instead make this global like this.