summaryrefslogtreecommitdiff
path: root/modules/ocaml.nix
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2021-12-11 17:40:53 +0100
committerQuentin Aristote <quentin@aristote.fr>2021-12-11 17:40:53 +0100
commit010e12fa7d72c7ba709147469a0cc212d62a7d5b (patch)
treee665dc909d90b187dce83357db7bcf69a0779b16 /modules/ocaml.nix
parent3db139457488215714d0147a3c8313d496eb17b2 (diff)
ocaml : add libDirs option
Diffstat (limited to 'modules/ocaml.nix')
-rw-r--r--modules/ocaml.nix44
1 files changed, 34 insertions, 10 deletions
diff --git a/modules/ocaml.nix b/modules/ocaml.nix
index e6a9266..73eba39 100644
--- a/modules/ocaml.nix
+++ b/modules/ocaml.nix
@@ -15,16 +15,29 @@ let
(optional (versionAtLeast cfg.version "4.02") dune_1)) ++ tuaregPackages
++ userPackages;
- ocamlInit = pkgs.writeText "ocamlinit" (''
- let () =
- try Topdirs.dir_directory "${cfg.ocamlPackages.findlib}/lib/ocaml/${cfg.version}/site-lib"
- with Not_found -> ()
- ;;
- #use "topfind";;
- '' + (optionalString cfg.toplevel.list "#list;;")
- + (optionalString cfg.toplevel.thread "#thread;;") + (concatStringsSep "\n"
- (map (pkg: ''#require "${pkg.pname}";;'') userPackages))
- + cfg.toplevel.extraInit);
+ stdlibDir = "${cfg.ocamlPackages.findlib}/lib/ocaml/${cfg.version}/site-lib";
+ ocamlInit = pkgs.writeText "ocamlinit" (
+
+ (concatStringsSep "\n" (map (dir: ''
+ let () = try Topdirs.dir_directory "${dir}"
+ with Not_found -> ();;
+ '') ([ stdlibDir ] ++ cfg.toplevel.libDirs)))
+
+ + ''
+ #use "topfind";;
+ ''
+
+ + (optionalString cfg.toplevel.list "#list;;")
+
+ + (optionalString cfg.toplevel.thread "#thread;;")
+
+ + (concatStringsSep "\n"
+ (map (pkg: ''# require "${pkg.pname}";;'') userPackages))
+
+ + cfg.toplevel.extraInit
+
+ );
+
in {
options.ocaml = {
enable = mkEnableOption { name = "ocaml"; };
@@ -70,6 +83,17 @@ in {
'';
example = [ "owl" "lwt" ];
};
+ libDirs = mkOption {
+ type = types.listOf types.path;
+ default = [ ];
+ description = ''
+ Additional paths from which to load OCaml libraries.
+ '';
+ example = let dollar = "$";
+ in literalExample ''
+ [ ${dollar}{my-package}/lib/ocaml/${dollar}{config.ocaml.version}/site-lib/ ]
+ '';
+ };
# Whether to list loaded packages when launching a top-level.
list = mkEnableOption "#require list;;";
# Whether to enable threading when running a top-level.