2015-12-25 01:17:42 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfge = config.environment;
|
|
|
|
|
|
|
|
cfg = config.programs.fish;
|
|
|
|
|
|
|
|
fishAliases = concatStringsSep "\n" (
|
|
|
|
mapAttrsFlatten (k: v: "alias ${k} '${v}'") cfg.shellAliases
|
|
|
|
);
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.fish = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to configure fish as an interactive shell.
|
|
|
|
'';
|
|
|
|
type = types.bool;
|
|
|
|
};
|
2017-03-25 09:37:07 +01:00
|
|
|
|
|
|
|
vendor.config.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether fish should source configuration snippets provided by other packages.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vendor.completions.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether fish should use completion files provided by other packages.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
vendor.functions.enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether fish should autoload fish functions provided by other packages.
|
|
|
|
'';
|
|
|
|
};
|
2015-12-25 01:17:42 +01:00
|
|
|
|
|
|
|
shellAliases = mkOption {
|
|
|
|
default = config.environment.shellAliases;
|
|
|
|
description = ''
|
|
|
|
Set of aliases for fish shell. See <option>environment.shellAliases</option>
|
|
|
|
for an option format description.
|
|
|
|
'';
|
|
|
|
type = types.attrs;
|
|
|
|
};
|
|
|
|
|
|
|
|
shellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during fish shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
loginShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during fish login shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
interactiveShellInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code called during interactive fish shell initialisation.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
promptInit = mkOption {
|
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
Shell script code used to initialise fish prompt.
|
|
|
|
'';
|
|
|
|
type = types.lines;
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2017-03-25 09:37:07 +01:00
|
|
|
environment.etc."fish/nixos-env-preinit.fish".text = ''
|
|
|
|
# avoid clobbering the environment if it's been set by a parent shell
|
|
|
|
|
|
|
|
# This happens before $__fish_datadir/config.fish sets fish_function_path, so it is currently
|
|
|
|
# unset. We set it and then completely erase it, leaving its configuration to $__fish_datadir/config.fish
|
|
|
|
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $__fish_datadir/functions
|
|
|
|
|
|
|
|
# source the NixOS environment config
|
|
|
|
fenv source ${config.system.build.setEnvironment}
|
|
|
|
|
|
|
|
# clear fish_function_path so that it will be correctly set when we return to $__fish_datadir/config.fish
|
|
|
|
set -e fish_function_path
|
|
|
|
'';
|
|
|
|
|
2015-12-25 01:17:42 +01:00
|
|
|
environment.etc."fish/config.fish".text = ''
|
|
|
|
# /etc/fish/config.fish: DO NOT EDIT -- this file has been generated automatically.
|
|
|
|
|
2017-03-25 09:37:07 +01:00
|
|
|
# if our parent shell didn't source the general config, do it
|
|
|
|
if not set -q __fish_nixos_general_config_sourced
|
|
|
|
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
|
|
|
|
fenv source /etc/fish/foreign-env/shellInit > /dev/null
|
|
|
|
set -e fish_function_path[1]
|
|
|
|
|
|
|
|
${cfg.shellInit}
|
2015-12-25 01:17:42 +01:00
|
|
|
|
2017-03-25 09:37:07 +01:00
|
|
|
# and leave a note to our children to spare them the same work
|
|
|
|
set -gx __fish_nixos_general_config_sourced 1
|
|
|
|
end
|
2015-12-25 01:17:42 +01:00
|
|
|
|
2017-03-25 09:37:07 +01:00
|
|
|
# if our parent shell didn't source the login config, do it
|
|
|
|
status --is-login; and not set -q __fish_nixos_login_config_sourced
|
|
|
|
and begin
|
|
|
|
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
|
2016-05-26 00:09:16 +02:00
|
|
|
fenv source /etc/fish/foreign-env/loginShellInit > /dev/null
|
2017-03-25 09:37:07 +01:00
|
|
|
set -e fish_function_path[1]
|
|
|
|
|
2015-12-25 01:17:42 +01:00
|
|
|
${cfg.loginShellInit}
|
2017-03-25 09:37:07 +01:00
|
|
|
|
|
|
|
# and leave a note to our children to spare them the same work
|
|
|
|
set -gx __fish_nixos_login_config_sourced 1
|
2015-12-25 01:17:42 +01:00
|
|
|
end
|
|
|
|
|
2017-03-25 09:37:07 +01:00
|
|
|
# if our parent shell didn't source the interactive config, do it
|
|
|
|
status --is-interactive; and not set -q __fish_nixos_interactive_config_sourced
|
|
|
|
and begin
|
2015-12-25 01:17:42 +01:00
|
|
|
${fishAliases}
|
2017-03-25 09:37:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path
|
2016-05-26 00:09:16 +02:00
|
|
|
fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null
|
2017-03-25 09:37:07 +01:00
|
|
|
set -e fish_function_path[1]
|
|
|
|
|
|
|
|
${cfg.promptInit}
|
2015-12-25 01:17:42 +01:00
|
|
|
${cfg.interactiveShellInit}
|
2017-03-25 09:37:07 +01:00
|
|
|
|
|
|
|
# and leave a note to our children to spare them the same work
|
|
|
|
set -gx __fish_nixos_interactive_config_sourced 1
|
2015-12-25 01:17:42 +01:00
|
|
|
end
|
|
|
|
'';
|
|
|
|
|
2016-04-08 04:13:41 +02:00
|
|
|
# include programs that bring their own completions
|
2017-03-25 09:37:07 +01:00
|
|
|
environment.pathsToLink = []
|
|
|
|
++ optional cfg.vendor.config.enable "/share/fish/vendor_conf.d"
|
|
|
|
++ optional cfg.vendor.completions.enable "/share/fish/vendor_completions.d"
|
|
|
|
++ optional cfg.vendor.functions.enable "/share/fish/vendor_functions.d";
|
|
|
|
|
2015-12-25 01:17:42 +01:00
|
|
|
environment.systemPackages = [ pkgs.fish ];
|
|
|
|
|
|
|
|
environment.shells = [
|
|
|
|
"/run/current-system/sw/bin/fish"
|
|
|
|
"/var/run/current-system/sw/bin/fish"
|
|
|
|
"${pkgs.fish}/bin/fish"
|
|
|
|
];
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|