git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #11945 from jgillich/fish

fish: add module to support it as default shell

commit1fc685ae644f9f99730b46aab61b12b40d5c6aea authorArseniy Seroka <jagajaga@users.noreply.github.com> dateWed 6 Jan 2016, 01:25 (11 years ago) parent2b7b3aaac7e923
7 files changed+394−1
nixos/modules/module-list.nix+1 nixos/modules/programs/fish.nix+114 pkgs/shells/fish-foreign-env/default.nix+28 pkgs/shells/fish/builtin_status.patch+216 pkgs/shells/fish/default.nix+16−1 pkgs/shells/fish/etc_config.patch+17 pkgs/top-level/all-packages.nix+2
nixos/modules/module-list.nix+1
@@ -64,6 +64,7 @@
6464 ./programs/dconf.nix
6565 ./programs/environment.nix
6666 ./programs/freetds.nix
67+ ./programs/fish.nix
6768 ./programs/ibus.nix
6869 ./programs/kbdlight.nix
6970 ./programs/light.nix
nixos/modules/programs/fish.nixnew file+114
@@ -0,0 +1,114 @@
1+{ config, lib, pkgs, ... }:
2+
3+with lib;
4+
5+let
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+
15+in
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+}
pkgs/shells/fish-foreign-env/default.nixnew file+28
@@ -0,0 +1,28 @@
1+{ stdenv, fetchFromGitHub, gnused, bash, coreutils }:
2+
3+stdenv.mkDerivation rec {
4+ name = "fish-foreign-env-${version}";
5+ version = "git-20151223";
6+
7+ src = fetchFromGitHub {
8+ owner = "oh-my-fish";
9+ repo = "plugin-foreign-env";
10+ rev = "2dfe5b73fd2101702c83d1d7b566e2b9332c5ddc";
11+ sha256 = "17jxlbljp7k2azcl1miz5h5xfyazlf9z9lrddcrnm6r7c1w1zdh5";
12+ };
13+
14+ buildCommand = ''
15+ mkdir -p $out/share/fish-foreign-env/functions/
16+ cp $src/functions/* $out/share/fish-foreign-env/functions/
17+ sed -e "s|sed|${gnused}/bin/sed|" \
18+ -e "s|bash|${bash}/bin/bash|" \
19+ -e "s|\| tr|\| ${coreutils}/bin/tr|" \
20+ -i $out/share/fish-foreign-env/functions/*
21+ '';
22+
23+ meta = with stdenv.lib; {
24+ description = "A foreign environment interface for Fish shell";
25+ license = licenses.mit;
26+ maintainers = with maintainers; [ jgillich ];
27+ };
28+}
pkgs/shells/fish/builtin_status.patchnew file+216
@@ -0,0 +1,216 @@
1+commit 5145ca56b0ac1e5e284ab6dfa6fdecc5e86e59b8
2+Author: Jakob Gillich <jakob@gillich.me>
3+Date: Sat Dec 26 04:57:06 2015 +0100
4+
5+ prefix status command with builtin
6+
7+diff --git a/etc/config.fish b/etc/config.fish
8+index 0683f40..9297a85 100644
9+--- a/etc/config.fish
10++++ b/etc/config.fish
11+@@ -6,7 +6,7 @@
12+ # Some things should only be done for login terminals
13+ #
14+
15+-if status --is-login
16++if builtin status --is-login
17+
18+ #
19+ # Set some value for LANG if nothing was set before, and this is a
20+diff --git a/share/functions/__fish_config_interactive.fish b/share/functions/__fish_config_interactive.fish
21+index 9b27fb9..d1c704b 100644
22+--- a/share/functions/__fish_config_interactive.fish
23++++ b/share/functions/__fish_config_interactive.fish
24+@@ -101,7 +101,7 @@ function __fish_config_interactive -d "Initializations that should be performed
25+ eval "$__fish_bin_dir/fish -c 'fish_update_completions > /dev/null ^/dev/null' &"
26+ end
27+
28+- if status -i
29++ if builtin status -i
30+ #
31+ # Print a greeting
32+ #
33+@@ -128,14 +128,14 @@ function __fish_config_interactive -d "Initializations that should be performed
34+ #
35+
36+ function __fish_repaint --on-variable fish_color_cwd --description "Event handler, repaints the prompt when fish_color_cwd changes"
37+- if status --is-interactive
38++ if builtin status --is-interactive
39+ set -e __fish_prompt_cwd
40+ commandline -f repaint ^/dev/null
41+ end
42+ end
43+
44+ function __fish_repaint_root --on-variable fish_color_cwd_root --description "Event handler, repaints the prompt when fish_color_cwd_root changes"
45+- if status --is-interactive
46++ if builtin status --is-interactive
47+ set -e __fish_prompt_cwd
48+ commandline -f repaint ^/dev/null
49+ end
50+@@ -191,7 +191,7 @@ function __fish_config_interactive -d "Initializations that should be performed
51+ # Notify vte-based terminals when $PWD changes (issue #906)
52+ if test "$VTE_VERSION" -ge 3405 -o "$TERM_PROGRAM" = "Apple_Terminal"
53+ function __update_vte_cwd --on-variable PWD --description 'Notify VTE of change to $PWD'
54+- status --is-command-substitution; and return
55++ builtin status --is-command-substitution; and return
56+ printf '\033]7;file://%s%s\a' (hostname) (pwd | __fish_urlencode)
57+ end
58+ end
59+diff --git a/share/functions/__fish_git_prompt.fish b/share/functions/__fish_git_prompt.fish
60+index 0117894..4e4b60f 100644
61+--- a/share/functions/__fish_git_prompt.fish
62++++ b/share/functions/__fish_git_prompt.fish
63+@@ -728,7 +728,7 @@ for var in repaint describe_style show_informative_status showdirtystate showsta
64+ set varargs $varargs --on-variable __fish_git_prompt_$var
65+ end
66+ function __fish_git_prompt_repaint $varargs --description "Event handler, repaints prompt when functionality changes"
67+- if status --is-interactive
68++ if builtin status --is-interactive
69+ if test $argv[3] = __fish_git_prompt_show_informative_status
70+ # Clear characters that have different defaults with/without informative status
71+ for name in cleanstate dirtystate invalidstate stagedstate stateseparator untrackedfiles upstream_ahead upstream_behind
72+@@ -746,7 +746,7 @@ for var in '' _prefix _suffix _bare _merging _cleanstate _invalidstate _upstream
73+ end
74+ set varargs $varargs --on-variable __fish_git_prompt_showcolorhints
75+ function __fish_git_prompt_repaint_color $varargs --description "Event handler, repaints prompt when any color changes"
76+- if status --is-interactive
77++ if builtin status --is-interactive
78+ set -l var $argv[3]
79+ set -e _$var
80+ set -e _{$var}_done
81+@@ -766,7 +766,7 @@ for var in cleanstate dirtystate invalidstate stagedstate stashstate statesepara
82+ set varargs $varargs --on-variable __fish_git_prompt_char_$var
83+ end
84+ function __fish_git_prompt_repaint_char $varargs --description "Event handler, repaints prompt when any char changes"
85+- if status --is-interactive
86++ if builtin status --is-interactive
87+ set -e _$argv[3]
88+ commandline -f repaint ^/dev/null
89+ end
90+diff --git a/share/functions/cd.fish b/share/functions/cd.fish
91+index 8faa469..10168d7 100644
92+--- a/share/functions/cd.fish
93++++ b/share/functions/cd.fish
94+@@ -5,7 +5,7 @@
95+ function cd --description "Change directory"
96+
97+ # Skip history in subshells
98+- if status --is-command-substitution
99++ if builtin status --is-command-substitution
100+ builtin cd $argv
101+ return $status
102+ end
103+@@ -33,4 +33,3 @@ function cd --description "Change directory"
104+
105+ return $cd_status
106+ end
107+-
108+diff --git a/share/functions/eval.fish b/share/functions/eval.fish
109+index 052d417..5eeb12a 100644
110+--- a/share/functions/eval.fish
111++++ b/share/functions/eval.fish
112+@@ -23,17 +23,17 @@ function eval -S -d "Evaluate parameters as a command"
113+ # used interactively, like less, wont work using eval.
114+
115+ set -l mode
116+- if status --is-interactive-job-control
117++ if builtin status --is-interactive-job-control
118+ set mode interactive
119+ else
120+- if status --is-full-job-control
121++ if builtin status --is-full-job-control
122+ set mode full
123+ else
124+ set mode none
125+ end
126+ end
127+- if status --is-interactive
128+- status --job-control full
129++ if builtin status --is-interactive
130++ builtin status --job-control full
131+ end
132+ __fish_restore_status $status_copy
133+
134+@@ -60,6 +60,6 @@ function eval -S -d "Evaluate parameters as a command"
135+ echo "begin; $argv "\n" ;end <&3 3<&-" | source 3<&0
136+ set -l res $status
137+
138+- status --job-control $mode
139++ builtin status --job-control $mode
140+ return $res
141+ end
142+diff --git a/share/functions/history.fish b/share/functions/history.fish
143+index fd2b91f..12d28d7 100644
144+--- a/share/functions/history.fish
145++++ b/share/functions/history.fish
146+@@ -38,7 +38,7 @@ function history --description "Deletes an item from history"
147+ end
148+ else
149+ #Execute history builtin without any argument
150+- if status --is-interactive
151++ if builtin status --is-interactive
152+ builtin history | eval $pager
153+ else
154+ builtin history
155+diff --git a/share/functions/psub.fish b/share/functions/psub.fish
156+index 67863ad..dd0e08b 100644
157+--- a/share/functions/psub.fish
158++++ b/share/functions/psub.fish
159+@@ -40,7 +40,7 @@ function psub --description "Read from stdin into a file and output the filename
160+
161+ end
162+
163+- if not status --is-command-substitution
164++ if not builtin status --is-command-substitution
165+ echo psub: Not inside of command substitution >&2
166+ return 1
167+ end
168+diff --git a/share/tools/web_config/sample_prompts/classic_git.fish b/share/tools/web_config/sample_prompts/classic_git.fish
169+index 39f3ab8..601fa19 100644
170+--- a/share/tools/web_config/sample_prompts/classic_git.fish
171++++ b/share/tools/web_config/sample_prompts/classic_git.fish
172+@@ -17,25 +17,25 @@ function fish_prompt --description 'Write out the prompt'
173+ set -g __fish_classic_git_functions_defined
174+
175+ function __fish_repaint_user --on-variable fish_color_user --description "Event handler, repaint when fish_color_user changes"
176+- if status --is-interactive
177++ if builtin status --is-interactive
178+ commandline -f repaint ^/dev/null
179+ end
180+ end
181+-
182++
183+ function __fish_repaint_host --on-variable fish_color_host --description "Event handler, repaint when fish_color_host changes"
184+- if status --is-interactive
185++ if builtin status --is-interactive
186+ commandline -f repaint ^/dev/null
187+ end
188+ end
189+-
190++
191+ function __fish_repaint_status --on-variable fish_color_status --description "Event handler; repaint when fish_color_status changes"
192+- if status --is-interactive
193++ if builtin status --is-interactive
194+ commandline -f repaint ^/dev/null
195+ end
196+ end
197+
198+ function __fish_repaint_bind_mode --on-variable fish_key_bindings --description "Event handler; repaint when fish_key_bindings changes"
199+- if status --is-interactive
200++ if builtin status --is-interactive
201+ commandline -f repaint ^/dev/null
202+ end
203+ end
204+diff --git a/tests/test_util.fish b/tests/test_util.fish
205+index 22744b3..576dbc4 100644
206+--- a/tests/test_util.fish
207++++ b/tests/test_util.fish
208+@@ -4,7 +4,7 @@
209+ if test "$argv[1]" = (status -f)
210+ echo 'test_util.fish requires sourcing script as argument to `source`' >&2
211+ echo 'use `source test_util.fish (status -f); or exit`' >&2
212+- status --print-stack-trace >&2
213++ builtin status --print-stack-trace >&2
214+ exit 1
215+ end
216+
pkgs/shells/fish/default.nix+16−1
@@ -1,4 +1,5 @@
1−{ stdenv, fetchurl, ncurses, nettools, python, which, groff, gettext, man_db, bc, libiconv, coreutils }:
1+{ stdenv, fetchurl, ncurses, nettools, python, which, groff, gettext, man_db,
2+ bc, libiconv, coreutils, gnused, kbd }:
23
34stdenv.mkDerivation rec {
45 name = "fish-${version}";
@@ -11,6 +12,9 @@ stdenv.mkDerivation rec {
1112 sha256 = "0ympqz7llmf0hafxwglykplw6j5cz82yhlrw50lw4bnf2kykjqx7";
1213 };
1314
15+ # builtin_status has been upstreamed https://github.com/fish-shell/fish-shell/pull/2636
16+ patches = [ ./etc_config.patch ./builtin_status.patch ];
17+
1418 buildInputs = [ ncurses libiconv ];
1519
1620 # Required binaries during execution
@@ -20,15 +24,26 @@ stdenv.mkDerivation rec {
2024 ++ [ bc coreutils ];
2125
2226 postInstall = ''
27+ sed -e "s|expr|${coreutils}/bin/expr|" \
28+ -e "s|if which unicode_start|if true|" \
29+ -e "s|unicode_start|${kbd}/bin/unicode_start|" \
30+ -i "$out/etc/fish/config.fish"
2331 sed -e "s|bc|${bc}/bin/bc|" \
2432 -e "s|/usr/bin/seq|${coreutils}/bin/seq|" \
2533 -i "$out/share/fish/functions/seq.fish" \
2634 "$out/share/fish/functions/math.fish"
2735 sed -i "s|which |${which}/bin/which |" "$out/share/fish/functions/type.fish"
36+ sed -e "s|\|cut|\|${coreutils}/bin/cut|" -i "$out/share/fish/functions/fish_prompt.fish"
2837 sed -i "s|nroff |${groff}/bin/nroff |" "$out/share/fish/functions/__fish_print_help.fish"
2938 sed -e "s|gettext |${gettext}/bin/gettext |" \
3039 -e "s|which |${which}/bin/which |" \
3140 -i "$out/share/fish/functions/_.fish"
41+ sed -e "s|uname|${coreutils}/bin/uname|" \
42+ -i "$out/share/fish/functions/__fish_pwd.fish" \
43+ "$out/share/fish/functions/prompt_pwd.fish"
44+ sed -e "s|sed |${gnused}/bin/sed |" \
45+ -i "$out/share/fish/functions/alias.fish" \
46+ "$out/share/fish/functions/prompt_pwd.fish"
3247 substituteInPlace "$out/share/fish/functions/fish_default_key_bindings.fish" \
3348 --replace "clear;" "${ncurses}/bin/clear;"
3449 '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
pkgs/shells/fish/etc_config.patchnew file+17
@@ -0,0 +1,17 @@
1+commit 0ec07a7018bd69513b0bca6e2f22dbf8575a5b5e
2+Author: Jakob Gillich <jakob@gillich.me>
3+Date: Fri Dec 25 01:59:29 2015 +0100
4+
5+ load /etc/fish/config.fish if it exists
6+
7+diff --git a/etc/config.fish b/etc/config.fish
8+index 0683f40..33f4da7 100644
9+--- a/etc/config.fish
10++++ b/etc/config.fish
11+@@ -37,3 +37,6 @@ if status --is-login
12+ end
13+ end
14+
15++if test -f /etc/fish/config.fish
16++ source /etc/fish/config.fish
17++end
pkgs/top-level/all-packages.nix+2
@@ -3765,6 +3765,8 @@ let
37653765 python = python27Full;
37663766 };
37673767
3768+ fish-foreign-env = callPackage ../shells/fish-foreign-env { };
3769+
37683770 mksh = callPackage ../shells/mksh { };
37693771
37703772 pash = callPackage ../shells/pash { };