summary refs log tree commit diff
path: root/pkgs/shells/fish/plugins/build-fish-plugin.nix
blob: b5d813133c5b01537e0e7508e5ecdef409708a78 (plain) (blame)
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
{ stdenv, lib, writeScript, wrapFish }:

attrs@{
  pname,
  version,
  src,

  name ? "fishplugin-${pname}-${version}",
  unpackPhase ? "",
  configurePhase ? ":",
  buildPhase ? ":",
  preInstall ? "",
  postInstall ? "",

  nativeCheckInputs ? [],
  # 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 != "",

  ...
}:

let
  # Do not pass attributes that are only relevant to buildFishPlugin to mkDerivation.
  drvAttrs = builtins.removeAttrs attrs [
    "checkPlugins"
    "checkFunctionDirs"
  ];
in

stdenv.mkDerivation (drvAttrs // {
  inherit name;
  inherit unpackPhase configurePhase buildPhase;

  inherit preInstall postInstall;
  installPhase = ''
    runHook preInstall

    (
      install_vendor_files() {
        source="$1"
        target="$out/share/fish/vendor_$2.d"

        [ -d $source ] || return 0
        mkdir -p $target
        cp -r $source/*.fish "$target/"
      }

      install_vendor_files completions completions
      install_vendor_files functions functions
      install_vendor_files conf conf
      install_vendor_files conf.d conf
    )

    runHook postInstall
  '';

  inherit doCheck;

  nativeCheckInputs = [ (wrapFish {
    pluginPkgs = checkPlugins;
    functionDirs = checkFunctionDirs;
  }) ] ++ nativeCheckInputs;

  checkPhase = ''
    export HOME=$(mktemp -d)  # fish wants a writable home
    fish "${writeScript "${name}-test" checkPhase}"
  '';
})