Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add simple template #884

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -38,14 +38,22 @@
} // attrs);
in
/*
You might read
https://nixos.org/manual/nixpkgs/stable/#sec-overlays-argument and
want to change this but because of how we're doing overlays we will
be overriding any extraOverlays if we don't use `appendOverlays`
You might read
https://nixos.org/manual/nixpkgs/stable/#sec-overlays-argument and
want to change this but because of how we're doing overlays we will
be overriding any extraOverlays if we don't use `appendOverlays`
*/
pkgs.appendOverlays extraOverlays;

overlays.default = final: prev: overlay final prev;

templates.simple = {
description =
"Simple setup for ocaml development";
path = ./templates/simple;
};

templates.default = self.templates.simple;
}
(flake-utils.lib.eachDefaultSystem (system: {
legacyPackages = self.makePkgs { inherit system; };
2 changes: 2 additions & 0 deletions templates/simple/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_build
result
Empty file added templates/simple/.ocamlformat
Empty file.
1 change: 1 addition & 0 deletions templates/simple/dune-project
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 3.8)
Empty file added templates/simple/example.opam
Empty file.
44 changes: 44 additions & 0 deletions templates/simple/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
nixConfig = {
extra-substituters = "https://ocaml.nix-cache.com";
extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY=";
};

inputs = {
nixpkgs.url = "github:nix-ocaml/nix-overlays";
flake-utils.url = "github:numtide/flake-utils";
flake-utils.follows = "nixpkgs/flake-utils";
nix-filter.url = "github:numtide/nix-filter";
};

outputs = { self, nixpkgs, flake-utils, nix-filter }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system}; in
{
packages = {
default = pkgs.callPackage ./nix {
inherit nix-filter;
doCheck = true;
};
};

devShells = {
default = pkgs.mkShell {
inputsFrom = [
self.packages.${system}.default
];

nativeBuildInputs = with pkgs.ocamlPackages; [
ocaml
dune

ocaml-lsp

ocamlformat
dune-release
odoc
];
};
};
});
}
48 changes: 48 additions & 0 deletions templates/simple/nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{ pkgs
, stdenv
, lib
, nix-filter
, ocamlPackages
, static ? false
, doCheck
}:
with ocamlPackages;
buildDunePackage {
pname = "example";
version = "1.0.0";

src = with nix-filter.lib;
filter {
# Root of the project relative to this file
root = ./..;
# If no include is passed, it will include all the paths.
include = [
# Include the "src" path relative to the root.
"src"
"test"
# Include this specific path. The path must be under the root.
../example.opam
../dune-project
];
};

checkInputs = [
# Put test dependencies here
alcotest
];

propagatedBuildInputs = [
# Put dependencies here if you're creating a library
];

buildInputs = [
# Put build-time dependencies here
];

inherit doCheck;

meta = {
description = "Describe your project here";
# license = stdenv.lib.licenses.bsd3;
};
}
4 changes: 4 additions & 0 deletions templates/simple/src/bin/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(executable
(name main)
(public_name example)
(libraries example))
18 changes: 18 additions & 0 deletions templates/simple/src/bin/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
let main () =
print_string "First number: ";
let first = read_line () |> int_of_string_opt in
print_string "Second number: ";
let second = read_line () |> int_of_string_opt in
let output =
match (first, second) with
| None, Some _ -> "First input is not a number"
| Some _, None -> "Second input is not a number"
| None, None -> "Neither of the inputs is a number"
| Some f, Some s ->
let number = Package.add f s in
Printf.sprintf "%i + %i = %i" f s number
in
print_endline output
;;

main ()
3 changes: 3 additions & 0 deletions templates/simple/src/lib/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(library
(name example)
(public_name example))
1 change: 1 addition & 0 deletions templates/simple/src/lib/package.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let add a b = a + b
3 changes: 3 additions & 0 deletions templates/simple/test/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(test
(name test)
(libraries alcotest package))
5 changes: 5 additions & 0 deletions templates/simple/test/test.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
let test_add () = Alcotest.(check int) "adds numbers" 5 (Package.add 2 3)

let () =
let open Alcotest in
run "Package" [ ("numbers", [ test_case "add" `Quick test_add ]) ]