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 ''
20 echo "testing bashup.events in ${shell}"
21 ${shell} <<'EOF'
22 source $out/bin/bashup.events
23 neat(){
24 echo $0: Hi from event \'test event\'. I can have both $1 and $2 arguments.
25 exit 0
26 }
27 event on "test event" @2 neat curried
28 echo event registered
29 event emit "test event" runtime
30 exit 1 # fail if emitting event didn't exit clean
31 EOF
32 '';
33
34in
35resholve.mkDerivation rec {
36 # bashup.events doesn't version yet but it has two variants with
37 # differing features/performance characteristics:
38 # - branch master: a variant for bash 3.2+
39 # - branch bash44: a variant for bash 4.4+
40 pname = "bashup-events${variant}-unstable";
41 # should be YYYY-MM-DD
42 inherit version;
43 inherit src;
44
45 installPhase = ''
46 runHook preInstall
47 install -Dt $out/bin bashup.events
48 runHook postInstall
49 '';
50
51 inherit doCheck;
52 nativeCheckInputs = [ bash ];
53
54 checkPhase = ''
55 runHook preCheck
56 ${bash}/bin/bash -n ./bashup.events
57 ${bash}/bin/bash ./bashup.events
58 runHook postCheck
59 '';
60
61 solutions = {
62 events = {
63 inputs = [ ];
64 interpreter = "none";
65 scripts = [ "bin/bashup.events" ];
66 inherit keep;
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}