-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathflake.nix
126 lines (108 loc) · 3.57 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# flake taken from github.com/brendanzab/ocaml-flake-example
{
description = "The nixbyexample flake";
inputs = {
# Convenience functions for writing flakes
flake-utils.url = "github:numtide/flake-utils";
# Precisely filter files copied to the nix store
nix-filter.url = "github:numtide/nix-filter";
};
outputs = { self, nixpkgs, flake-utils, nix-filter }:
flake-utils.lib.eachDefaultSystem (system:
let
# Legacy packages that have not been converted to flakes
legacyPackages = nixpkgs.legacyPackages.${system};
# OCaml packages available on nixpkgs
ocamlPackages = legacyPackages.ocamlPackages;
# Library functions from nixpkgs
lib = legacyPackages.lib;
# OCaml source files
ocaml-src = nix-filter.lib.filter {
root = ./tools;
include = [
".ocamlformat"
"dune-project"
"byexample.opam"
(nix-filter.lib.matchExt "opam")
(nix-filter.lib.inDirectory "bin")
(nix-filter.lib.inDirectory "lib")
];
};
# Nix source files
nix-src = nix-filter.lib.filter {
root = ./.;
include = [
(nix-filter.lib.matchExt "nix")
];
};
in
{
# Executed by `nix build .#<name>`
packages = {
# Executed by `nix build .#byexample`
byexample = ocamlPackages.buildDunePackage {
pname = "byexample";
version = "0.1.0";
# Would be nice to use dune 3.x, but the odoc package needs to be
# updated first.
duneVersion = "3";
src = ocaml-src;
outputs = [ "doc" "out" ];
nativeBuildInputs = [
ocamlPackages.odoc
ocamlPackages.yojson
ocamlPackages.jingoo
ocamlPackages.ppx_deri
];
strictDeps = true;
preBuild = ''
dune build ./bin/main.exe
'';
postBuild = ''
echo "building docs"
dune build @doc -p byexample
'';
postInstall = ''
echo "Installing $doc/share/doc/byexample/html"
mkdir -p $doc/share/doc/byexample/html
cp -r _build/default/_doc/_html/* $doc/share/doc/byexample/html
'';
};
# Executed by `nix build`
default = self.packages.${system}.byexample;
};
# Executed by `nix run .#<name> <args?>`
apps = {
# Executed by `nix run .#byexample`
byexample = {
type = "app";
program = "${self.packages.${system}.byexample}/bin/byexample";
};
# Executed by `nix run`
default = self.apps.${system}.byexample;
};
# Used by `nix develop`
devShells = {
default = legacyPackages.mkShell {
# Development tools
packages = [
# Source file formatting
legacyPackages.nixpkgs-fmt
legacyPackages.ocamlformat
# For `dune build --watch ...`
legacyPackages.fswatch
# OCaml editor support
ocamlPackages.ocaml-lsp
# Nicely formatted types on hover
ocamlPackages.ocamlformat-rpc-lib
# Fancy REPL thing
ocamlPackages.utop
];
# Tools from packages
inputsFrom = [
self.packages.${system}.byexample
];
};
};
});
}