git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #44441 from mnacamura/shell-aliases

environment.shellAliases: change default behavior

commitd4f2f4c79d45c2599664e99345530f43ccfb6ef8 authorSilvan Mosberger <infinisil@icloud.com> dateSat 13 Oct 2018, 17:46 (8 years ago) parent6e4d0c4c941577
5 files changed+32−24
nixos/modules/config/shells-environment.nix+9−3 nixos/modules/programs/bash/bash.nix+8−5 nixos/modules/programs/fish.nix+8−5 nixos/modules/programs/shell.nix−6 nixos/modules/programs/zsh/zsh.nix+7−5
nixos/modules/config/shells-environment.nix+9−3
@@ -108,14 +108,14 @@ in
108108 };
109109
110110 environment.shellAliases = mkOption {
111− default = {};
112− example = { ll = "ls -l"; };
111+ example = { l = null; ll = "ls -l"; };
113112 description = ''
114113 An attribute set that maps aliases (the top level attribute names in
115114 this option) to command strings or directly to build outputs. The
116115 aliases are added to all users' shells.
116+ Aliases mapped to <code>null</code> are ignored.
117117 '';
118− type = types.attrs; # types.attrsOf types.stringOrPath;
118+ type = with types; attrsOf (nullOr (either str path));
119119 };
120120
121121 environment.binsh = mkOption {
@@ -157,6 +157,12 @@ in
157157 # terminal instead of logging out of X11).
158158 environment.variables = config.environment.sessionVariables;
159159
160+ environment.shellAliases = mapAttrs (name: mkDefault) {
161+ ls = "ls --color=tty";
162+ ll = "ls -l";
163+ l = "ls -alh";
164+ };
165+
160166 environment.etc."shells".text =
161167 ''
162168 ${concatStringsSep "\n" (map utils.toShellPath cfg.shells)}
nixos/modules/programs/bash/bash.nix+8−5
@@ -33,7 +33,8 @@ let
3333 '';
3434
3535 bashAliases = concatStringsSep "\n" (
36− mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases
36+ mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
37+ (filterAttrs (k: v: !isNull v) cfg.shellAliases)
3738 );
3839
3940in
@@ -59,12 +60,12 @@ in
5960 */
6061
6162 shellAliases = mkOption {
62− default = config.environment.shellAliases;
63+ default = {};
6364 description = ''
64− Set of aliases for bash shell. See <option>environment.shellAliases</option>
65− for an option format description.
65+ Set of aliases for bash shell, which overrides <option>environment.shellAliases</option>.
66+ See <option>environment.shellAliases</option> for an option format description.
6667 '';
67− type = types.attrs; # types.attrsOf types.stringOrPath;
68+ type = with types; attrsOf (nullOr (either str path));
6869 };
6970
7071 shellInit = mkOption {
@@ -125,6 +126,8 @@ in
125126
126127 programs.bash = {
127128
129+ shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
130+
128131 shellInit = ''
129132 if [ -z "$__NIXOS_SET_ENVIRONMENT_DONE" ]; then
130133 . ${config.system.build.setEnvironment}
nixos/modules/programs/fish.nix+8−5
@@ -9,7 +9,8 @@ let
99 cfg = config.programs.fish;
1010
1111 fishAliases = concatStringsSep "\n" (
12− mapAttrsFlatten (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases
12+ mapAttrsFlatten (k: v: "alias ${k} ${escapeShellArg v}")
13+ (filterAttrs (k: v: !isNull v) cfg.shellAliases)
1314 );
1415
1516in
@@ -53,12 +54,12 @@ in
5354 };
5455
5556 shellAliases = mkOption {
56− default = config.environment.shellAliases;
57+ default = {};
5758 description = ''
58− Set of aliases for fish shell. See <option>environment.shellAliases</option>
59− for an option format description.
59+ Set of aliases for fish shell, which overrides <option>environment.shellAliases</option>.
60+ See <option>environment.shellAliases</option> for an option format description.
6061 '';
61− type = types.attrs;
62+ type = with types; attrsOf (nullOr (either str path));
6263 };
6364
6465 shellInit = mkOption {
@@ -99,6 +100,8 @@ in
99100
100101 config = mkIf cfg.enable {
101102
103+ programs.fish.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
104+
102105 environment.etc."fish/foreign-env/shellInit".text = cfge.shellInit;
103106 environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit;
104107 environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit;
nixos/modules/programs/shell.nix−6
@@ -8,12 +8,6 @@ with lib;
88
99 config = {
1010
11− environment.shellAliases =
12− { ls = "ls --color=tty";
13− ll = "ls -l";
14− l = "ls -alh";
15− };
16−
1711 environment.shellInit =
1812 ''
1913 # Set up the per-user profile.
nixos/modules/programs/zsh/zsh.nix+7−5
@@ -11,7 +11,8 @@ let
1111 cfg = config.programs.zsh;
1212
1313 zshAliases = concatStringsSep "\n" (
14− mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases
14+ mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}")
15+ (filterAttrs (k: v: !isNull v) cfg.shellAliases)
1516 );
1617
1718in
@@ -34,13 +35,12 @@ in
3435 };
3536
3637 shellAliases = mkOption {
37− default = config.environment.shellAliases;
38+ default = {};
3839 description = ''
39− Set of aliases for zsh shell. Overrides the default value taken from
40− <option>environment.shellAliases</option>.
40+ Set of aliases for zsh shell, which overrides <option>environment.shellAliases</option>.
4141 See <option>environment.shellAliases</option> for an option format description.
4242 '';
43− type = types.attrs; # types.attrsOf types.stringOrPath;
43+ type = with types; attrsOf (nullOr (either str path));
4444 };
4545
4646 shellInit = mkOption {
@@ -106,6 +106,8 @@ in
106106
107107 config = mkIf cfg.enable {
108108
109+ programs.zsh.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases;
110+
109111 environment.etc."zshenv".text =
110112 ''
111113 # /etc/zshenv: DO NOT EDIT -- this file has been generated automatically.