From a22c3621555137a39ffe3e40b836c65baaa79001 Mon Sep 17 00:00:00 2001 From: Rickard Nilsson Date: Wed, 25 Jul 2012 16:53:46 +0200 Subject: [PATCH] Add option for specifying shell aliases, environment.shellAliases. --- modules/module-list.nix | 1 + modules/programs/bash/bash.nix | 20 +++++++++++++++----- modules/programs/bash/bashrc.sh | 6 +----- modules/programs/shell.nix | 25 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 modules/programs/shell.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 0cca6a95544..f2811fd2f5f 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -39,6 +39,7 @@ ./programs/blcr.nix ./programs/info.nix ./programs/shadow.nix + ./programs/shell.nix ./programs/ssh.nix ./programs/ssmtp.nix ./programs/wvdial.nix diff --git a/modules/programs/bash/bash.nix b/modules/programs/bash/bash.nix index 441d30f1e9f..2ba275c7409 100644 --- a/modules/programs/bash/bash.nix +++ b/modules/programs/bash/bash.nix @@ -25,6 +25,9 @@ let fi ''; + shellAliases = concatStringsSep "\n" ( + mapAttrsFlatten (k: v: "alias ${k}='${v}'") config.environment.shellAliases + ); options = { @@ -63,11 +66,11 @@ in { # /etc/bashrc: executed every time a bash starts. Sources # /etc/profile to ensure that the system environment is # configured properly. - source = pkgs.substituteAll { - src = ./bashrc.sh; - inherit initBashCompletion; - }; - target = "bashrc"; + source = pkgs.substituteAll { + src = ./bashrc.sh; + inherit initBashCompletion shellAliases; + }; + target = "bashrc"; } { # Configuration for readline in bash. @@ -76,6 +79,13 @@ in } ]; + environment.shellAliases = { + ls = "ls --color=tty"; + ll = "ls -l"; + l = "ls -alh"; + which = "type -P"; + }; + system.build.binsh = pkgs.bashInteractive; system.activationScripts.binsh = stringAfter [ "stdio" ] diff --git a/modules/programs/bash/bashrc.sh b/modules/programs/bash/bashrc.sh index 4382e7ee9d8..b1ecb278b93 100644 --- a/modules/programs/bash/bashrc.sh +++ b/modules/programs/bash/bashrc.sh @@ -29,8 +29,4 @@ fi @initBashCompletion@ -# Some aliases. -alias ls="ls --color=tty" -alias ll="ls -l" -alias l="ls -alh" -alias which="type -P" +@shellAliases@ diff --git a/modules/programs/shell.nix b/modules/programs/shell.nix new file mode 100644 index 00000000000..8348c4c25a1 --- /dev/null +++ b/modules/programs/shell.nix @@ -0,0 +1,25 @@ +# This module defines global configuration for the shells. + +{ config, pkgs, ... }: + +with pkgs.lib; + +{ + options = { + environment.shellAliases = mkOption { + type = types.attrs; # types.attrsOf types.stringOrPath; + default = {}; + example = { + ll = "ls -lh"; + }; + 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. + ''; + }; + }; + + config = { + }; +}