Skip to content

Commit deee356

Browse files
committed
Add simple template
1 parent d18f7ad commit deee356

File tree

13 files changed

+142
-4
lines changed

13 files changed

+142
-4
lines changed

flake.nix

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,22 @@
3838
} // attrs);
3939
in
4040
/*
41-
You might read
42-
https://nixos.org/manual/nixpkgs/stable/#sec-overlays-argument and
43-
want to change this but because of how we're doing overlays we will
44-
be overriding any extraOverlays if we don't use `appendOverlays`
41+
You might read
42+
https://nixos.org/manual/nixpkgs/stable/#sec-overlays-argument and
43+
want to change this but because of how we're doing overlays we will
44+
be overriding any extraOverlays if we don't use `appendOverlays`
4545
*/
4646
pkgs.appendOverlays extraOverlays;
4747

4848
overlays.default = final: prev: overlay final prev;
49+
50+
templates.simple = {
51+
description =
52+
"Simple setup for ocaml development";
53+
path = ./templates/simple;
54+
};
55+
56+
templates.default = self.templates.simple;
4957
}
5058
(flake-utils.lib.eachDefaultSystem (system: {
5159
legacyPackages = self.makePkgs { inherit system; };

templates/simple/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_build
2+
result

templates/simple/.ocamlformat

Whitespace-only changes.

templates/simple/dune-project

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 3.0)

templates/simple/flake.nix

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
nixConfig = {
3+
extra-substituters = "https://ocaml.nix-cache.com";
4+
extra-trusted-public-keys = "ocaml.nix-cache.com-1:/xI2h2+56rwFfKyyFVbkJSeGqSIYMC/Je+7XXqGKDIY=";
5+
};
6+
7+
inputs = {
8+
nixpkgs.url = "github:nix-ocaml/nix-overlays";
9+
flake-utils.url = "github:numtide/flake-utils";
10+
flake-utils.follows = "nixpkgs/flake-utils";
11+
nix-filter.url = "github:numtide/nix-filter";
12+
};
13+
14+
outputs = { self, nixpkgs, flake-utils, nix-filter }:
15+
flake-utils.lib.eachDefaultSystem (system:
16+
let pkgs = nixpkgs.legacyPackages.${system}; in
17+
{
18+
packages = {
19+
inherit (pkgs.ocamlPackages.callPackage ./nix {
20+
inherit nix-filter;
21+
doCheck = true;
22+
}) package;
23+
};
24+
25+
devShells = {
26+
default = pkgs.mkShell {
27+
inputsFrom = with self.packages.${system}; [
28+
package
29+
];
30+
31+
nativeBuildInputs = with pkgs.ocamlPackages; [
32+
ocaml
33+
dune
34+
35+
ocaml-lsp
36+
37+
ocamlformat
38+
dune-release
39+
odoc
40+
];
41+
};
42+
};
43+
});
44+
}

templates/simple/nix/default.nix

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
{ pkgs
2+
, stdenv
3+
, lib
4+
, nix-filter
5+
, ocamlPackages
6+
, static ? false
7+
, doCheck
8+
}:
9+
with ocamlPackages; {
10+
package = buildDunePackage {
11+
pname = "package";
12+
version = "1.0.0";
13+
14+
src = with nix-filter.lib;
15+
filter {
16+
# Root of the project relative to this file
17+
root = ./..;
18+
# If no include is passed, it will include all the paths.
19+
include = [
20+
# Include the "src" path relative to the root.
21+
"src"
22+
"test"
23+
# Include this specific path. The path must be under the root.
24+
../package.opam
25+
../dune-project
26+
];
27+
};
28+
29+
checkInputs = [
30+
# Put test dependencies here
31+
alcotest
32+
];
33+
34+
propagatedBuildInputs = [
35+
# Put dependencies here if you're creating a library
36+
];
37+
38+
buildInputs = [
39+
# Put build-time dependencies here
40+
];
41+
42+
inherit doCheck;
43+
44+
meta = {
45+
description = "Describe your project here";
46+
# license = stdenv.lib.licenses.bsd3;
47+
};
48+
};
49+
}

templates/simple/package.opam

Whitespace-only changes.

templates/simple/src/bin/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(executable
2+
(name main)
3+
(public_name package)
4+
(libraries package))

templates/simple/src/bin/main.ml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let main () =
2+
print_string "First number: ";
3+
let first = read_line () |> int_of_string_opt in
4+
print_string "Second number: ";
5+
let second = read_line () |> int_of_string_opt in
6+
let output =
7+
match (first, second) with
8+
| None, Some _ -> "First input is not a number"
9+
| Some _, None -> "Second input is not a number"
10+
| None, None -> "Neither of the inputs is a number"
11+
| Some f, Some s ->
12+
let number = Package.add f s in
13+
Printf.sprintf "%i + %i = %i" f s number
14+
in
15+
print_endline output
16+
;;
17+
18+
main ()

templates/simple/src/lib/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(library
2+
(name package)
3+
(public_name package))

0 commit comments

Comments
 (0)