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> as well as the limits.conf(5)
19 man page.
20 '';
21 };
22
23 extraConfig = mkOption {
24 default = "";
25 type = types.lines;
26 example = "Storage=journal";
27 description = ''
28 Extra config options for systemd-coredump. See coredump.conf(5) man page
29 for available options.
30 '';
31 };
32 };
33
34 };
35
36 config = mkMerge [
37 (mkIf config.systemd.coredump.enable {
38
39 systemd.additionalUpstreamSystemUnits = [ "systemd-coredump.socket" "systemd-coredump@.service" ];
40
41 environment.etc."systemd/coredump.conf".text =
42 ''
43 [Coredump]
44 ${config.systemd.coredump.extraConfig}
45 '';
46
47 # Have the kernel pass core dumps to systemd's coredump helper binary.
48 # From systemd's 50-coredump.conf file. See:
49 # <https://github.com/systemd/systemd/blob/v218/sysctl.d/50-coredump.conf.in>
50 boot.kernel.sysctl."kernel.core_pattern" = "|${pkgs.systemd}/lib/systemd/systemd-coredump %P %u %g %s %t %c %e";
51 })
52
53 (mkIf (!config.systemd.coredump.enable) {
54 boot.kernel.sysctl."kernel.core_pattern" = mkDefault "core";
55
56 systemd.extraConfig =
57 ''
58 DefaultLimitCORE=0:infinity
59 '';
60 })
61 ];
62
63}