nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 writeShellApplication,
4 fish,
5 writeTextFile,
6}:
7
8lib.makeOverridable (
9 /**
10 Creates a wrapped fish shell binary with some plugins, completions,
11 configuration snippets and functions sourced from the function
12 arguments.
13
14 This can for example be used as a convenient way to test fish plugins
15 and scripts without having to alter the environment.
16
17 # Type
18
19 ```pseudocode
20 wrapFish :: {
21 completionDirs :: [Path] ?,
22 functionDirs :: [Path] ?,
23 confDirs :: [Path] ?,
24 pluginPkgs :: [Derivation] ?,
25 localConfig :: String ?,
26 shellAliases :: {
27 [ N :: T ] :: String
28 } ?,
29 runtimeInputs :: [Derivation] ?,
30 } -> Derivation
31 ```
32
33 # Example
34
35 ::: {.example}
36 ```nix
37 wrapFish {
38 pluginPkgs = with fishPlugins; [
39 pure
40 foreign-env
41 ];
42 completionDirs = [ ];
43 functionDirs = [ ];
44 confDirs = [ "/path/to/some/fish/init/dir/" ];
45 shellAliases = {
46 hello = "echo 'Hello World!'";
47 bye = "echo 'Bye World!'; exit";
48 };
49 runtimeInputs = with pkgs; [
50 curl
51 w3m
52 ];
53 }
54 ```
55 :::
56
57 # Arguments
58
59 All arguments are optional.
60
61 ## `completionDirs` (list of paths)
62
63 Directories containing fish completions which will be prepended to
64 {env}`fish_complete_paths` in the environment of the resulting wrapped
65 fish binary.
66
67 ## `functionDirs` (list of paths)
68
69 Directories containing fish functions which will be prepended to
70 {env}`fish_function_path` in the environment of the resulting wrapped
71 fish binary.
72
73 ## `confDirs` (list of paths)
74
75 Directories containing fish code which will be sourced by the resulting
76 wrapped fish binary.
77
78 ## `pluginPkgs` (list of derivations)
79
80 Derivations, usually from the package set `fishPlugins`, that will be
81 added to the resulting wrapped fish binary.
82
83 ## `localConfig` (string)
84
85 String containing a fish script which will be sourced by the resulting
86 wrapped fish binary.
87
88 ## `shellAliases` (attribute set of strings)
89
90 Shell aliases that will be made available in the resulting wrapped fish
91 binary.
92
93 ## `runtimeInputs` (list of derivations)
94
95 A list of Derivations that will be added to the {env}`PATH` of the
96 resulting wrapped fish binary.
97 */
98 {
99 completionDirs ? [ ],
100 functionDirs ? [ ],
101 confDirs ? [ ],
102 pluginPkgs ? [ ],
103 localConfig ? "",
104 shellAliases ? { },
105 runtimeInputs ? [ ],
106 }:
107
108 let
109 aliasesStr = builtins.concatStringsSep "\n" (
110 lib.mapAttrsToList (k: v: "alias ${k} ${lib.escapeShellArg v}") shellAliases
111 );
112
113 shellAliasesFishConfig = writeTextFile {
114 name = "wrapfish.aliases.fish";
115 destination = "/share/fish/vendor_conf.d/aliases.fish";
116 text = ''
117 status is-interactive; and begin
118 # Aliases
119 ${aliasesStr}
120 end
121 '';
122 };
123
124 localFishConfig = writeTextFile {
125 name = "wrapfish.local.fish";
126 destination = "/share/fish/vendor_conf.d/config.local.fish";
127 text = localConfig;
128 };
129
130 vendorDir = kind: plugin: "${plugin}/share/fish/vendor_${kind}.d";
131 complPath = completionDirs ++ map (vendorDir "completions") pluginPkgs;
132 funcPath = functionDirs ++ map (vendorDir "functions") pluginPkgs;
133 confPath =
134 confDirs
135 ++ (map (vendorDir "conf") pluginPkgs)
136 ++ (map (vendorDir "conf") [
137 localFishConfig
138 shellAliasesFishConfig
139 ]);
140
141 in
142 writeShellApplication {
143 inherit runtimeInputs;
144 name = "fish";
145 text = ''
146 ${fish}/bin/fish --init-command "
147 set --prepend fish_complete_path ${lib.escapeShellArgs complPath}
148 set --prepend fish_function_path ${lib.escapeShellArgs funcPath}
149 set --local fish_conf_source_path ${lib.escapeShellArgs confPath}
150 for c in \$fish_conf_source_path/*; source \$c; end
151 " "$@"
152 '';
153 }
154)