-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
134 lines (128 loc) · 4.05 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
{
inputs = {
opam-nix.url = "github:tweag/opam-nix";
flake-utils.follows = "opam-nix/flake-utils";
nixpkgs.follows = "opam-nix/nixpkgs";
waq-external-repo = {
url = "github:ushitora-anqou/waq-external-repo";
flake = false;
};
};
outputs = {
self,
nixpkgs,
flake-utils,
opam-nix,
waq-external-repo,
} @ inputs:
flake-utils.lib.eachDefaultSystem (
system: let
package = "waq";
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.lib;
on = opam-nix.lib.${system};
devPackagesQuery = {
ocaml-lsp-server = "*";
utop = "*";
ocamlformat = let
# read .ocamlformat
# cf. https://nymphium.github.io/2023/05/06/purely-functioinal-ocaml-development.html
ocamlformatConfig = lib.strings.splitString "\n" (builtins.readFile ./.ocamlformat);
re = builtins.match "version[[:space:]]*=[[:space:]]*([^[:space:]]*)[[:space:]]*$";
versionLine =
lib.lists.findFirst
(l: builtins.isList (re l))
(throw "no version specified in .ocamlformat")
ocamlformatConfig;
version = builtins.elemAt (re versionLine) 0;
in
version;
};
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 = "*";
## - or force ocamlfind to be a certain version:
# ocamlfind = "1.9.2";
};
src = with builtins;
filterSource (
path: type:
!((type == "directory")
&& elem (baseNameOf path) [
".github"
"e2e"
"test"
"Makefile"
])
)
./.;
scope =
on.buildOpamProject' {
repos = [on.opamRepository waq-external-repo];
resolveArgs = {
with-test = true;
with-doc = true;
};
}
src
query;
overlay = final: prev:
(
# disable library's test and doc
# cf. https://nymphium.github.io/2023/05/06/purely-functioinal-ocaml-development.html
with builtins;
mapAttrs
(p: _:
if hasAttr "passthru" prev.${p} && hasAttr "pkgdef" prev.${p}.passthru
then
prev.${p}.overrideAttrs (_: {
opam__with_test = "false";
opam__with_doc = "false";
})
else prev.${p})
prev
)
// {
# You can add overrides here
${package} = prev.${package}.overrideAttrs (_: {
# Prevent the ocaml dependencies from leaking into dependent environments
doNixSupport = false;
removeOcamlReferences = true;
});
};
scope' = scope.overrideScope overlay;
# The main package containing the executable
main = scope'.${package};
# Packages from devPackagesQuery
devPackages = builtins.attrValues (pkgs.lib.getAttrs (builtins.attrNames devPackagesQuery) scope');
in {
formatter = pkgs.alejandra;
legacyPackages = scope';
packages = {
default = main;
docker = pkgs.callPackage nix/docker.nix {
waq = main;
};
};
devShells.default = pkgs.mkShell {
inputsFrom = [main];
buildInputs =
devPackages
++ (with pkgs; [
# For e2e tests
docker
jq
kind
kubectl
kubernetes-helm
(callPackage ./nix/kneesocks.nix {})
]);
};
}
);
}