diff --git a/flake.nix b/flake.nix index fc532c5cd..f131afcd5 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; diff --git a/templates/simple/.gitignore b/templates/simple/.gitignore new file mode 100644 index 000000000..b86e1533f --- /dev/null +++ b/templates/simple/.gitignore @@ -0,0 +1,2 @@ +_build +result \ No newline at end of file diff --git a/templates/simple/.ocamlformat b/templates/simple/.ocamlformat new file mode 100644 index 000000000..e69de29bb diff --git a/templates/simple/dune-project b/templates/simple/dune-project new file mode 100644 index 000000000..37f995d64 --- /dev/null +++ b/templates/simple/dune-project @@ -0,0 +1 @@ +(lang dune 3.0) diff --git a/templates/simple/flake.nix b/templates/simple/flake.nix new file mode 100644 index 000000000..74422fd4d --- /dev/null +++ b/templates/simple/flake.nix @@ -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 = { + inherit (pkgs.ocamlPackages.callPackage ./nix { + inherit nix-filter; + doCheck = true; + }) package; + }; + + devShells = { + default = pkgs.mkShell { + inputsFrom = with self.packages.${system}; [ + package + ]; + + nativeBuildInputs = with pkgs.ocamlPackages; [ + ocaml + dune + + ocaml-lsp + + ocamlformat + dune-release + odoc + ]; + }; + }; + }); +} diff --git a/templates/simple/nix/default.nix b/templates/simple/nix/default.nix new file mode 100644 index 000000000..dc9a11b0c --- /dev/null +++ b/templates/simple/nix/default.nix @@ -0,0 +1,49 @@ +{ pkgs +, stdenv +, lib +, nix-filter +, ocamlPackages +, static ? false +, doCheck +}: +with ocamlPackages; { + package = buildDunePackage { + pname = "package"; + 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. + ../package.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; + }; + }; +} diff --git a/templates/simple/package.opam b/templates/simple/package.opam new file mode 100644 index 000000000..e69de29bb diff --git a/templates/simple/src/bin/dune b/templates/simple/src/bin/dune new file mode 100644 index 000000000..995b241cb --- /dev/null +++ b/templates/simple/src/bin/dune @@ -0,0 +1,4 @@ +(executable + (name main) + (public_name package) + (libraries package)) diff --git a/templates/simple/src/bin/main.ml b/templates/simple/src/bin/main.ml new file mode 100644 index 000000000..216e2c5aa --- /dev/null +++ b/templates/simple/src/bin/main.ml @@ -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 () \ No newline at end of file diff --git a/templates/simple/src/lib/dune b/templates/simple/src/lib/dune new file mode 100644 index 000000000..74423e2eb --- /dev/null +++ b/templates/simple/src/lib/dune @@ -0,0 +1,3 @@ +(library + (name package) + (public_name package)) diff --git a/templates/simple/src/lib/package.ml b/templates/simple/src/lib/package.ml new file mode 100644 index 000000000..455045d9c --- /dev/null +++ b/templates/simple/src/lib/package.ml @@ -0,0 +1 @@ +let add a b = a + b \ No newline at end of file diff --git a/templates/simple/test/dune b/templates/simple/test/dune new file mode 100644 index 000000000..a52339956 --- /dev/null +++ b/templates/simple/test/dune @@ -0,0 +1,3 @@ +(test + (name test) + (libraries alcotest package)) diff --git a/templates/simple/test/test.ml b/templates/simple/test/test.ml new file mode 100644 index 000000000..2347d42aa --- /dev/null +++ b/templates/simple/test/test.ml @@ -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 ]) ]