ocaml
This commit is contained in:
73
ocaml/flake.nix
Normal file
73
ocaml/flake.nix
Normal 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/
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user