This commit is contained in:
2026-03-14 07:05:56 +01:00
parent c8bb7585ee
commit 9c57ea69f2
8 changed files with 149 additions and 0 deletions

73
ocaml/flake.nix Normal file
View File

@@ -0,0 +1,73 @@
{
description = "OCaml -> JavaScript demo using js_of_ocaml";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs =
{ self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
in
{
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs; [
ocaml
dune_3
ocamlPackages.js_of_ocaml
ocamlPackages.js_of_ocaml-compiler
nodejs
tmux
ocamlPackages.ocaml-lsp
ocamlPackages.ocamlformat
(pkgs.writeShellApplication {
name = "dev";
runtimeInputs = [ dune nodejs tmux ];
text = ''
SESSION=ocaml-js
tmux new-session -d -s "$SESSION"
tmux new-window -t "$SESSION" -n build
tmux send-keys -t "$SESSION:0" "dune build main.bc.js --watch" C-m
tmux new-window -t "$SESSION" -n server
tmux send-keys -t "$SESSION:1" "npx live-server result" C-m
tmux attach -t "$SESSION"
'';
})
];
shellHook = ''
echo "Run 'dev' to start tmux dev environment."
'';
};
packages.${system}.default = pkgs.stdenv.mkDerivation {
pname = "ocaml-js-demo";
version = "0.1";
src = ./.;
nativeBuildInputs = with pkgs; [
ocaml
dune_3
ocamlPackages.js_of_ocaml
ocamlPackages.js_of_ocaml-compiler
ocamlPackages.js_of_ocaml-ppx
];
buildPhase = ''
dune build main.bc.js
'';
installPhase = ''
mkdir -p $out
cp _build/default/main.bc.js $out/
cp index.html $out/
'';
};
};
}