-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathflake.nix
More file actions
179 lines (179 loc) · 6.38 KB
/
Copy pathflake.nix
File metadata and controls
179 lines (179 loc) · 6.38 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
opam-repository = {
url = "github:ocaml/opam-repository";
flake = false;
};
opam-nix.url = "github:tweag/opam-nix";
opam-nix.inputs = {
nixpkgs.follows = "nixpkgs";
opam-repository.follows = "opam-repository";
};
nix-filter.url = "github:numtide/nix-filter";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs:
let
package = "kast";
filter = inputs.nix-filter.lib;
in inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import inputs.nixpkgs { inherit system; };
opam-nix = inputs.opam-nix.lib.${system};
devPackagesQuery = {
# You can add "development" packages here. They will get added to the devShell automatically.
ocaml-lsp-server = "*";
ocamlformat = "*";
ocaml-index = "*";
dune-deps = "*";
odoc = "*";
odig = "*";
utop = "*";
};
query = devPackagesQuery // {
## You can force versions of certain packages here, e.g:
## - force the ocaml compiler to be taken from opam-repository:
ocaml-base-compiler = "*";
## - or force the compiler to be taken from nixpkgs and be a certain version:
# ocaml-system = "4.14.0";
## - or force ocamlfind to be a certain version:
# ocamlfind = "1.9.2";
};
overlay = final: prev: {
# You can add overrides here
${package} = prev.${package}.overrideAttrs (_: {
# Prevent the ocaml dependencies from leaking into dependent environments
doNixSupport = false;
});
memtrace = let
src = builtins.fetchGit {
url = "https://github.com/janestreet/memtrace";
rev = "c86e4fe3e8308e86f066d6c00e4dbc69003ec381";
};
in (opam-nix.buildOpamProject { } "memtrace" src {
ocaml-base-compiler = "*";
}).memtrace;
ppxlib = let
src = builtins.fetchGit {
url = "https://github.com/NathanReb/ppxlib";
rev = "7fa47adcba0261acf6aa39736a9c7d80a70815c7";
};
in (opam-nix.buildOpamProject { } "ppxlib" src {
ocaml-base-compiler = "*";
}).ppxlib;
};
createScope = src:
(opam-nix.buildDuneProject { } package src query).overrideScope
overlay;
devScope = createScope (filter {
root = ./.;
include = [ "dune-workspace" "dune-project" ];
});
# The main package containing the executable
mainScope = createScope (filter {
root = ./.;
include = [ "dune-workspace" "dune-project" "std" "src" ];
});
main = mainScope.${package};
# Packages from devPackagesQuery
devPackages = builtins.attrValues
(pkgs.lib.getAttrs (builtins.attrNames devPackagesQuery) devScope);
memtrace_viewer = let
src = builtins.fetchGit {
url = "https://github.com/kuviman/memtrace_viewer";
rev = "2fadaf8b3dfe4c8f9699ffc17e16052598f691d5";
};
in (opam-nix.buildOpamProject { } "memtrace_viewer" src {
ocaml-base-compiler = "*";
}).memtrace_viewer;
package_json = filter {
root = ./.;
include = [ "package.json" "package-lock.json" ];
};
in {
packages = rec {
default = let
npmDeps = pkgs.importNpmLock.buildNodeModules {
npmRoot = package_json;
nodejs = pkgs.nodejs;
};
in main.overrideAttrs (oa: {
nativeBuildInputs = [ pkgs.nodejs ];
buildPhase = ''
ln -s ${npmDeps}/node_modules ./node_modules
ls -la ./node_modules
export KAST_STD="../lib/std"
${oa.buildPhase}
'';
postFixup = ''
rm -rf $out/lib/ocaml
cp -r std $out/lib/std
'';
});
kast = default;
js-runtime = let
npmDeps = pkgs.importNpmLock.buildNodeModules {
npmRoot = package_json;
nodejs = pkgs.nodejs;
};
in pkgs.stdenv.mkDerivation {
name = "kast-js-runtime";
src = filter {
root = ./src/transpiler/javascript;
include = [ "runtime.ts" "tsconfig.json" ];
};
nativeBuildInputs = [ pkgs.nodejs ];
buildPhase = ''
ln -s ${npmDeps}/node_modules ./node_modules
cp ${package_json}/* .
npm exec tsc
mkdir $out
cp runtime.js $out/runtime.js
'';
};
};
devShells.default = pkgs.mkShell {
inputsFrom = [ main ];
buildInputs = devPackages ++ (with pkgs; [
# (pkgs.writeShellScriptBin "kast" ''
# [ -f kast.log ] && rm kast.log
# tee >(sed -u 's/^/IN /' >> kast.log) \
# | systemd-run --user --scope -p MemoryMax=1G \
# rlwrap dune exec kast -- "$@" \
# | tee >(sed -u 's/^/OUT /' >> kast.log)
# '')
(pkgs.writeShellScriptBin "kast" ''
systemd-run --user --scope -p MemoryMax=5G \
dune exec kast -- "$@"
'')
# (pkgs.writeShellScriptBin "kast" ''
# dune build
# MEMTRACE=lsp-trace.ctf dune exec kast -- "$@"
# # valgrind --leak-check=yes _build/install/default/bin/kast "$@"
# '')
# You can add packages from nixpkgs here
just # look at .justfile
nodejs # for running js output
graphviz # for dep-graph
caddy # serve html
nixfmt-classic # nix formatter
nil # nix lsp
rlwrap
memtrace_viewer
valgrind
prettier
hyperfine
]);
shellHook = ''
echo 'Hello from Kast devshell'
echo ' dont forget to run `just lsp-support` :)'
export OCAML_BACKTRACE=1
export OCAMLRUNPARAM="b,d=10"
export DUNE_CONFIG__GLOBAL_LOCK=disabled
export KAST_STD=$(pwd)/std
'';
};
formatter = pkgs.nixfmt-classic;
});
}