-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
109 lines (105 loc) · 3.38 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
{
description = "Melange starter";
inputs = {
nix-filter.url = "github:numtide/nix-filter";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs = {
url = "github:nix-ocaml/nix-overlays";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{ self
, nixpkgs
, flake-utils
, nix-filter
}:
(flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}".appendOverlays (import ./nix/overlay.nix { });
inherit (pkgs) ocamlPackages;
nodeDependencies = (pkgs.lib.callPackageWith pkgs ./node.nix { nix-filter = nix-filter.lib; }).nodeDependencies;
serverPkg = system: static:
let
pkgs = nixpkgs.legacyPackages."${system}".appendOverlays (
(import ./nix/overlay.nix { })
);
nodeDependencies = (pkgs.lib.callPackageWith pkgs ./node.nix {
nix-filter = nix-filter.lib;
}).nodeDependencies;
in
(pkgs.callPackage ./nix {
inherit static;
nix-filter = nix-filter.lib;
inherit nodeDependencies;
}).server;
in
rec {
devShells.default = pkgs.mkShell {
SSL_CERT_FILE = "${pkgs.cacert.out}/etc/ssl/certs/ca-bundle.crt";
shellHook = ''
export NODE_PATH=${nodeDependencies}/lib/node_modules
export PATH="${nodeDependencies}/bin:$PATH"
'';
inputsFrom = [ (serverPkg system false) ];
nativeBuildInputs = [
pkgs.nodejs
ocamlPackages.ocaml-lsp
ocamlPackages.reason
ocamlPackages.reason-native.refmterr
ocamlPackages.ocamlformat
pkgs.bintools
pkgs.node2nix
pkgs.watchexec
] ++ pkgs.lib.optionals (pkgs.stdenv.isDarwin) [
ocamlPackages.odoc
];
OCAMLRUNPARAM = "b";
};
packages =
let
pkgs = nixpkgs.legacyPackages."x86_64-linux".appendOverlays (
(import ./nix/overlay.nix { })
);
nodeDependencies = (pkgs.pkgsCross.musl64.lib.callPackageWith pkgs ./node.nix {
nix-filter = nix-filter.lib;
}).nodeDependencies;
packages = pkgs.callPackage ./nix {
nix-filter = nix-filter.lib;
inherit nodeDependencies;
};
in
{
server = serverPkg system false;
serverMusl = serverPkg "x86_64-linux" true;
docker = pkgs.dockerTools.buildLayeredImage {
name = "server-reason-react-example";
tag = "0.0.1";
contents = [
# this is required for fly ssh to work
pkgs.dockerTools.fakeNss
pkgs.pkgsStatic.curl
pkgs.pkgsCross.musl64.busybox
pkgs.pkgsStatic.file
];
config = {
# TODO: fly.io doesn't need this, but local docker and other deployments do
#Entrypoint = [
# "${pkgs.pkgsStatic.tini}/bin/tini"
# "--"
#];
Entrypoint = [
"${packages.serverMusl.out}/bin/server"
];
ExposedPorts = {
"8080/tcp" = { };
};
WorkingDir = "/";
Env = [
"SSL_CERT_FILE=${pkgs.cacert.out}/etc/ssl/certs/ca-bundle.crt"
];
};
};
};
}));
}