From 176e38f6f2fba056343d65cf12ba8f6668bdb497 Mon Sep 17 00:00:00 2001
From: Vincent Laporte <Vincent.Laporte@gmail.com>
Date: Sun, 22 Feb 2015 08:17:52 +0100
Subject: [PATCH] Adds ocaml-cstruct

Cstruct is a library and syntax extension to make it easier to access
C-like structures directly from OCaml. It supports both reading and
writing to these structures, and they are accessed via the Bigarray
module.

Homepage: https://github.com/mirage/ocaml-cstruct
---
 .../ocaml-modules/cstruct/default.nix         | 27 +++++++++++++++++++
 pkgs/top-level/all-packages.nix               |  5 ++++
 2 files changed, 32 insertions(+)
 create mode 100644 pkgs/development/ocaml-modules/cstruct/default.nix

diff --git a/pkgs/development/ocaml-modules/cstruct/default.nix b/pkgs/development/ocaml-modules/cstruct/default.nix
new file mode 100644
index 000000000000..194a852e7ef9
--- /dev/null
+++ b/pkgs/development/ocaml-modules/cstruct/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchzip, ocaml, findlib, sexplib, ocplib-endian, lwt, camlp4 }:
+
+let version = "1.6.0"; in
+
+stdenv.mkDerivation {
+  name = "ocaml-cstruct-${version}";
+
+  src = fetchzip {
+    url = "https://github.com/mirage/ocaml-cstruct/archive/v${version}.tar.gz";
+    sha256 = "09qw3rhfiq2kkns6660p9cwm5610k72md52a04cy91gr6gsig6ic";
+  };
+
+  buildInputs = [ ocaml findlib lwt camlp4 ];
+  propagatedBuildInputs = [ ocplib-endian sexplib ];
+
+  configureFlags = "--enable-lwt";
+
+  createFindlibDestdir = true;
+
+  meta = {
+    description = "Map OCaml arrays onto C-like structs";
+    homepage = https://github.com/mirage/ocaml-cstruct;
+    license = stdenv.lib.licenses.isc;
+    maintainers = with stdenv.lib.maintainers; [ vbgl ];
+    platforms = ocaml.meta.platforms;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 3dd8284bbc93..71d2c6434506 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -3864,6 +3864,11 @@ let
 
     cryptokit = callPackage ../development/ocaml-modules/cryptokit { };
 
+    cstruct = callPackage ../development/ocaml-modules/cstruct {
+      lwt = ocaml_lwt;
+      sexplib = ocaml_sexplib;
+    };
+
     csv = callPackage ../development/ocaml-modules/csv { };
 
     deriving = callPackage ../development/tools/ocaml/deriving { };