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
environment.shellAliases: change default behavior #44441
Conversation
@@ -107,7 +107,11 @@ in | |||
}; | |||
|
|||
environment.shellAliases = mkOption { | |||
default = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these defaults intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just moved these aliases that were in nixos/modules/programs/shell.nix
to here without any specific reason. Empty default is fine or better I think though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made default environment.shellAliases empty.
Note it was just a remark. I have no opinion really on the matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Never mind. It just reflected my preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted the default aliases. See #44441 (comment)
a69e3db
to
b59e790
Compare
Made default |
b59e790
to
0be12c9
Compare
0be12c9
to
0e5358f
Compare
ll = "ls -l"; | ||
l = "ls -alh"; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely sure about removing those, they have been there for a long time. I don't personally use them, but maybe some people do. Do other distros have any default aliases?
Also, the cost of keeping these around with the changes in this PR isn't very high, so we might as well just leave them in for the sake of not annoying anybody.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. Moved them to the default of environment.shellAliases
.
nixos/modules/programs/bash/bash.nix
Outdated
@@ -33,7 +33,7 @@ let | |||
''; | |||
|
|||
bashAliases = concatStringsSep "\n" ( | |||
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases | |||
mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") (cfge.shellAliases // cfg.shellAliases) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a better way to implement this is to have
{
config.programs.bash.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
}
This should then have the //
override behavior automatically through the module system. Also this allows the user to query all bash aliases by evaluating the option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... By your change, although defined in /etc/nixos/configuration.nix
, bash aliases that have the same names as defined in environment.shellAliases
seem not appearing in programs.bash.shellAliases
.
0e5358f
to
e604566
Compare
Ah yeah, there's a problem with the original type. This works: diff --git a/nixos/modules/config/shells-environment.nix b/nixos/modules/config/shells-environment.nix
index 5ecc3cfd207..a279120e125 100644
--- a/nixos/modules/config/shells-environment.nix
+++ b/nixos/modules/config/shells-environment.nix
@@ -108,18 +108,13 @@ in
};
environment.shellAliases = mkOption {
- default = {
- ls = "ls --color=tty";
- ll = "ls -l";
- l = "ls -alh";
- };
example = { ll = "ls -l"; };
description = ''
An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs. The
aliases are added to all users' shells.
'';
- type = types.attrs; # types.attrsOf types.stringOrPath;
+ type = with types; attrsOf (either str path);
};
environment.binsh = mkOption {
@@ -161,6 +156,12 @@ in
# terminal instead of logging out of X11).
environment.variables = config.environment.sessionVariables;
+ environment.shellAliases = mapAttrs (name: mkDefault) {
+ ls = "ls --color=tty";
+ ll = "ls -l";
+ l = "ls -alh";
+ };
+
environment.etc."shells".text =
''
${concatStringsSep "\n" (map utils.toShellPath cfg.shells)}
diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix
index 62c63f2aeb3..aa524a333ee 100644
--- a/nixos/modules/programs/bash/bash.nix
+++ b/nixos/modules/programs/bash/bash.nix
@@ -33,7 +33,7 @@ let
'';
bashAliases = concatStringsSep "\n" (
- mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") (cfge.shellAliases // cfg.shellAliases)
+ mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases
);
in
@@ -64,7 +64,7 @@ in
Set of aliases for bash shell, which overrides <option>environment.shellAliases</option>.
See <option>environment.shellAliases</option> for an option format description.
'';
- type = types.attrs; # types.attrsOf types.stringOrPath;
+ type = with types; attrsOf (either str path);
};
shellInit = mkOption {
@@ -125,6 +125,8 @@ in
programs.bash = {
+ shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
+
shellInit = ''
if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
. ${config.system.build.setEnvironment} (the same for fish and zsh) |
The above patch works. Thank you! Another problem that concerns me is how to remove the default aliases defined in |
Yeah, usually that's done by allowing |
c75c0be
to
8c1092b
Compare
All set. |
default = {}; | ||
default = mapAttrs (name: mkDefault) { | ||
ls = "ls --color=tty"; | ||
ll = "ls -l"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should work like that. It needs to be in the config section. How it's currently will disable all default aliases if a user adds any of their own.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right. Sorry.
8c1092b
to
c941577
Compare
This time for sure. |
This changes the following:
Solves all issues mentioned in #36282 |
nixos/modules/programs/shell.nix
.programs.{bash,zsh,fish}.shellAliases
overrideenvironment.shellAliases
for each shell.Motivation for this change
Hopefully improve the situation in #36282.
Things done
sandbox
innix.conf
on non-NixOS)nix-shell -p nox --run "nox-review wip"
./result/bin/
)nix path-info -S
before and after)