2015-02-05 08:42:00 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
systemd.coredump = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Enables storing core dumps in systemd.
|
|
|
|
Note that this alone is not enough to enable core dumps. The maximum
|
|
|
|
file size for core dumps must be specified in limits.conf as well. See
|
2018-05-12 15:44:57 +00:00
|
|
|
<option>security.pam.loginLimits</option> and the limits.conf(5)
|
|
|
|
man page (these specify the core dump limits for user login sessions)
|
|
|
|
and <option>systemd.extraConfig</option> (where e.g.
|
|
|
|
<literal>DefaultLimitCORE=1000000</literal> can be specified to set
|
|
|
|
the core dump limit for systemd system-level services).
|
2015-02-05 08:42:00 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
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.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-03-25 16:29:02 +00:00
|
|
|
config = mkMerge [
|
|
|
|
(mkIf config.systemd.coredump.enable {
|
2015-02-05 08:42:00 +00:00
|
|
|
|
2016-07-10 00:45:18 +00:00
|
|
|
systemd.additionalUpstreamSystemUnits = [ "systemd-coredump.socket" "systemd-coredump@.service" ];
|
|
|
|
|
2016-03-25 16:29:02 +00:00
|
|
|
environment.etc."systemd/coredump.conf".text =
|
|
|
|
''
|
|
|
|
[Coredump]
|
|
|
|
${config.systemd.coredump.extraConfig}
|
|
|
|
'';
|
2015-02-05 08:42:00 +00:00
|
|
|
|
2016-03-25 16:29:02 +00:00
|
|
|
# Have the kernel pass core dumps to systemd's coredump helper binary.
|
|
|
|
# From systemd's 50-coredump.conf file. See:
|
|
|
|
# <https://github.com/systemd/systemd/blob/v218/sysctl.d/50-coredump.conf.in>
|
2016-07-10 00:45:18 +00:00
|
|
|
boot.kernel.sysctl."kernel.core_pattern" = "|${pkgs.systemd}/lib/systemd/systemd-coredump %P %u %g %s %t %c %e";
|
2016-03-25 16:29:02 +00:00
|
|
|
})
|
2015-02-05 08:42:00 +00:00
|
|
|
|
2016-03-25 16:29:02 +00:00
|
|
|
(mkIf (!config.systemd.coredump.enable) {
|
|
|
|
boot.kernel.sysctl."kernel.core_pattern" = mkDefault "core";
|
2016-04-14 11:15:20 +00:00
|
|
|
|
|
|
|
systemd.extraConfig =
|
|
|
|
''
|
|
|
|
DefaultLimitCORE=0:infinity
|
|
|
|
'';
|
2016-03-25 16:29:02 +00:00
|
|
|
})
|
|
|
|
];
|
2015-02-05 08:42:00 +00:00
|
|
|
|
|
|
|
}
|