Skip to content

Commit

Permalink
Add nix support
Browse files Browse the repository at this point in the history
  • Loading branch information
Nymphium committed May 3, 2022
1 parent aecb432 commit 1df3795
Show file tree
Hide file tree
Showing 8 changed files with 1,658 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nix/opam-selection.nix linguist-generated=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ setup.log
_opam

# End of https://www.toptal.com/developers/gitignore/api/ocaml

# nix-build artifacts
/result*
10 changes: 10 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {}
, ocamlPackages ? import ./nix/ocamlPackages.nix { inherit pkgs; }
, opam2nix ?
pkgs.callPackage ./nix/opam2nix.nix {
inherit pkgs;
ocamlPackagesOverride = ocamlPackages;

} }:

pkgs.callPackage ./nix { inherit ocamlPackages opam2nix; }
50 changes: 50 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{ pkgs, lib, stdenv, ocamlPackages, opam2nix }:
let
inherit (lib) strings;

source =
let ignores = pkgs.lib.strings.fileContents ../.gitignore;
in pkgs.nix-gitignore.gitignoreSourcePure ignores ../.;

localPackages =
let contents = builtins.attrNames (builtins.readDir ../.);
in builtins.filter (strings.hasSuffix ".opam") contents;

src = pkgs.lib.listToAttrs (builtins.map (name:
{ name = strings.removeSuffix ".opam" name; value = source; }) localPackages);

args = {
inherit (ocamlPackages) ocaml;
inherit src;
selection = ./opam-selection.nix;
};

opam-selection = opam2nix.build (args // {
override = { pkgs, ... }: {
camlpdf = super: super.overrideAttrs (attrs: {
buildInputs = (attrs.buildInputs or []) ++ [ pkgs.which ];
});
easy-format = super: super.overrideAttrs (_: {
buildPhase = ''
dune build -p easy-format @install
'';
});
};
});

resolve = opam2nix.resolve (args // {
repo = {
key = "satysfi-external";
url = "gfngfn/satysfi-external-repo";
};
}) localPackages;


in (builtins.listToAttrs (builtins.map (fname:
let packageName = strings.removeSuffix ".opam" fname;
in {
name = packageName;
value = builtins.getAttr packageName opam-selection;
}) localPackages)) // {
inherit resolve opam-selection;
}
2 changes: 2 additions & 0 deletions nix/ocamlPackages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.ocaml-ng.ocamlPackages_4_13
Loading

0 comments on commit 1df3795

Please sign in to comment.