2017-01-07 18:16:26 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.bash;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2017-09-26 21:40:31 +00:00
|
|
|
meta.maintainers = [ maintainers.rycee ];
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
options = {
|
|
|
|
programs.bash = {
|
|
|
|
enable = mkEnableOption "GNU Bourne-Again SHell";
|
|
|
|
|
|
|
|
historySize = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 10000;
|
|
|
|
description = "Number of history lines to keep in memory.";
|
|
|
|
};
|
|
|
|
|
2018-01-06 09:10:20 +00:00
|
|
|
historyFile = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "$HOME/.bash_history";
|
|
|
|
description = "Location of the bash history file.";
|
|
|
|
};
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
historyFileSize = mkOption {
|
|
|
|
type = types.int;
|
|
|
|
default = 100000;
|
|
|
|
description = "Number of history lines to keep on file.";
|
|
|
|
};
|
|
|
|
|
|
|
|
historyControl = mkOption {
|
|
|
|
type = types.listOf (types.enum [
|
|
|
|
"erasedups"
|
|
|
|
"ignoredups"
|
|
|
|
"ignorespace"
|
|
|
|
]);
|
|
|
|
default = [];
|
|
|
|
description = "Controlling how commands are saved on the history list.";
|
|
|
|
};
|
|
|
|
|
|
|
|
historyIgnore = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2017-01-15 19:03:55 +00:00
|
|
|
example = [ "ls" "cd" "exit" ];
|
2017-01-07 18:16:26 +00:00
|
|
|
description = "List of commands that should not be saved to the history list.";
|
|
|
|
};
|
|
|
|
|
|
|
|
shellOptions = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [
|
|
|
|
# Append to history file rather than replacing it.
|
|
|
|
"histappend"
|
|
|
|
|
|
|
|
# check the window size after each command and, if
|
|
|
|
# necessary, update the values of LINES and COLUMNS.
|
|
|
|
"checkwinsize"
|
|
|
|
|
|
|
|
# Extended globbing.
|
|
|
|
"extglob"
|
|
|
|
"globstar"
|
|
|
|
|
|
|
|
# Warn if closing shell with running jobs.
|
|
|
|
"checkjobs"
|
|
|
|
];
|
|
|
|
description = "Shell options to set.";
|
|
|
|
};
|
|
|
|
|
2017-10-12 13:06:51 +00:00
|
|
|
sessionVariables = mkOption {
|
|
|
|
default = {};
|
2019-03-31 11:00:02 +00:00
|
|
|
type = with types; attrsOf (either int str);
|
2017-10-12 13:06:51 +00:00
|
|
|
example = { MAILCHECK = 30; };
|
|
|
|
description = ''
|
|
|
|
Environment variables that will be set for the Bash session.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
shellAliases = mkOption {
|
|
|
|
default = {};
|
2019-03-31 11:00:02 +00:00
|
|
|
type = types.attrsOf types.str;
|
2017-01-07 18:16:26 +00:00
|
|
|
example = { ll = "ls -l"; ".." = "cd .."; };
|
|
|
|
description = ''
|
|
|
|
An attribute set that maps aliases (the top level attribute names in
|
2018-06-11 02:41:27 +00:00
|
|
|
this option) to command strings or directly to build outputs.
|
2017-01-07 18:16:26 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableAutojump = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = "Enable the autojump navigation tool.";
|
|
|
|
};
|
|
|
|
|
|
|
|
profileExtra = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2018-01-07 14:04:57 +00:00
|
|
|
description = ''
|
|
|
|
Extra commands that should be run when initializing a login
|
|
|
|
shell.
|
|
|
|
'';
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
|
|
|
|
2018-01-07 14:14:41 +00:00
|
|
|
bashrcExtra = mkOption {
|
|
|
|
# Hide for now, may want to rename in the future.
|
|
|
|
visible = false;
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
description = ''
|
|
|
|
Extra commands that should be added to
|
|
|
|
<filename>~/.bashrc</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
initExtra = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
2018-01-07 14:04:57 +00:00
|
|
|
description = ''
|
|
|
|
Extra commands that should be run when initializing an
|
|
|
|
interactive shell.
|
|
|
|
'';
|
2017-01-07 18:16:26 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = (
|
|
|
|
let
|
|
|
|
aliasesStr = concatStringsSep "\n" (
|
2018-05-26 08:52:40 +00:00
|
|
|
mapAttrsToList (k: v: "alias ${k}=${escapeShellArg v}") cfg.shellAliases
|
2017-01-07 18:16:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
shoptsStr = concatStringsSep "\n" (
|
|
|
|
map (v: "shopt -s ${v}") cfg.shellOptions
|
|
|
|
);
|
|
|
|
|
2018-01-04 12:29:45 +00:00
|
|
|
sessionVarsStr = config.lib.shell.exportAll cfg.sessionVariables;
|
2018-01-04 11:22:17 +00:00
|
|
|
|
|
|
|
historyControlStr =
|
|
|
|
concatStringsSep "\n" (mapAttrsToList (n: v: "${n}=${v}") (
|
|
|
|
{
|
2018-01-06 09:10:20 +00:00
|
|
|
HISTFILE = "\"${cfg.historyFile}\"";
|
2018-01-04 11:22:17 +00:00
|
|
|
HISTFILESIZE = toString cfg.historyFileSize;
|
2018-01-06 09:10:20 +00:00
|
|
|
HISTSIZE = toString cfg.historySize;
|
2018-01-04 11:22:17 +00:00
|
|
|
}
|
|
|
|
// optionalAttrs (cfg.historyControl != []) {
|
|
|
|
HISTCONTROL = concatStringsSep ":" cfg.historyControl;
|
|
|
|
}
|
|
|
|
// optionalAttrs (cfg.historyIgnore != []) {
|
|
|
|
HISTIGNORE = concatStringsSep ":" cfg.historyIgnore;
|
|
|
|
}
|
|
|
|
));
|
2017-01-07 18:16:26 +00:00
|
|
|
in mkIf cfg.enable {
|
2018-01-07 14:14:41 +00:00
|
|
|
programs.bash.bashrcExtra = ''
|
|
|
|
# Commands that should be applied only for interactive shells.
|
2018-09-25 21:44:38 +00:00
|
|
|
if [[ $- == *i* ]]; then
|
2018-01-04 11:22:17 +00:00
|
|
|
${historyControlStr}
|
2018-01-07 14:14:41 +00:00
|
|
|
|
|
|
|
${shoptsStr}
|
|
|
|
|
|
|
|
${aliasesStr}
|
|
|
|
|
|
|
|
${cfg.initExtra}
|
|
|
|
|
|
|
|
${optionalString cfg.enableAutojump
|
|
|
|
". ${pkgs.autojump}/share/autojump/autojump.bash"}
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2017-01-07 18:16:26 +00:00
|
|
|
home.file.".bash_profile".text = ''
|
|
|
|
# -*- mode: sh -*-
|
|
|
|
|
|
|
|
# include .profile if it exists
|
|
|
|
[[ -f ~/.profile ]] && . ~/.profile
|
|
|
|
|
|
|
|
# include .bashrc if it exists
|
|
|
|
[[ -f ~/.bashrc ]] && . ~/.bashrc
|
|
|
|
'';
|
|
|
|
|
|
|
|
home.file.".profile".text = ''
|
|
|
|
# -*- mode: sh -*-
|
|
|
|
|
2018-07-29 16:15:50 +00:00
|
|
|
. "${config.home.profileDirectory}/etc/profile.d/hm-session-vars.sh"
|
2018-01-04 12:29:45 +00:00
|
|
|
|
|
|
|
${sessionVarsStr}
|
2017-01-07 18:16:26 +00:00
|
|
|
|
|
|
|
${cfg.profileExtra}
|
|
|
|
'';
|
|
|
|
|
|
|
|
home.file.".bashrc".text = ''
|
|
|
|
# -*- mode: sh -*-
|
|
|
|
|
2018-01-07 14:14:41 +00:00
|
|
|
${cfg.bashrcExtra}
|
2017-01-07 18:16:26 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
home.packages =
|
|
|
|
optional (cfg.enableAutojump) pkgs.autojump;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|