summary refs log tree commit diff
path: root/nixos/modules/system/boot/coredump.nix
blob: 30f367da766634477a1f7a96e536ad1c5082c6c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ 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
          <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).
        '';
      };

      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.
        '';
      };
    };

  };

  config = mkMerge [
    (mkIf config.systemd.coredump.enable {

      systemd.additionalUpstreamSystemUnits = [ "systemd-coredump.socket" "systemd-coredump@.service" ];

      environment.etc."systemd/coredump.conf".text =
        ''
          [Coredump]
          ${config.systemd.coredump.extraConfig}
        '';

      # 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>
      boot.kernel.sysctl."kernel.core_pattern" = "|${pkgs.systemd}/lib/systemd/systemd-coredump %P %u %g %s %t %c %e";
    })

    (mkIf (!config.systemd.coredump.enable) {
      boot.kernel.sysctl."kernel.core_pattern" = mkDefault "core";

      systemd.extraConfig =
        ''
          DefaultLimitCORE=0:infinity
        '';
    })
  ];

}