Skip to content

Commit 07adb51

Browse files
committed
init
0 parents  commit 07adb51

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+8052
-0
lines changed

.envrc

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
if ! has nix_direnv_version || ! nix_direnv_version 2.3.0; then
2+
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/2.3.0/direnvrc" "sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8="
3+
fi
4+
use flake

.gitignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.direnv/
2+
_build/
3+
node_modules/
4+
out/
5+
*.install
6+
trace*.json
7+
_coverage/
8+
result
9+
.processes/last_built_at.txt
10+
*.qcow2
11+
*.dump
12+
.processes/

.ocamlformat

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
margin=100

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.PHONY: watch
2+
watch: build
3+
$(MAKE) -j 3 watch-vite run-server watch-build
4+
5+
.PHONY: build
6+
build:
7+
@dune build
8+
9+
.PHONY: watch-build
10+
watch-build:
11+
dune build @default --watch
12+
13+
.PHONY: run-server
14+
run-server:
15+
@watchexec --debounce "100ms" --no-ignore -w .processes/last_built_at.txt -r \
16+
-- "./scripts/start-server.sh"
17+
18+
.PHONY: watch-vite
19+
watch-vite:
20+
./node_modules/.bin/vite --host

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# server-reason-react-example
2+
3+
## Developing
4+
5+
When using direnv with
6+
[nix-direnv](https://github.com/nix-community/nix-direnv), a dev shell using
7+
the flake will automatically be loaded. Otherwise, `nix develop` can be used to
8+
start a shell with all required dependencies.
9+
10+
Run `make watch` to start the server and watch for changes on the backend and frontend.

default.nix

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# This file has been generated by node2nix 1.11.1. Do not edit!
2+
3+
{pkgs ? import <nixpkgs> {
4+
inherit system;
5+
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs_14"}:
6+
7+
let
8+
nodeEnv = import ./node-env.nix {
9+
inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript;
10+
inherit pkgs nodejs;
11+
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
12+
};
13+
in
14+
import ./node-packages.nix {
15+
inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
16+
inherit nodeEnv;
17+
}

dune

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(env
2+
(dev
3+
(flags (:standard -warn-error -A+6+8+9+28)))
4+
(static
5+
(ocamlopt_flags (:standard -O3 -ccopt -static -ccopt -Wl,--no-as-needed)))
6+
(strict
7+
; disabling some warnings that are not useful
8+
; 40 - name-out-of-scope
9+
; 44 - open-shadow-identifier
10+
; 42 - disambiguated-name - 4.00 backward compatibility
11+
; 70 - missing-mli
12+
(flags (:standard -w +A-4-40-42-44-70-45-60 -warn-error +A-4-40-60-70-45)))
13+
(release (ocamlopt_flags (:standard -O3))
14+
))
15+
16+
(dirs :standard \ node_modules \ .direnv)

dune-project

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(lang dune 3.9)
2+
(formatting
3+
(enabled_for ocaml))
4+
5+
(using melange 0.1)
6+
7+
(name server-reason-react-example)
8+
9+
(generate_opam_files true)
10+
11+
(source
12+
(github joprice/server-reason-react-example))
13+
14+
(authors "pricejosephd@gmail.com")
15+
(maintainers "pricejosephd@gmail.com")
16+
(license MIT)
17+
18+
(package
19+
(name server-reason-react-example)
20+
(synopsis "A short synopsis")
21+
(description "A longer description")
22+
(depends ocaml dune)
23+
(tags
24+
(topics "to describe" your project)))
25+

flake.lock

+151
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
{
2+
description = "Melange starter";
3+
4+
inputs = {
5+
nix-filter.url = "github:numtide/nix-filter";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
nixpkgs = {
8+
url = "github:nix-ocaml/nix-overlays";
9+
inputs.flake-utils.follows = "flake-utils";
10+
};
11+
melange = {
12+
url = "github:melange-re/melange";
13+
inputs.nixpkgs.follows = "nixpkgs";
14+
inputs.nix-filter.follows = "nix-filter";
15+
inputs.flake-utils.follows = "flake-utils";
16+
};
17+
};
18+
19+
outputs =
20+
{ self
21+
, nixpkgs
22+
, flake-utils
23+
, melange
24+
, nix-filter
25+
}:
26+
(flake-utils.lib.eachDefaultSystem (system:
27+
let
28+
pkgs = nixpkgs.legacyPackages."${system}".appendOverlays (import ./nix/overlay.nix {
29+
inherit melange;
30+
});
31+
inherit (pkgs) ocamlPackages;
32+
nodeDependencies = (pkgs.lib.callPackageWith pkgs ./node.nix { nix-filter = nix-filter.lib; }).nodeDependencies;
33+
serverPkg = system: static:
34+
let
35+
pkgs = nixpkgs.legacyPackages."${system}".appendOverlays (
36+
(import ./nix/overlay.nix {
37+
inherit melange;
38+
})
39+
);
40+
nodeDependencies = (pkgs.lib.callPackageWith pkgs ./node.nix {
41+
nix-filter = nix-filter.lib;
42+
}).nodeDependencies;
43+
in
44+
(pkgs.callPackage ./nix {
45+
inherit static;
46+
nix-filter = nix-filter.lib;
47+
inherit nodeDependencies;
48+
}).server;
49+
in
50+
rec {
51+
devShells.default = pkgs.mkShell {
52+
SSL_CERT_FILE = "${pkgs.cacert.out}/etc/ssl/certs/ca-bundle.crt";
53+
shellHook = ''
54+
export NODE_PATH=${nodeDependencies}/lib/node_modules
55+
export PATH="${nodeDependencies}/bin:$PATH"
56+
'';
57+
inputsFrom = [ (serverPkg system false) ];
58+
nativeBuildInputs = [
59+
pkgs.nodejs
60+
ocamlPackages.ocaml-lsp
61+
ocamlPackages.reason
62+
ocamlPackages.reason-native.refmterr
63+
ocamlPackages.ocamlformat
64+
pkgs.bintools
65+
pkgs.node2nix
66+
pkgs.watchexec
67+
] ++ pkgs.lib.optionals (pkgs.stdenv.isDarwin) [
68+
ocamlPackages.odoc
69+
];
70+
OCAMLRUNPARAM = "b";
71+
};
72+
packages =
73+
let
74+
pkgs = nixpkgs.legacyPackages."x86_64-linux".appendOverlays (
75+
(import ./nix/overlay.nix {
76+
inherit melange;
77+
})
78+
);
79+
nodeDependencies = (pkgs.pkgsCross.musl64.lib.callPackageWith pkgs ./node.nix {
80+
nix-filter = nix-filter.lib;
81+
}).nodeDependencies;
82+
packages = pkgs.callPackage ./nix {
83+
nix-filter = nix-filter.lib;
84+
inherit nodeDependencies;
85+
};
86+
in
87+
{
88+
server = serverPkg system false;
89+
serverMusl = serverPkg "x86_64-linux" true;
90+
docker = pkgs.dockerTools.buildLayeredImage {
91+
name = "server-reason-react-example";
92+
tag = "0.0.1";
93+
contents = [
94+
# this is required for fly ssh to work
95+
pkgs.dockerTools.fakeNss
96+
pkgs.pkgsStatic.curl
97+
pkgs.pkgsCross.musl64.busybox
98+
pkgs.pkgsStatic.file
99+
];
100+
config = {
101+
# TODO: fly.io doesn't need this, but local docker and other deployments do
102+
#Entrypoint = [
103+
# "${pkgs.pkgsStatic.tini}/bin/tini"
104+
# "--"
105+
#];
106+
Entrypoint = [
107+
"${packages.serverMusl.out}/bin/server"
108+
];
109+
ExposedPorts = {
110+
"8080/tcp" = { };
111+
};
112+
WorkingDir = "/";
113+
Env = [
114+
"SSL_CERT_FILE=${pkgs.cacert.out}/etc/ssl/certs/ca-bundle.crt"
115+
];
116+
};
117+
};
118+
};
119+
}));
120+
}
121+
122+

0 commit comments

Comments
 (0)