blob: 698bc32261a53727a413c99bf66243f980121477 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
{ config, lib, pkgs, ...}:
with lib;
let
cfg = config.programs.fish;
cfge = config.environment;
foreignEnv = pkgs.writeText "fish-foreign-env" ''
# TODO: environment.shellInit
${cfge.extraInit}
'';
loginForeignEnv = pkgs.writeText "fish-login-foreign-env" ''
# TODO: environment.loginShellInit
'';
interactiveForeignEnv = pkgs.writeText "fish-interactive-foreign-env" ''
${cfge.interactiveShellInit}
'';
shell = pkgs.runCommand pkgs.fish.name
{ buildInputs = [ pkgs.makeWrapper ]; }
''
source $stdenv/setup
mkdir -p $out/bin
makeWrapper ${pkgs.fish}/bin/fish $out/bin/fish
'';
fishAliases = concatStringsSep "\n" (
mapAttrsFlatten (k: v: "alias ${k} '${v}'") cfg.shellAliases
);
fishVariables =
mapAttrsToList (n: v: ''set -x ${n} "${v}"'') cfg.variables;
in
{
options = {
programs.fish = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to configure fish as an interactive shell.
'';
};
variables = mkOption {
type = types.attrsOf (types.either types.str (types.listOf types.str));
default = {};
description = ''
A set of environment variables used in the global environment.
These variables will be set on shell initialisation.
The value of each variable can be either a string or a list of
strings. The latter is concatenated, interspersed with colon
characters.
'';
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
};
shellAliases = mkOption {
type = types.attrs;
default = cfge.shellAliases;
description = ''
Set of aliases for fish shell. See <option>environment.shellAliases</option>
for an option format description.
'';
};
shellInit = mkOption {
type = types.lines;
default = "";
description = ''
Shell Script code called during fish shell initialisation.
'';
};
loginShellInit = mkOption {
type = types.lines;
default = "";
description = ''
Shell script code called during fish login shell initialisation.
'';
};
interactiveShellInit = mkOption {
type = types.lines;
default = "";
description = ''
Shell script code called during interactive fish shell initialisation.
'';
};
promptInit = mkOption {
type = types.lines;
default = "";
description = ''
Shell script code used to initialise fish prompt.
'';
};
};
};
config = mkIf cfg.enable {
environment.etc."fish/config.fish".text = ''
# /etc/fish/config.fish: DO NOT EDIT -- this file has been generated automatically.
set fish_function_path $fish_function_path ${pkgs.fish-foreign-env}/share/fish-foreign-env/functions
set PATH ${replaceStrings [":"] [" "] config.environment.systemPath} $PATH
${config.system.build.setEnvironment}
fenv source ${foreignEnv}
${cfg.shellInit}
${concatStringsSep "\n" fishVariables}
if status --is-login
# TODO: environment.loginShellInit
${cfg.loginShellInit}
end
if status --is-interactive
${fishAliases}
${optionalString (cfge.interactiveShellInit != "") ''
fenv source ${interactiveForeignEnv}
''}
${cfg.interactiveShellInit}
${cfg.promptInit}
end
'';
# include programs that bring their own completions
# FIXME: environment.pathsToLink = [ "/share/fish/vendor_completions.d" ];
environment.systemPackages = [ pkgs.fish ];
environment.loginShell = mkDefault "${shell}/bin/fish -l";
environment.variables.SHELL = mkDefault "${shell}/bin/fish";
};
}
|