Skip to content

Commit f6a2e2f

Browse files
committed
Use crashpad
1 parent f2fc17a commit f6a2e2f

File tree

8 files changed

+69
-8
lines changed

8 files changed

+69
-8
lines changed

packaging/dependencies.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ scope: {
148148
idnSupport = !stdenv.hostPlatform.isStatic;
149149
};
150150

151-
sentry-native = pkgs.sentry-native.override {
151+
sentry-native = (pkgs.callPackage ./sentry-native.nix { }).override {
152152
# Avoid having two curls in our closure.
153153
inherit (scope) curl;
154154
};

packaging/sentry-native.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
lib,
3+
stdenv,
4+
fetchgit,
5+
cmake,
6+
curl,
7+
pkg-config,
8+
}:
9+
10+
stdenv.mkDerivation rec {
11+
pname = "sentry-native";
12+
version = "0.13.5";
13+
14+
src = fetchgit {
15+
url = "https://github.com/getsentry/sentry-native";
16+
tag = version;
17+
hash = "sha256-vDBI6lB1DMLleAgRCfsHvTSdtmXOzvJSaNAt+NwOd3c=";
18+
fetchSubmodules = true;
19+
};
20+
21+
nativeBuildInputs = [
22+
cmake
23+
pkg-config
24+
];
25+
26+
buildInputs = [
27+
curl
28+
];
29+
30+
cmakeBuildType = "RelWithDebInfo";
31+
32+
cmakeFlags = [ ];
33+
34+
outputs = [
35+
"out"
36+
"dev"
37+
];
38+
}

src/nix/main.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,14 +384,18 @@ void mainWrapped(int argc, char ** argv)
384384
bool sentryEnabled = false;
385385

386386
#if HAVE_SENTRY
387-
if (getEnv("NIX_DISABLE_SENTRY").value_or("") != "1") {
387+
auto sentryEndpoint =
388+
getEnv("NIX_SENTRY_ENDPOINT")
389+
.value_or(
390+
"https://ca42fa4b6b08ae1caf3d96b998af6bac@o4506062689927168.ingest.us.sentry.io/4511151087878144");
391+
if (sentryEndpoint != "") {
388392
sentry_options_t * options = sentry_options_new();
389-
sentry_options_set_dsn(
390-
options, "https://ca42fa4b6b08ae1caf3d96b998af6bac@o4506062689927168.ingest.us.sentry.io/4511151087878144");
393+
sentry_options_set_dsn(options, sentryEndpoint.c_str());
391394
sentry_options_set_database_path(options, (getCacheDir() / "sentry").string().c_str());
392395
sentry_options_set_release(options, fmt("nix@%s", determinateNixVersion).c_str());
393396
sentry_options_set_traces_sample_rate(options, 0);
394397
sentry_options_set_auto_session_tracking(options, false);
398+
sentry_options_set_handler_path(options, CRASHPAD_HANDLER_PATH);
395399
sentry_init(options);
396400
sentryEnabled = true;
397401
}

src/nix/meson.build

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ configdata.set_quoted('NIX_MAN_DIR', mandir)
5252

5353
sentry_required = get_option('sentry')
5454
configdata.set('HAVE_SENTRY', sentry_required.enabled().to_int())
55+
if sentry_required.enabled()
56+
crashpad_handler_path = get_option('crashpad-handler')
57+
assert(
58+
crashpad_handler_path != '',
59+
'crashpad-handler path must be set when sentry is enabled',
60+
)
61+
configdata.set_quoted('CRASHPAD_HANDLER_PATH', crashpad_handler_path)
62+
endif
5563

5664
config_priv_h = configure_file(
5765
configuration : configdata,

src/nix/meson.options

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@ option(
1414
value : 'auto',
1515
description : 'Enable Sentry crash reporting',
1616
)
17+
18+
option(
19+
'crashpad-handler',
20+
type : 'string',
21+
value : '',
22+
description : 'Path to the crashpad_handler binary (required when sentry is enabled)',
23+
)

src/nix/package.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ mkMesonExecutable (finalAttrs: {
8383

8484
mesonFlags = [
8585
(lib.mesonEnable "sentry" enableSentry)
86-
];
86+
]
87+
++ lib.optional enableSentry (
88+
lib.mesonOption "crashpad-handler" "${sentry-native}/bin/crashpad_handler"
89+
);
8790

8891
postInstall = lib.optionalString stdenv.hostPlatform.isStatic ''
8992
mkdir -p $out/nix-support

tests/functional/common/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
: "${test_nix_conf_dir?}" "${test_nix_conf?}"
55

66
# Don't upload crashes from tests to Sentry.
7-
export NIX_DISABLE_SENTRY=1
7+
export NIX_SENTRY_ENDPOINT=
88

99
if isTestOnNixOS; then
1010

tests/functional/sentry.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
source common.sh
44

5-
unset NIX_DISABLE_SENTRY
5+
# This doesn't actually work, but it prevents sentry from uploading for real.
6+
export NIX_SENTRY_ENDPOINT=file://$TEST_ROOT/sentry-endpoint
67

78
ulimit -c 0
89

@@ -20,7 +21,7 @@ for type in segfault assert logic-error; do
2021

2122
[[ -e $sentryDir/last_crash ]]
2223

23-
envelopes=("$sentryDir"/*.run/*.envelope)
24+
envelopes=("$sentryDir"/pending/*.dmp)
2425
if [[ ! -e "${envelopes[0]}" ]]; then
2526
fail "No crash dump found in $sentryDir after crash"
2627
fi

0 commit comments

Comments
 (0)