1{ config, lib, pkgs, ... }:
2
3with lib;
4
5{
6
7 options = {
8
9 systemd.coredump = {
10
11 enable = mkOption {
12 default = false;
13 type = types.bool;
14 description = ''
15 Enables storing core dumps in systemd.
16 Note that this alone is not enough to enable core dumps. The maximum
17 file size for core dumps must be specified in limits.conf as well. See
18 <option>security.pam.loginLimits</option> and the limits.conf(5)
19 man page (these specify the core dump limits for user login sessions)
20 and <option>systemd.extraConfig</option> (where e.g.
21 <literal>DefaultLimitCORE=1000000</literal> can be specified to set
22 the core dump limit for systemd system-level services).
23 '';
24 };
25
26 extraConfig = mkOption {
27 default = "";
28 type = types.lines;
29 example = "Storage=journal";
30 description = ''
31 Extra config options for systemd-coredump. See coredump.conf(5) man page
32 for available options.
33 '';
34 };
35 };
36
37 };
38
39 config = mkMerge [
40 (mkIf config.systemd.coredump.enable {
41
42 systemd.additionalUpstreamSystemUnits = [ "systemd-coredump.socket" "systemd-coredump@.service" ];
43
44 environment.etc."systemd/coredump.conf".text =
45 ''
46 [Coredump]
47 ${config.systemd.coredump.extraConfig}
48 '';
49
50 # Have the kernel pass core dumps to systemd's coredump helper binary.
51 # From systemd's 50-coredump.conf file. See:
52 # <https://github.com/systemd/systemd/blob/v218/sysctl.d/50-coredump.conf.in>
53 boot.kernel.sysctl."kernel.core_pattern" = "|${pkgs.systemd}/lib/systemd/systemd-coredump %P %u %g %s %t %c %e";
54 })
55
56 (mkIf (!config.systemd.coredump.enable) {
57 boot.kernel.sysctl."kernel.core_pattern" = mkDefault "core";
58
59 systemd.extraConfig =
60 ''
61 DefaultLimitCORE=0:infinity
62 '';
63 })
64 ];
65
66}