-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
82 lines (74 loc) · 2.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
{
description = "C++ Project Template";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
};
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
perSystem = { config, pkgs, system, ... }: {
devShells.default = pkgs.mkShell {
inherit (config.checks.pre-commit-check) shellHook;
inputsFrom = [ config.packages.attoparsec ];
hardeningDisable = [ "all" ];
};
packages =
let
attoparsec = pkgs.callPackage ./build.nix { };
in
{
inherit attoparsec;
default = config.packages.attoparsec;
attoparsec-clang = attoparsec.override { stdenv = pkgs.clangStdenv; };
attoparsec-gcc = attoparsec.override { stdenv = pkgs.gccStdenv; };
coverage = config.packages.attoparsec.overrideAttrs (_: {
hardeningDisable = [ "all" ];
cmakeBuildType = "Coverage";
postCheck = ''
cmake --build . --target process_coverage
'';
installPhase = ''
cp -r coverage $out
'';
});
};
checks = {
inherit (config.packages)
coverage
attoparsec-clang
attoparsec-gcc
;
pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
hooks = {
clang-format.enable = true;
deadnix.enable = true;
nixpkgs-fmt.enable = true;
statix.enable = true;
};
};
} // pkgs.lib.optionalAttrs (!pkgs.hostPlatform.isDarwin) (
# Sanitizers turned out to be complicated on macOS for now.
let
sansStr = pkgs.lib.concatMapStringsSep " " (x: "-fsanitize=${x}");
toSanitized = _: sans: config.packages.attoparsec.overrideAttrs (_: {
hardeningDisable = [ "all" ];
cmakeBuildType = "Debug";
preConfigure = ''
cmakeFlagsArray+=(
"-DCMAKE_CXX_FLAGS='-fsanitize=undefined ${sansStr sans}'"
)
'';
});
in
builtins.mapAttrs toSanitized {
sanitizer-ub-address = [ "undefined" "address" ];
sanitizer-leak = [ "leak" ];
}
) // pkgs.lib.optionalAttrs (!pkgs.hostPlatform.isDarwin) {
inherit (config.packages) attoparsec-gcc;
};
};
};
}