|
27 | 27 | '';
|
28 | 28 | type = types.bool;
|
29 | 29 | };
|
| 30 | + |
| 31 | + vendor.config.enable = mkOption { |
| 32 | + type = types.bool; |
| 33 | + default = true; |
| 34 | + description = '' |
| 35 | + Whether fish should source configuration snippets provided by other packages. |
| 36 | + ''; |
| 37 | + }; |
| 38 | + |
| 39 | + vendor.completions.enable = mkOption { |
| 40 | + type = types.bool; |
| 41 | + default = true; |
| 42 | + description = '' |
| 43 | + Whether fish should use completion files provided by other packages. |
| 44 | + ''; |
| 45 | + }; |
| 46 | + |
| 47 | + vendor.functions.enable = mkOption { |
| 48 | + type = types.bool; |
| 49 | + default = true; |
| 50 | + description = '' |
| 51 | + Whether fish should autoload fish functions provided by other packages. |
| 52 | + ''; |
| 53 | + }; |
30 | 54 |
|
31 | 55 | shellAliases = mkOption {
|
32 | 56 | default = config.environment.shellAliases;
|
|
79 | 103 | environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit;
|
80 | 104 | environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit;
|
81 | 105 |
|
| 106 | + environment.etc."fish/nixos-env-preinit.fish".text = '' |
| 107 | + # avoid clobbering the environment if it's been set by a parent shell |
| 108 | +
|
| 109 | + # This happens before $__fish_datadir/config.fish sets fish_function_path, so it is currently |
| 110 | + # unset. We set it and then completely erase it, leaving its configuration to $__fish_datadir/config.fish |
| 111 | + set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $__fish_datadir/functions |
| 112 | + |
| 113 | + # source the NixOS environment config |
| 114 | + fenv source ${config.system.build.setEnvironment} |
| 115 | +
|
| 116 | + # clear fish_function_path so that it will be correctly set when we return to $__fish_datadir/config.fish |
| 117 | + set -e fish_function_path |
| 118 | + ''; |
| 119 | + |
82 | 120 | environment.etc."fish/config.fish".text = ''
|
83 | 121 | # /etc/fish/config.fish: DO NOT EDIT -- this file has been generated automatically.
|
84 | 122 |
|
85 |
| - set fish_function_path $fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions |
86 |
| -
|
87 |
| - fenv source ${config.system.build.setEnvironment} > /dev/null ^&1 |
88 |
| - fenv source /etc/fish/foreign-env/shellInit > /dev/null |
| 123 | + # if our parent shell didn't source the general config, do it |
| 124 | + if not set -q __fish_nixos_general_config_sourced |
| 125 | + set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path |
| 126 | + fenv source /etc/fish/foreign-env/shellInit > /dev/null |
| 127 | + set -e fish_function_path[1] |
| 128 | + |
| 129 | + ${cfg.shellInit} |
89 | 130 |
|
90 |
| - ${cfg.shellInit} |
| 131 | + # and leave a note to our children to spare them the same work |
| 132 | + set -gx __fish_nixos_general_config_sourced 1 |
| 133 | + end |
91 | 134 |
|
92 |
| - if status --is-login |
| 135 | + # if our parent shell didn't source the login config, do it |
| 136 | + status --is-login; and not set -q __fish_nixos_login_config_sourced |
| 137 | + and begin |
| 138 | + set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path |
93 | 139 | fenv source /etc/fish/foreign-env/loginShellInit > /dev/null
|
| 140 | + set -e fish_function_path[1] |
| 141 | + |
94 | 142 | ${cfg.loginShellInit}
|
| 143 | +
|
| 144 | + # and leave a note to our children to spare them the same work |
| 145 | + set -gx __fish_nixos_login_config_sourced 1 |
95 | 146 | end
|
96 | 147 |
|
97 |
| - if status --is-interactive |
| 148 | + # if our parent shell didn't source the interactive config, do it |
| 149 | + status --is-interactive; and not set -q __fish_nixos_interactive_config_sourced |
| 150 | + and begin |
98 | 151 | ${fishAliases}
|
| 152 | + |
| 153 | +
|
| 154 | + set fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions $fish_function_path |
99 | 155 | fenv source /etc/fish/foreign-env/interactiveShellInit > /dev/null
|
| 156 | + set -e fish_function_path[1] |
| 157 | + |
| 158 | + ${cfg.promptInit} |
100 | 159 | ${cfg.interactiveShellInit}
|
| 160 | +
|
| 161 | + # and leave a note to our children to spare them the same work |
| 162 | + set -gx __fish_nixos_interactive_config_sourced 1 |
101 | 163 | end
|
102 | 164 | '';
|
103 | 165 |
|
104 | 166 | # include programs that bring their own completions
|
105 |
| - environment.pathsToLink = [ "/share/fish/vendor_completions.d" ]; |
106 |
| - |
| 167 | + environment.pathsToLink = [] |
| 168 | + ++ optional cfg.vendor.config.enable "/share/fish/vendor_conf.d" |
| 169 | + ++ optional cfg.vendor.completions.enable "/share/fish/vendor_completions.d" |
| 170 | + ++ optional cfg.vendor.functions.enable "/share/fish/vendor_functions.d"; |
| 171 | + |
107 | 172 | environment.systemPackages = [ pkgs.fish ];
|
108 | 173 |
|
109 | 174 | environment.shells = [
|
|
0 commit comments