1{
2 # general
3 lib,
4 resholve,
5 bash,
6 doCheck ? true,
7 doInstallCheck ? true,
8 # variant-specific
9 variant,
10 version,
11 branch,
12 src,
13 fake ? false,
14 keep,
15}:
16let
17 # extracting this so that it's trivial to test in other shells
18 installCheck = shell: ''
19 echo "testing bashup.events in ${shell}"
20 ${shell} <<'EOF'
21 source $out/bin/bashup.events
22 neat(){
23 echo $0: Hi from event \'test event\'. I can have both $1 and $2 arguments.
24 exit 0
25 }
26 event on "test event" @2 neat curried
27 echo event registered
28 event emit "test event" runtime
29 exit 1 # fail if emitting event didn't exit clean
30 EOF
31 '';
32
33in
34resholve.mkDerivation {
35 # bashup.events doesn't version yet but it has two variants with
36 # differing features/performance characteristics:
37 # - branch master: a variant for bash 3.2+
38 # - branch bash44: a variant for bash 4.4+
39 pname = "bashup-events${variant}-unstable";
40 # should be YYYY-MM-DD
41 inherit version;
42 inherit src;
43
44 installPhase = ''
45 runHook preInstall
46 install -Dt $out/bin bashup.events
47 runHook postInstall
48 '';
49
50 inherit doCheck;
51 nativeCheckInputs = [ bash ];
52
53 checkPhase = ''
54 runHook preCheck
55 ${bash}/bin/bash -n ./bashup.events
56 ${bash}/bin/bash ./bashup.events
57 runHook postCheck
58 '';
59
60 solutions = {
61 events = {
62 inputs = [ ];
63 interpreter = "none";
64 scripts = [ "bin/bashup.events" ];
65 inherit keep;
66 }
67 // lib.optionalAttrs (lib.isAttrs fake) { inherit fake; };
68 };
69
70 inherit doInstallCheck;
71 nativeInstallCheckInputs = [ bash ];
72 installCheckPhase = ''
73 runHook preInstallCheck
74 ${installCheck "${bash}/bin/bash"}
75 runHook postInstallCheck
76 '';
77
78 meta = with lib; {
79 inherit branch;
80 description = "Event listener/callback API for creating extensible bash programs";
81 mainProgram = "bashup.events";
82 homepage = "https://github.com/bashup/events";
83 license = licenses.cc0;
84 maintainers = with maintainers; [ abathur ];
85 platforms = platforms.all;
86 };
87}