-
Notifications
You must be signed in to change notification settings - Fork 6
/
flake.nix
112 lines (101 loc) · 3.88 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
# Run tests with:
# nix develop -c matrix-client-test
{
description = "The matrix-client library";
nixConfig.bash-prompt = "[nix]λ ";
inputs = {
nixpkgs.url =
"github:NixOS/nixpkgs/00d73d5385b63e868bd11282fb775f6fe4921fb5";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachSystem [ "x86_64-linux" ] (system:
let
config = { };
compilerVersion = "924";
compiler = "ghc" + compilerVersion;
overlays = [
(final: prev: {
haskell-language-server = prev.haskell-language-server.override {
supportedGhcVersions = [ compilerVersion ];
};
myHaskellPackages = prev.haskell.packages.${compiler}.override {
overrides = hpFinal: hpPrev: {
matrix-client =
hpPrev.callCabal2nix "matrix-client" ./matrix-client/. { };
matrix-bot =
hpPrev.callCabal2nix "matrix-bot" ./matrix-bot/. { };
};
};
})
];
pkgs = import nixpkgs { inherit config overlays system; };
conduitHome = "/tmp/conduit-home";
conduitConfig = pkgs.writeTextFile {
name = "conduit.toml";
text = ''
[global]
server_name = "localhost"
database_path = "${conduitHome}"
database_backend = "rocksdb"
port = 6167
max_request_size = 20_000_000
allow_registration = true
allow_federation = false
trusted_servers = []
#log = "info,state_res=warn,rocket=off,_=off,sled=off"
address = "127.0.0.1"
'';
};
# A script to start a local matrix server with conduit
conduitStart = pkgs.writeScriptBin "conduit-start" ''
#!/bin/sh -e
rm -Rf ${conduitHome}
mkdir -p ${conduitHome}
exec env CONDUIT_CONFIG=${conduitConfig} ${pkgs.matrix-conduit}/bin/conduit
'';
# A script to setup test environment
conduitSetup = pkgs.writeScriptBin "conduit-setup" ''
#!/bin/sh -e
HOMESERVER_URL=http://localhost:6167
export PATH=$PATH:${pkgs.jq}/bin:${pkgs.curl}/bin
create_token () {
REGISTER_TOKEN=$(curl -XPOST $HOMESERVER_URL/_matrix/client/v3/register -d '{"auth":{"type": "m.login.dummy"}, "username": "'$1'", "password": "'$2'"}' | jq -r ".access_token")
if [ "$REGISTER_TOKEN" != "null" ]; then
echo $REGISTER_TOKEN
else
curl -XPOST $HOMESERVER_URL/_matrix/client/v3/login -d '{"type": "m.login.password", "identifier": {"type": "m.id.user", "user": "'$1'"}, "password": "'$2'"}' | jq -r ".access_token"
fi
}
echo HOMESERVER_URL=$HOMESERVER_URL
echo PRIMARY_TOKEN=$(create_token "test-user" "test-pass")
echo SECONDARY_TOKEN=$(create_token "other-user" "test-pass")
'';
testScript = pkgs.writeScriptBin "matrix-client-test" ''
#!/bin/sh -ex
# running doctest in the haskellPackages.shellFor environment seems to be
# more reliable
doctest ./matrix-client/ -XOverloadedStrings
hlint .
cabal build all
cabal test all
'';
in rec {
packages = with pkgs.myHaskellPackages; { inherit matrix-client; };
defaultPackage = packages.matrix-client;
devShell = pkgs.myHaskellPackages.shellFor {
packages = p: [ p.matrix-client p.matrix-bot ];
buildInputs = with pkgs.myHaskellPackages; [
cabal-install
doctest
hlint
pkgs.haskell-language-server
pkgs.ghcid
testScript
conduitStart
conduitSetup
];
withHoogle = false;
};
});
}