-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
78 lines (69 loc) · 2.53 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
{
description = "A Nix flake for the ts project.";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
};
outputs = { self, nixpkgs, ... }:
let
forAllSystems = function: nixpkgs.lib.genAttrs [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ] (
system: function system nixpkgs.legacyPackages.${system}
);
overlay = final: prev: {
ts = final.callPackage ./package.nix {};
};
in {
overlays.default = overlay;
packages = forAllSystems (system: pkgs: {
default = pkgs.callPackage ./package.nix {};
});
devShells = forAllSystems (system: pkgs: {
default = pkgs.mkShell {
buildInputs = [
self.packages.${system}.default.buildInputs
];
nativeBuildInputs = [
pkgs.hyperfine
pkgs.include-what-you-use
pkgs.pkg-config
]
++ pkgs.lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) pkgs.gdb
++ pkgs.lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) pkgs.ltrace
++ pkgs.lib.optional (!pkgs.stdenv.hostPlatform.isDarwin) pkgs.valgrind;
shellHook = ''
remove_from_env() {
local env_var_name=$1
shift # Shift the first argument so we can loop over the rest
IFS=' ' read -ra env_var_array <<< "''${!env_var_name}"
for value_to_remove in "$@"; do
for i in "''${!env_var_array[@]}"; do
if [[ "''${env_var_array[i]}" == "$value_to_remove" ]]; then
unset 'env_var_array[i]'
fi
done
done
if [ "''${#env_var_array[@]}" -eq 0 ]; then
unset "$env_var_name"
else
printf -v "$env_var_name" '%s ' "''${env_var_array[@]}"
export "$env_var_name"
fi
}
export ASAN_OPTIONS=abort_on_error=1
export USE_ASAN=1
export DEBUG=1
if [[ "{$DEBUG:-" ]]; then
# There's a better debug experience when _FORTIFY_SOURCE is not set.
# Variables stop being reported as 'optimised out'.
echo "DEBUG build: removing 'fortify fortify3' from \$NIX_HARDENING_ENABLE"
remove_from_env NIX_HARDENING_ENABLE fortify fortify3
fi
${pkgs.lib.optionalString pkgs.stdenv.hostPlatform.isDarwin ''
# I simply have more joy debugging with /usr/bin/clang and
# /usr/bin/lldb on macOS.
export CC=/usr/bin/clang
''}
'';
};
});
};
}