1 { config, lib, pkgs, ... }:
7 cfg = config.hardware.rasdaemon;
11 options.hardware.rasdaemon = {
13 enable = mkEnableOption (lib.mdDoc "RAS logging daemon");
18 description = lib.mdDoc "record events via sqlite3, required for ras-mc-ctl";
21 mainboard = mkOption {
24 description = lib.mdDoc "Custom mainboard description, see {manpage}`ras-mc-ctl(8)` for more details.";
29 # it should default to such values from
30 # /sys/class/dmi/id/board_[vendor|name]
31 # alternatively one can supply a script
32 # that returns the same format as above
34 script = <path to script>
38 # TODO, accept `rasdaemon.labels = " ";` or `rasdaemon.labels = { dell = " "; asrock = " "; };'
43 description = lib.mdDoc "Additional memory module label descriptions to be placed in /etc/ras/dimm_labels.d/labels";
45 # vendor and model may be shown by 'ras-mc-ctl --mainboard'
47 product: To Be Filled By O.E.M.
49 # these labels are names for the motherboard slots
50 # the numbers may be shown by `ras-mc-ctl --error-count`
51 # they are mc:csrow:channel
52 DDR4_A1: 0.2.0; DDR4_B1: 0.2.1;
53 DDR4_A2: 0.3.0; DDR4_B2: 0.3.1;
60 description = lib.mdDoc ''
61 rasdaemon configuration, currently only used for CE PFA
62 for details, read rasdaemon.outPath/etc/sysconfig/rasdaemon's comments
65 # defaults from included config
66 PAGE_CE_REFRESH_CYCLE="24h"
67 PAGE_CE_THRESHOLD="50"
72 extraModules = mkOption {
73 type = types.listOf types.str;
75 description = lib.mdDoc "extra kernel modules to load";
76 example = [ "i7core_edac" ];
79 testing = mkEnableOption (lib.mdDoc "error injection infrastructure");
82 config = mkIf cfg.enable {
86 enable = cfg.mainboard != "";
89 # TODO, handle multiple cfg.labels.brand = " ";
90 "ras/dimm_labels.d/labels" = {
91 enable = cfg.labels != "";
94 "sysconfig/rasdaemon" = {
95 enable = cfg.config != "";
99 environment.systemPackages = [ pkgs.rasdaemon ]
100 ++ optionals (cfg.testing) (with pkgs.error-inject; [
106 boot.initrd.kernelModules = cfg.extraModules
107 ++ optionals (cfg.testing) [
108 # edac_core and amd64_edac should get loaded automatically
109 # i7core_edac may not be, and may not be required, but should load successfully
117 boot.kernelPatches = optionals (cfg.testing) [{
118 name = "rasdaemon-tests";
130 # i tried to set up a group for this
131 # but rasdaemon needs higher permissions?
132 # `rasdaemon: Can't locate a mounted debugfs`
134 # most of this taken from src/misc/
137 description = "the RAS logging daemon";
138 documentation = [ "man:rasdaemon(1)" ];
139 wantedBy = [ "multi-user.target" ];
142 StateDirectory = optionalString (cfg.record) "rasdaemon";
144 ExecStart = "${pkgs.rasdaemon}/bin/rasdaemon --foreground"
145 + optionalString (cfg.record) " --record";
146 ExecStop = "${pkgs.rasdaemon}/bin/rasdaemon --disable";
147 Restart = "on-abort";
149 # src/misc/rasdaemon.service.in shows this:
150 # ExecStartPost = ${pkgs.rasdaemon}/bin/rasdaemon --enable
151 # but that results in unpredictable existence of the database
152 # and everything seems to be enabled without this...
155 ras-mc-ctl = mkIf (cfg.labels != "") {
156 description = "register DIMM labels on startup";
157 documentation = [ "man:ras-mc-ctl(8)" ];
158 wantedBy = [ "multi-user.target" ];
161 ExecStart = "${pkgs.rasdaemon}/bin/ras-mc-ctl --register-labels";
162 RemainAfterExit = true;
168 meta.maintainers = [ maintainers.evils ];