forked from sarthakbagaria/web-push
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
127 lines (119 loc) · 5.33 KB
/
flake.nix
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{
description = "Web push notifications";
inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.web-push-testing-src = {
url = "github:cotrone/web-push-testing?ref=server-bin";
flake = false;
};
outputs = { self, nixpkgs, flake-utils, haskellNix, web-push-testing-src }:
flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ] (system:
let
compiler-nix-name = "ghc928";
# Web push is a JS project that emulates the behaviour of push notifications in browsers and the servers that deliver notifications to them
web-push-testing = pkgs.buildNpmPackage {
pname = "web-push-testing";
version = "1.0.0";
src = web-push-testing-src;
npmDepsHash = "sha256-KPy4OImh9pDeXVx3zCZsw4low1SqLdWY87HHIdzRsRQ=";
dontNpmBuild = true;
buildInputs = [ pkgs.makeWrapper ];
preConfigure = ''
chmod +x src/bin/server.js
ls -lah src/bin/server.js
patchShebangs --build src/bin/server.js
'';
postFixup = "wrapProgram $out/bin/web-push-testing --prefix PATH : ${pkgs.nodejs}/bin";
meta = with pkgs.lib; {
description = "A server that can be run to test against a mocked API endpoint for web push without relying on flaky browser drivers.";
homepage = "https://github.com/marc1706/web-push-testing";
license = licenses.mit;
};
};
overlays = [haskellNix.overlay (final: prev: {
web-push =
final.haskell-nix.cabalProject' {
src = ./.;
inherit compiler-nix-name;
shell.tools = {
cabal = {};
ghcid = {};
haskell-language-server = {}; # This doesn't work on the internal web-push-example project
};
shell.buildInputs = [ web-push-testing
pkgs.firefox pkgs.geckodriver
pkgs.google-chrome pkgs.chromedriver
];
};
})];
# Wrap the web-push-test binary to include the web-push-testing-server binary in the PATH
web-push-test = pkgs.symlinkJoin {
name = "web-push-test";
nativeBuildInputs = [ pkgs.makeWrapper ];
paths = [ web-push-testing flake.packages."web-push:test:web-push-test" ];
postBuild = ''
wrapProgram $out/bin/web-push-test --prefix PATH : ${web-push-testing}/bin
'';
};
web-push-example-test = pkgs.writeScriptBin "web-push-example-test" ''
export CHROME_BINARY=${pkgs.google-chrome}/bin/google-chrome-stable
export FIREFOX_BINARY=${pkgs.firefox}/bin/firefox
echo "Starting geckodriver"
${pkgs.geckodriver}/bin/geckodriver --log error 2>&1 > /dev/null &
GECKODRIVER_PID=$!
echo "Starting chromedriver"
${pkgs.chromedriver}/bin/chromedriver --log-level=SEVERE 2>&1 > /dev/null &
CHROMEDRIVER_PID=$!
cleanup() {
code=$?
echo "Killing chromedriver and geckodriver and returning $code"
kill $CHROMEDRIVER_PID
kill $GECKODRIVER_PID
exit $code
}
trap "cleanup" EXIT
echo "Wait for geckodriver to start"
timeout 30 sh -c 'until ${pkgs.netcat}/bin/nc -z $0 $1; do sleep 1; done' localhost 4444
GECKODRIVER_EXIT_CODE=$?
if [ $GECKODRIVER_EXIT_CODE -ne 0 ]; then
echo "Failed to start geckodriver"
exit $GECKODRIVER_EXIT_CODE
fi
timeout 30 sh -c 'until ${pkgs.netcat}/bin/nc -z $0 $1; do sleep 1; done' localhost 9515
# Exit if either of the timeout fails
CHROMEDRIVER_EXIT_CODE=$?
if [ $CHROMEDRIVER_EXIT_CODE -ne 0 ]; then
echo "Failed to start chromedriver"
exit $CHROMEDRIVER_EXIT_CODE
fi
echo "Starting web-push-example-tests"
${flake.packages."web-push-example:test:web-push-example-test"}/bin/web-push-example-test
EXIT_CODE=$?
echo "web-push-example-tests exited with code $EXIT_CODE"
exit $EXIT_CODE
'';
# Populate the ci cache with the binaries for tests
# this requires the cache keys to be set in the environment
populate-ci-cache = pkgs.writeScriptBin "populate-ci-cache" ''
nix flake archive --json | ${pkgs.jq}/bin/jq -r '.path,(.inputs|to_entries[].value.path)' | ${pkgs.cachix}/bin/cachix push web-push
nix build .#web-push-test --json | ${pkgs.jq}/bin/jq -r '.[].outputs | to_entries[].value' | ${pkgs.cachix}/bin/cachix push web-push
nix build .#web-push-example-test --json | ${pkgs.jq}/bin/jq -r '.[].outputs | to_entries[].value' | ${pkgs.cachix}/bin/cachix push web-push
'';
pkgs = import nixpkgs {
inherit system overlays;
config = haskellNix.config // {
allowUnfree = true;
};
};
flake = pkgs.web-push.flake { } ;
in flake // {
packages = flake.packages // {
web-push-testing = web-push-testing;
web-push-example-server = flake.packages."web-push-example:exe:web-push-example-server";
web-push-example-test = web-push-example-test;
web-push-test = web-push-test;
populate-ci-cache = populate-ci-cache;
};
});
}