-
-
Notifications
You must be signed in to change notification settings - Fork 186
/
flake.nix
169 lines (156 loc) · 5.04 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
{
description = "Immutable data structures";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixpkgs-unstable;
flake-utils.url = "github:numtide/flake-utils";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
pre-commit-hooks = {
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
flake-compat.follows = "flake-compat";
flake-utils.follows = "flake-utils";
gitignore.follows = "gitignore";
nixpkgs.follows = "nixpkgs";
};
};
arximboldi-cereal-src = {
url = "github:arximboldi/cereal";
flake = false;
};
};
outputs = {
self,
nixpkgs,
flake-utils,
flake-compat,
pre-commit-hooks,
gitignore,
arximboldi-cereal-src,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = nixpkgs.legacyPackages.${system};
withLLVM = drv:
if pkgs.stdenv.isLinux
# Use LLVM for Linux to build fuzzers
then drv.override {stdenv = pkgs.llvmPackages_latest.stdenv;}
# macOS uses LLVM by default
else drv;
arximboldi-cereal = pkgs.callPackage ./nix/cereal.nix {inherit arximboldi-cereal-src;};
persist-inputs = with pkgs; [
spdlog
arximboldi-cereal
xxHash
nlohmann_json
];
in {
checks =
{
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
alejandra.enable = true;
cmake-format.enable = true;
clang-format = {
enable = true;
types_or = pkgs.lib.mkForce ["c" "c++"];
};
};
};
inherit (self.packages.${system}) unit-tests fuzzers-debug;
}
// pkgs.lib.optionalAttrs pkgs.stdenv.isLinux {
unit-tests-valgrind = self.packages.${system}.unit-tests.overrideAttrs (prev: {
nativeBuildInputs = with pkgs; prev.nativeBuildInputs ++ [valgrind];
name = "immer-unit-tests-valgrind";
ninjaFlags = ["tests"];
checkPhase = ''
ctest -D ExperimentalMemCheck
valgrind --quiet --error-exitcode=99 --leak-check=full --errors-for-leak-kinds=all \
--suppressions=./test/extra/persist/valgrind.supp \
./test/extra/persist/persist-tests
'';
});
};
devShells.default = (withLLVM pkgs.mkShell) {
NIX_HARDENING_ENABLE = "";
inputsFrom = [
(import ./shell.nix {
inherit system nixpkgs;
})
];
packages = with pkgs;
[
# for the llvm-symbolizer binary, that allows to show stacks in ASAN and LeakSanitizer.
llvmPackages_latest.bintools-unwrapped
cmake-format
alejandra
just
fzf
starship
]
++ persist-inputs;
shellHook =
self.checks.${system}.pre-commit-check.shellHook
+ "\n"
+ ''
alias j=just
eval "$(starship init bash)"
'';
};
packages = {
immer = let
inherit (gitignore.lib) gitignoreSource;
nixFilter = name: type: !(pkgs.lib.hasSuffix ".nix" name);
srcFilter = src:
pkgs.lib.cleanSourceWith {
filter = nixFilter;
src = gitignoreSource src;
};
in
pkgs.callPackage nix/immer.nix {src = srcFilter ./.;};
default = self.packages.${system}.immer;
fuzzers-debug = (withLLVM self.packages.${system}.immer).overrideAttrs (prev: {
name = "immer-fuzzers";
# Fuzzers should be built with minimal dependencies to use them easily with OSS-Fuzz
buildInputs = with pkgs; [boehmgc];
nativeBuildInputs = with pkgs; [cmake ninja];
dontBuild = false;
dontStrip = true;
# fuzzers target is not built by default
ninjaFlags = ["fuzzers"];
cmakeBuildType = "Debug";
cmakeFlags = [
"-DENABLE_ASAN=ON"
"-Dimmer_BUILD_TESTS=OFF"
"-Dimmer_INSTALL_FUZZERS=ON"
];
});
unit-tests = (withLLVM self.packages.${system}.immer).overrideAttrs (prev: {
name = "immer-unit-tests";
buildInputs = with pkgs; [catch2_3 boehmgc boost fmt] ++ persist-inputs;
nativeBuildInputs = with pkgs; [cmake ninja];
dontBuild = false;
doCheck = true;
# Building fuzzers but not running them, just to ensure they compile
ninjaFlags = ["fuzzers tests"];
checkPhase = ''
ninja test
'';
cmakeFlags = [
"-DCMAKE_BUILD_TYPE=Debug"
"-Dimmer_BUILD_TESTS=ON"
"-Dimmer_BUILD_PERSIST_TESTS=ON"
"-Dimmer_BUILD_EXAMPLES=OFF"
"-DCXX_STANDARD=20"
];
});
};
});
}