Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nymphium committed May 27, 2022
0 parents commit 3718eff
Show file tree
Hide file tree
Showing 22 changed files with 1,111 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
*.annot
*.cmo
*.cma
*.cmi
*.a
*.o
*.cmx
*.cmxs
*.cmxa

# ocamlbuild working directory
_build/

# ocamlbuild targets
*.byte
*.native

# oasis generated files
setup.data
setup.log

# Merlin configuring file for Vim and Emacs
.merlin

# Dune generated files
*.install

# Local OPAM switch
_opam/

# nix-build out-link
/result*
3 changes: 3 additions & 0 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version=0.20.1
profile=janestreet

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Nymphium

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
OCaml + [Nix](https://nixos.org/manual/nixpkgs/stable/) template
===

# Concepts
Setup *reproducable* and *lightweight* OCaml dev environment with [opam2nix](https://github.com/timbertson/opam2nix).

This template provides OCaml-LSP and ocamlformat for development.

# Setup & Run
Use [direnv](https://direnv.net/) and `dune exec it-is-test`, or run `nix-shell --run "dune exec it-is-test"`

# Add Packages
1. add `pkg` to `depends` (or `depexts`) in `test.opam`,
2. add `pkg` to `testPackages` in `nix/default.nix` if it is for test,
3. run `nix-shell default.nix -A resolve`,
4. reload shell.

4 changes: 4 additions & 0 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(name main)
(public_name it-is-test)
(libraries it-is-test.lib))
1 change: 1 addition & 0 deletions bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let () = Lib.Main.run ()
3 changes: 3 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{ pkgs ? import ./nix/pkgs.nix
, ocamlPackages ? pkgs.callPackage ./nix/ocamlPackages.nix {}}:
pkgs.callPackage ./nix { inherit ocamlPackages; }
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.0)
11 changes: 11 additions & 0 deletions it-is-test.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
opam-version: "2.0"
version: "0.0.0"
depends: [
"dune" {>= "3.0"}
"ocaml" {< "5.0"}
"lwt"
]

build: [
"dune" "build" "@install" "-p" name "-j" jobs
]
4 changes: 4 additions & 0 deletions lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(library
(name lib)
(public_name it-is-test.lib)
(libraries lwt.unix))
2 changes: 2 additions & 0 deletions lib/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let run () =
Lwt_main.run @@ Lwt_io.print "hello"
28 changes: 28 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{ pkgs, lib, fetchFromGitHub, ocamlPackages }:
let
opam2nix = pkgs.callPackage ./opam2nix.nix {
ocamlPackagesOverride = ocamlPackages;
};

src = pkgs.nix-gitignore.gitignoreSource [] ../.;

localPackages =
let contents = builtins.attrNames (builtins.readDir ../.);
in builtins.filter (lib.strings.hasSuffix ".opam") contents;

# package names with {with-test} in opam;
# opam2nix does not support the flag at present.
testPackages = [ "ppx_inline_test" ];

args = {
ocaml = ocamlPackages.ocaml;
selection = ./opam-selection.nix;
inherit src;
};

opam = opam2nix.build args;
resolve = opam2nix.resolve args (localPackages ++ testPackages);
in
{
inherit opam resolve;
}
4 changes: 4 additions & 0 deletions nix/niv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let
sources = import ./sources.nix {};
in
import sources.niv {}
2 changes: 2 additions & 0 deletions nix/ocamlPackages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ pkgs }:
pkgs.ocaml-ng.ocamlPackages_4_13
17 changes: 17 additions & 0 deletions nix/ocamlformat.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{ pkgs, lib, ocamlformat }:
let
ocamlformat_version =
let
ocamlformat_config = lib.strings.splitString "\n" (builtins.readFile ocamlformat);
re = builtins.match "version\s*=\s*(.*)";
version_line = lib.lists.findFirst
(l: builtins.isList (re l))
(throw "no version specified in .ocamlformat")
ocamlformat_config;
version = builtins.elemAt (re version_line) 0;
in
builtins.trace
"detect ocamlformat version: ${version}"
(builtins.replaceStrings ["."] ["_"] version);
in
builtins.getAttr ("ocamlformat_" + ocamlformat_version) pkgs
Loading

0 comments on commit 3718eff

Please sign in to comment.