forked from WalletConnect/walletconnect-monorepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
68 lines (68 loc) · 1.9 KB
/
default.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
{ sources ? import ./ops/nix/sources.nix, githash ? "" }:
let
organization = "walletconnect";
pkgs = import sources.nixpkgs {
overlays = [
(self: super: {
npmlock2nix = pkgs.callPackage sources.npmlock2nix { };
})
];
};
buildNodeApp =
{ src
, node_modules
, pkgjson ? builtins.fromJSON (builtins.readFile (src + "/package.json"))
}: pkgs.stdenv.mkDerivation {
inherit src;
pname = builtins.replaceStrings [ "@" "/" ] [ "_at_" "_slash_" ] pkgjson.name;
version = "v${pkgjson.version}";
buildInputs = [ node_modules.nodejs ];
buildPhase = ''
ln -s ${node_modules}/node_modules ./node_modules
${node_modules.nodejs}/bin/npm run compile
'';
installPhase = ''
mkdir -p $out
ln -s ${node_modules}/node_modules $out/node_modules
cp -r dist/ $out/
cp -r package.json $out/
'';
};
buildDockerImage = { app, nodejs, githash }: pkgs.dockerTools.buildLayeredImage {
name = "${organization}/${pkgs.lib.lists.last (builtins.split "_slash_" app.pname)}";
tag = "${app.version}";
config = {
Cmd = [ "${nodejs}/bin/node" "${app}/dist" ];
Env = [ "GITHASH=${githash}" ];
};
};
build = { src, nodejs }: rec {
app = buildNodeApp {
inherit src;
# remember that node_modules {} accepts mkDerivation attributes
node_modules = pkgs.npmlock2nix.node_modules {
inherit src nodejs;
buildPhase = ''npm ci'';
};
};
docker = buildDockerImage { inherit app githash nodejs; };
};
in
{
relay = build {
nodejs = pkgs.nodejs-16_x;
src = pkgs.nix-gitignore.gitignoreSourcePure [
"dist"
"test"
./.gitignore
] ./servers/relay;
};
health = build {
nodejs = pkgs.nodejs-16_x;
src = pkgs.nix-gitignore.gitignoreSourcePure [
"dist"
"test"
./.gitignore
] ./servers/health;
};
}