1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfge = config.environment;
8
9 cfg = config.programs.fish;
10
11 fishAliases = concatStringsSep "\n" (
12 mapAttrsFlatten (k: v: "alias ${k} '${v}'") cfg.shellAliases
13 );
14
15in
16
17{
18
19 options = {
20
21 programs.fish = {
22
23 enable = mkOption {
24 default = false;
25 description = ''
26 Whether to configure fish as an interactive shell.
27 '';
28 type = types.bool;
29 };
30
31 shellAliases = mkOption {
32 default = config.environment.shellAliases;
33 description = ''
34 Set of aliases for fish shell. See <option>environment.shellAliases</option>
35 for an option format description.
36 '';
37 type = types.attrs;
38 };
39
40 shellInit = mkOption {
41 default = "";
42 description = ''
43 Shell script code called during fish shell initialisation.
44 '';
45 type = types.lines;
46 };
47
48 loginShellInit = mkOption {
49 default = "";
50 description = ''
51 Shell script code called during fish login shell initialisation.
52 '';
53 type = types.lines;
54 };
55
56 interactiveShellInit = mkOption {
57 default = "";
58 description = ''
59 Shell script code called during interactive fish shell initialisation.
60 '';
61 type = types.lines;
62 };
63
64 promptInit = mkOption {
65 default = "";
66 description = ''
67 Shell script code used to initialise fish prompt.
68 '';
69 type = types.lines;
70 };
71
72 };
73
74 };
75
76 config = mkIf cfg.enable {
77
78 environment.etc."fish/foreign-env/shellInit".text = cfge.shellInit;
79 environment.etc."fish/foreign-env/loginShellInit".text = cfge.loginShellInit;
80 environment.etc."fish/foreign-env/interactiveShellInit".text = cfge.interactiveShellInit;
81
82 environment.etc."fish/config.fish".text = ''
83 # /etc/fish/config.fish: DO NOT EDIT -- this file has been generated automatically.
84
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} 1> /dev/null
88 fenv source /etc/fish/foreign-env/shellInit 1> /dev/null
89
90 ${cfg.shellInit}
91
92 if builtin status --is-login
93 fenv source /etc/fish/foreign-env/loginShellInit 1> /dev/null
94 ${cfg.loginShellInit}
95 end
96
97 if builtin status --is-interactive
98 ${fishAliases}
99 fenv source /etc/fish/foreign-env/interactiveShellInit 1> /dev/null
100 ${cfg.interactiveShellInit}
101 end
102 '';
103
104 environment.systemPackages = [ pkgs.fish ];
105
106 environment.shells = [
107 "/run/current-system/sw/bin/fish"
108 "/var/run/current-system/sw/bin/fish"
109 "${pkgs.fish}/bin/fish"
110 ];
111
112 };
113
114}