-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
145 lines (134 loc) · 4.19 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
{
# This is based on an example, if more is required of the flake
# look at the [source](https://github.com/brendanzab/ocaml-flake-example)
description = "nix flake for building wasp";
# Flake dependency specification
#
# To update all flake inputs:
#
# $ nix flake update --commit-lockfile
#
# To update individual flake inputs:
#
# $ nix flake lock --update-input <input> ... --commit-lockfile
#
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
# 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 }:
# Construct an output set that supports a number of default systems
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {inherit system;};
# OCaml packages available on nixpkgs
# This functions as a switch
ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_14;
# Library functions from nixpkgs
lib = pkgs.lib;
my_python3_packages = p: [
# wasp-c
p.pycparser
];
my_python3 = pkgs.python310.withPackages my_python3_packages;
# Filtered sources (prevents unecessary rebuilds)
sources = {
ocaml = nix-filter.lib {
root = ./.;
include = [
".ocamlformat"
"dune-project"
(nix-filter.lib.inDirectory "wasp")
];
};
};
in
{
# Exposed packages that can be built or run with `nix build` or
# `nix run` respectively:
#
# $ nix build .#<name>
# $ nix run .#<name> -- <args?>
#
packages = {
# The package that will be built or run by default. For example:
#
# $ nix build
# $ nix run -- <args?>
#
default = self.packages.${system}.wasp;
wasp = ocamlPackages.buildDunePackage {
pname = "wasp";
version = "0.2.0";
duneVersion = "3";
src = sources.ocaml;
strictDeps = true;
nativeBuildInputs = [
pkgs.z3
];
buildInputs = [
ocamlPackages.batteries
ocamlPackages.base
ocamlPackages.core
ocamlPackages.ppx_inline_test
ocamlPackages.z3
];
preBuild = ''
cd wasp
'';
};
};
# Development shells
#
# $ nix develop .#<name>
# $ nix develop .#<name> --command dune build @test
#
# [Direnv](https://direnv.net/) is recommended for automatically loading
# development environments in your shell. For example:
#
# $ echo "use flake" > .envrc && direnv allow
# $ dune build @test
#
devShells = {
default = pkgs.mkShell {
# Development tools
packages = with pkgs; [
# Source file formatting
ocamlformat
# For `dune build --watch ...`
fswatch
# For `dune build @doc`
ocamlPackages.odoc
# OCaml editor support
ocamlPackages.ocaml-lsp
# Nicely formatted types on hover
ocamlPackages.ocamlformat-rpc-lib
# Fancy REPL thing
ocamlPackages.utop
# wasp and wasp-c stuff
gnumake
my_python3
libcxx
gmp
clang_10
llvmPackages_10.bintools-unwrapped
wabt
];
# Tools from packages
inputsFrom = [
self.packages.${system}.wasp
];
shellHook = ''
# To allow executing wasp wihtout specifying full path
export PATH="$PWD/wasp/_build/install/default/bin:$PATH"
# To allow executing wasp-c wihtout specifying full path
# libc.a breakes some things
# export PATH="$PATH:$PWD/wasp-c/bin"
'';
};
};
});
}