summary refs log tree commit diff
path: root/pkgs/shells
diff options
context:
space:
mode:
authorMichele Guerini Rocco <rnhmjoj@users.noreply.github.com>2021-01-11 09:10:52 +0100
committerGitHub <noreply@github.com>2021-01-11 09:10:52 +0100
commita306b088f6f1f2f66bdb01de654e6e2f51b3b937 (patch)
tree50cf49b18aead97cda5b52342f924a3f94ab026c /pkgs/shells
parent1109e2423d4b4ce34a860a13beb87ac88e76a40f (diff)
parent108fd69a8c40d4488c96fd275430b6638fed19df (diff)
downloadnixpkgs-a306b088f6f1f2f66bdb01de654e6e2f51b3b937.tar
nixpkgs-a306b088f6f1f2f66bdb01de654e6e2f51b3b937.tar.gz
nixpkgs-a306b088f6f1f2f66bdb01de654e6e2f51b3b937.tar.bz2
nixpkgs-a306b088f6f1f2f66bdb01de654e6e2f51b3b937.tar.lz
nixpkgs-a306b088f6f1f2f66bdb01de654e6e2f51b3b937.tar.xz
nixpkgs-a306b088f6f1f2f66bdb01de654e6e2f51b3b937.tar.zst
nixpkgs-a306b088f6f1f2f66bdb01de654e6e2f51b3b937.zip
Merge pull request #108491 from pacien/fishPlugins-wrapFish
wrapFish: add fish shell wrapper package
Diffstat (limited to 'pkgs/shells')
-rw-r--r--pkgs/shells/fish/plugins/build-fish-plugin.nix36
-rw-r--r--pkgs/shells/fish/plugins/fishtape.nix2
-rw-r--r--pkgs/shells/fish/plugins/pure.nix2
-rw-r--r--pkgs/shells/fish/wrapper.nix25
4 files changed, 40 insertions, 25 deletions
diff --git a/pkgs/shells/fish/plugins/build-fish-plugin.nix b/pkgs/shells/fish/plugins/build-fish-plugin.nix
index e2ec342e544..a52c5746492 100644
--- a/pkgs/shells/fish/plugins/build-fish-plugin.nix
+++ b/pkgs/shells/fish/plugins/build-fish-plugin.nix
@@ -1,23 +1,6 @@
-{ stdenv, lib, writeShellScriptBin, writeScript, fish }:
+{ stdenv, lib, writeScript, wrapFish }:
 
-let
-  rtpPath = "share/fish";
-
-  mapToFuncPath = v:
-    if lib.isString v
-    then v
-    else "${v}/${rtpPath}/vendor_functions.d";
-
-  fishWithFunctionPath = plugins: let
-    funcPaths = map mapToFuncPath plugins;
-  in writeShellScriptBin "fish" ''
-    ${fish}/bin/fish \
-      --init-command \
-        "set --prepend fish_function_path ${lib.escapeShellArgs funcPaths}" \
-      "$@"
-  '';
-
-in attrs@{
+attrs@{
   pname,
   version,
   src,
@@ -32,8 +15,10 @@ in attrs@{
   installPath ? lib.getName pname,
 
   checkInputs ? [],
-  # plugins or paths to add to the function path of the test fish shell
-  checkFunctionPath ? [],
+  # plugin packages to add to the vendor paths of the test fish shell
+  checkPlugins ? [],
+  # vendor directories to add to the function path of the test fish shell
+  checkFunctionDirs ? [],
   # test script to be executed in a fish shell
   checkPhase ? "",
   doCheck ? checkPhase != "",
@@ -52,7 +37,7 @@ stdenv.mkDerivation (attrs // {
     (
       install_vendor_files() {
         source="$1"
-        target="$out/${rtpPath}/vendor_$2.d"
+        target="$out/share/fish/vendor_$2.d"
 
         [ -d $source ] || return 0
         mkdir -p $target
@@ -69,7 +54,12 @@ stdenv.mkDerivation (attrs // {
   '';
 
   inherit doCheck;
-  checkInputs = [ (fishWithFunctionPath checkFunctionPath) ] ++ checkInputs;
+
+  checkInputs = [ (wrapFish {
+    pluginPkgs = checkPlugins;
+    functionDirs = checkFunctionDirs;
+  }) ] ++ checkInputs;
+
   checkPhase = ''
     export HOME=$(mktemp -d)  # fish wants a writable home
     fish "${writeScript "${name}-test" checkPhase}"
diff --git a/pkgs/shells/fish/plugins/fishtape.nix b/pkgs/shells/fish/plugins/fishtape.nix
index 326ff61c417..82f2375d5e3 100644
--- a/pkgs/shells/fish/plugins/fishtape.nix
+++ b/pkgs/shells/fish/plugins/fishtape.nix
@@ -11,7 +11,7 @@ buildFishPlugin rec {
     sha256 = "0dxcyhs2shhgy5xnwcimqja8vqsyk841x486lgq13i3y1h0kp2kd";
   };
 
-  checkFunctionPath = [ "./" ]; # fishtape is introspective
+  checkFunctionDirs = [ "./" ]; # fishtape is introspective
   checkPhase = ''
     rm test/tty.fish  # test expects a tty
     fishtape test/*.fish
diff --git a/pkgs/shells/fish/plugins/pure.nix b/pkgs/shells/fish/plugins/pure.nix
index 54af2e0663e..3221f6b97ca 100644
--- a/pkgs/shells/fish/plugins/pure.nix
+++ b/pkgs/shells/fish/plugins/pure.nix
@@ -12,7 +12,7 @@ buildFishPlugin rec {
   };
 
   checkInputs = [ git ];
-  checkFunctionPath = [ fishtape ];
+  checkPlugins = [ fishtape ];
   checkPhase = ''
     # https://github.com/rafaelrinaldi/pure/issues/264
     rm tests/_pure_string_width.test.fish
diff --git a/pkgs/shells/fish/wrapper.nix b/pkgs/shells/fish/wrapper.nix
new file mode 100644
index 00000000000..053568bc6b9
--- /dev/null
+++ b/pkgs/shells/fish/wrapper.nix
@@ -0,0 +1,25 @@
+{ lib, writeShellScriptBin, fish }:
+
+with lib;
+
+makeOverridable ({
+  completionDirs ? [],
+  functionDirs ? [],
+  confDirs ? [],
+  pluginPkgs ? []
+}:
+
+let
+  vendorDir = kind: plugin: "${plugin}/share/fish/vendor_${kind}.d";
+  complPath = completionDirs ++ map (vendorDir "completions") pluginPkgs;
+  funcPath = functionDirs ++ map (vendorDir "functions") pluginPkgs;
+  confPath = confDirs ++ map (vendorDir "conf") pluginPkgs;
+  safeConfPath = map escapeShellArg confPath;
+
+in writeShellScriptBin "fish" ''
+  ${fish}/bin/fish --init-command "
+    set --prepend fish_complete_path ${escapeShellArgs complPath}
+    set --prepend fish_function_path ${escapeShellArgs funcPath}
+    for c in {${concatStringsSep "," safeConfPath}}/*; source $c; end
+  " "$@"
+'')