diff --git a/flake.nix b/flake.nix index d7bde9477..6d6ba3aee 100644 --- a/flake.nix +++ b/flake.nix @@ -57,6 +57,14 @@ pkgs.appendOverlays extraOverlays; overlays.default = import ./overlay nixpkgs; + + templates.opinionated = { + description = + "Opinionated setup for ocaml development"; + path = ./templates/opinionated; + }; + + templates.default = self.templates.opinionated; } // flake-utils.lib.eachDefaultSystem (system: { legacyPackages = self.makePkgs { inherit system; }; diff --git a/templates/opinionated/.ocamlformat b/templates/opinionated/.ocamlformat new file mode 100644 index 000000000..e69de29bb diff --git a/templates/opinionated/flake.nix b/templates/opinionated/flake.nix new file mode 100644 index 000000000..91baf233c --- /dev/null +++ b/templates/opinionated/flake.nix @@ -0,0 +1,63 @@ +{ + 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"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; + nix-filter.url = "github:numtide/nix-filter"; + }; + + outputs = inputs @ { flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + inputs.treefmt-nix.flakeModule + ]; + systems = [ "x86_64-linux" "aarch64-darwin" ]; + perSystem = + { config + , self' + , inputs' + , pkgs + , system + , ... + }: { + treefmt = { + projectRootFile = "flake.nix"; + programs = { + alejandra.enable = true; + ocamlformat = { + inherit pkgs; + configFile = ./.ocamlformat; + enable = true; + }; + }; + }; + + packages = pkgs.ocamlPackages.callPackage ./nix { + inherit (inputs) nix-filter; + doCheck = true; + }; + + devShells.default = pkgs.mkShell { + inputsFrom = with self'.packages; [ + self'.packages.package + ]; + + packages = with pkgs.ocamlPackages; [ + ocaml + dune + + ocaml-lsp + + ocamlformat + dune-release + odoc + ]; + }; + }; + }; +} diff --git a/templates/opinionated/nix/default.nix b/templates/opinionated/nix/default.nix new file mode 100644 index 000000000..984c889c6 --- /dev/null +++ b/templates/opinionated/nix/default.nix @@ -0,0 +1,49 @@ +{ pkgs +, stdenv +, lib +, nix-filter +, ocamlPackages +, static ? false +, doCheck +, +}: +with ocamlPackages; rec { + 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 + ]; + + propagatedBuildInputs = [ + # Put dependencies here + ]; + + buildInputs = [ + # Put build-time dependencies here + ]; + + inherit doCheck; + + meta = { + description = "Describe your project here"; + # license = stdenv.lib.licenses.bsd3; + }; + }; +}