2022-03-13 15:57:35 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
utils,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
2022-03-17 23:16:30 +01:00
|
|
|
cfg = config.systemd.coredump;
|
2022-03-13 15:57:35 +01:00
|
|
|
systemd = config.systemd.package;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
systemd.coredump.enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether core dumps should be processed by
|
|
|
|
{command}`systemd-coredump`. If disabled, core dumps
|
|
|
|
appear in the current directory of the crashing process.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.coredump.extraConfig = mkOption {
|
|
|
|
default = "";
|
|
|
|
type = types.lines;
|
|
|
|
example = "Storage=journal";
|
|
|
|
description = ''
|
|
|
|
Extra config options for systemd-coredump. See coredump.conf(5) man page
|
|
|
|
for available options.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-08-01 09:44:29 -07:00
|
|
|
config = mkMerge [
|
2022-03-13 15:57:35 +01:00
|
|
|
|
2022-08-01 09:44:29 -07:00
|
|
|
(mkIf cfg.enable {
|
|
|
|
systemd.additionalUpstreamSystemUnits = [
|
|
|
|
"systemd-coredump.socket"
|
|
|
|
"systemd-coredump@.service"
|
|
|
|
];
|
2022-03-13 15:57:35 +01:00
|
|
|
|
2022-08-01 09:44:29 -07:00
|
|
|
environment.etc = {
|
|
|
|
"systemd/coredump.conf".text = ''
|
|
|
|
[Coredump]
|
|
|
|
${cfg.extraConfig}
|
|
|
|
'';
|
|
|
|
|
|
|
|
# install provided sysctl snippets
|
2023-01-29 15:48:47 -05:00
|
|
|
"sysctl.d/50-coredump.conf".source =
|
|
|
|
# Fix systemd-coredump error caused by truncation of `kernel.core_pattern`
|
|
|
|
# when the `systemd` derivation name is too long. This works by substituting
|
|
|
|
# the path to `systemd` with a symlink that has a constant-length path.
|
|
|
|
#
|
|
|
|
# See: https://github.com/NixOS/nixpkgs/issues/213408
|
|
|
|
pkgs.substitute {
|
|
|
|
src = "${systemd}/example/sysctl.d/50-coredump.conf";
|
2024-02-09 04:30:09 +01:00
|
|
|
substitutions = [
|
2024-06-06 18:33:30 +02:00
|
|
|
"--replace-fail"
|
2023-01-29 15:48:47 -05:00
|
|
|
"${systemd}"
|
|
|
|
"${pkgs.symlinkJoin {
|
|
|
|
name = "systemd";
|
|
|
|
paths = [ systemd ];
|
|
|
|
}}"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-08-01 09:44:29 -07:00
|
|
|
"sysctl.d/50-default.conf".source = "${systemd}/example/sysctl.d/50-default.conf";
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.systemd-coredump = {
|
|
|
|
uid = config.ids.uids.systemd-coredump;
|
|
|
|
group = "systemd-coredump";
|
|
|
|
};
|
2023-02-25 22:24:56 -05:00
|
|
|
users.groups.systemd-coredump = { };
|
2022-08-01 09:44:29 -07:00
|
|
|
})
|
|
|
|
|
|
|
|
(mkIf (!cfg.enable) {
|
|
|
|
boot.kernel.sysctl."kernel.core_pattern" = mkDefault "core";
|
|
|
|
})
|
|
|
|
|
|
|
|
];
|
2022-03-13 15:57:35 +01:00
|
|
|
|
|
|
|
}
|