From e4e160cc3990584bf3472d8df76d6cb3deb38b47 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Sat, 4 Aug 2018 17:35:05 +0900 Subject: [PATCH 1/3] nixos/shells: do not override user-defined shell aliases --- nixos/modules/config/shells-environment.nix | 9 +++++++-- nixos/modules/programs/shell.nix | 6 ------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/nixos/modules/config/shells-environment.nix b/nixos/modules/config/shells-environment.nix index 555db459f57a..a279120e125d 100644 --- a/nixos/modules/config/shells-environment.nix +++ b/nixos/modules/config/shells-environment.nix @@ -108,14 +108,13 @@ in }; environment.shellAliases = mkOption { - default = {}; 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 { @@ -157,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/shell.nix b/nixos/modules/programs/shell.nix index 944a8bdf16fc..6aa0262e3a4c 100644 --- a/nixos/modules/programs/shell.nix +++ b/nixos/modules/programs/shell.nix @@ -8,12 +8,6 @@ with lib; config = { - environment.shellAliases = - { ls = "ls --color=tty"; - ll = "ls -l"; - l = "ls -alh"; - }; - environment.shellInit = '' # Set up the per-user profile. From 3b5449b80c1840aeb07322fbd3c37f8a80d11958 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Sat, 4 Aug 2018 12:32:30 +0900 Subject: [PATCH 2/3] nixos/shells: programs.*sh.shellAliases override environment.shellAliases --- nixos/modules/programs/bash/bash.nix | 10 ++++++---- nixos/modules/programs/fish.nix | 10 ++++++---- nixos/modules/programs/zsh/zsh.nix | 9 +++++---- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix index f664e2225550..aa524a333ee6 100644 --- a/nixos/modules/programs/bash/bash.nix +++ b/nixos/modules/programs/bash/bash.nix @@ -59,12 +59,12 @@ in */ shellAliases = mkOption { - default = config.environment.shellAliases; + default = {}; description = '' - Set of aliases for bash shell. See - for an option format description. + Set of aliases for bash shell, which overrides . + See 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} diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix index 5948fe11f92b..82af9ecc5611 100644 --- a/nixos/modules/programs/fish.nix +++ b/nixos/modules/programs/fish.nix @@ -53,12 +53,12 @@ in }; shellAliases = mkOption { - default = config.environment.shellAliases; + default = {}; description = '' - Set of aliases for fish shell. See - for an option format description. + Set of aliases for fish shell, which overrides . + See for an option format description. ''; - type = types.attrs; + type = with types; attrsOf (either str path); }; shellInit = mkOption { @@ -99,6 +99,8 @@ in config = mkIf cfg.enable { + programs.fish.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases; + environment.etc."fish/foreign-env/shellInit".text = cfge.shellInit; environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit; environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit; diff --git a/nixos/modules/programs/zsh/zsh.nix b/nixos/modules/programs/zsh/zsh.nix index 865d148c1629..66ca5e5d4eb5 100644 --- a/nixos/modules/programs/zsh/zsh.nix +++ b/nixos/modules/programs/zsh/zsh.nix @@ -34,13 +34,12 @@ in }; shellAliases = mkOption { - default = config.environment.shellAliases; + default = {}; description = '' - Set of aliases for zsh shell. Overrides the default value taken from - . + Set of aliases for zsh shell, which overrides . See for an option format description. ''; - type = types.attrs; # types.attrsOf types.stringOrPath; + type = with types; attrsOf (either str path); }; shellInit = mkOption { @@ -106,6 +105,8 @@ in config = mkIf cfg.enable { + programs.zsh.shellAliases = mapAttrs (name: mkDefault) cfge.shellAliases; + environment.etc."zshenv".text = '' # /etc/zshenv: DO NOT EDIT -- this file has been generated automatically. From c941577dcb68ad413853ae744a458555b3209c21 Mon Sep 17 00:00:00 2001 From: Mitsuhiro Nakamura Date: Fri, 12 Oct 2018 22:58:35 +0900 Subject: [PATCH 3/3] nixos/shells: enable to nullify already defined aliases --- nixos/modules/config/shells-environment.nix | 5 +++-- nixos/modules/programs/bash/bash.nix | 5 +++-- nixos/modules/programs/fish.nix | 5 +++-- nixos/modules/programs/zsh/zsh.nix | 5 +++-- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/nixos/modules/config/shells-environment.nix b/nixos/modules/config/shells-environment.nix index a279120e125d..6379b52870ea 100644 --- a/nixos/modules/config/shells-environment.nix +++ b/nixos/modules/config/shells-environment.nix @@ -108,13 +108,14 @@ in }; environment.shellAliases = mkOption { - example = { ll = "ls -l"; }; + example = { l = null; 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. + Aliases mapped to null are ignored. ''; - type = with types; attrsOf (either str path); + type = with types; attrsOf (nullOr (either str path)); }; environment.binsh = mkOption { diff --git a/nixos/modules/programs/bash/bash.nix b/nixos/modules/programs/bash/bash.nix index aa524a333ee6..0fbc77ea44cf 100644 --- a/nixos/modules/programs/bash/bash.nix +++ b/nixos/modules/programs/bash/bash.nix @@ -33,7 +33,8 @@ let ''; bashAliases = concatStringsSep "\n" ( - mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases + mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") + (filterAttrs (k: v: !isNull v) cfg.shellAliases) ); in @@ -64,7 +65,7 @@ in Set of aliases for bash shell, which overrides . See for an option format description. ''; - type = with types; attrsOf (either str path); + type = with types; attrsOf (nullOr (either str path)); }; shellInit = mkOption { diff --git a/nixos/modules/programs/fish.nix b/nixos/modules/programs/fish.nix index 82af9ecc5611..b38af07b92c3 100644 --- a/nixos/modules/programs/fish.nix +++ b/nixos/modules/programs/fish.nix @@ -9,7 +9,8 @@ let cfg = config.programs.fish; fishAliases = concatStringsSep "\n" ( - mapAttrsFlatten (k: v: "alias ${k} ${escapeShellArg v}") cfg.shellAliases + mapAttrsFlatten (k: v: "alias ${k} ${escapeShellArg v}") + (filterAttrs (k: v: !isNull v) cfg.shellAliases) ); in @@ -58,7 +59,7 @@ in Set of aliases for fish shell, which overrides . See for an option format description. ''; - type = with types; attrsOf (either str path); + type = with types; attrsOf (nullOr (either str path)); }; shellInit = mkOption { diff --git a/nixos/modules/programs/zsh/zsh.nix b/nixos/modules/programs/zsh/zsh.nix index 66ca5e5d4eb5..164d8db5859a 100644 --- a/nixos/modules/programs/zsh/zsh.nix +++ b/nixos/modules/programs/zsh/zsh.nix @@ -11,7 +11,8 @@ let cfg = config.programs.zsh; zshAliases = concatStringsSep "\n" ( - mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases + mapAttrsFlatten (k: v: "alias ${k}=${escapeShellArg v}") + (filterAttrs (k: v: !isNull v) cfg.shellAliases) ); in @@ -39,7 +40,7 @@ in Set of aliases for zsh shell, which overrides . See for an option format description. ''; - type = with types; attrsOf (either str path); + type = with types; attrsOf (nullOr (either str path)); }; shellInit = mkOption {