summaryrefslogtreecommitdiff
path: root/pkgs/development/libraries/bashup-events/generic.nix
blob: 8c058bc7d3751897145698ce95cddca071790dae (plain)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
{
  # general
  lib,
  resholve,
  bash,
  doCheck ? true,
  doInstallCheck ? true,
  # variant-specific
  variant,
  version,
  branch,
  src,
  fake ? false,
  keep,
}:
let
  # extracting this so that it's trivial to test in other shells
  installCheck = shell: ''
    echo "testing bashup.events in ${shell}"
    ${shell} <<'EOF'
    source $out/bin/bashup.events
    neat(){
      echo $0: Hi from event \'test event\'. I can have both $1 and $2 arguments.
      exit 0
    }
    event on "test event" @2 neat curried
    echo event registered
    event emit "test event" runtime
    exit 1 # fail if emitting event didn't exit clean
    EOF
  '';

in
resholve.mkDerivation {
  # bashup.events doesn't version yet but it has two variants with
  # differing features/performance characteristics:
  # - branch master: a variant for bash 3.2+
  # - branch bash44: a variant for bash 4.4+
  pname = "bashup-events${variant}-unstable";
  # should be YYYY-MM-DD
  inherit version;
  inherit src;

  installPhase = ''
    runHook preInstall
    install -Dt $out/bin bashup.events
    runHook postInstall
  '';

  inherit doCheck;
  nativeCheckInputs = [ bash ];

  checkPhase = ''
    runHook preCheck
    ${bash}/bin/bash -n ./bashup.events
    ${bash}/bin/bash ./bashup.events
    runHook postCheck
  '';

  solutions = {
    events = {
      inputs = [ ];
      interpreter = "none";
      scripts = [ "bin/bashup.events" ];
      inherit keep;
    }
    // lib.optionalAttrs (lib.isAttrs fake) { inherit fake; };
  };

  inherit doInstallCheck;
  nativeInstallCheckInputs = [ bash ];
  installCheckPhase = ''
    runHook preInstallCheck
    ${installCheck "${bash}/bin/bash"}
    runHook postInstallCheck
  '';

  meta = {
    inherit branch;
    description = "Event listener/callback API for creating extensible bash programs";
    mainProgram = "bashup.events";
    homepage = "https://github.com/bashup/events";
    license = lib.licenses.cc0;
    maintainers = with lib.maintainers; [ abathur ];
    platforms = lib.platforms.all;
  };
}