2018-07-20 22:56:59 +02:00
|
|
|
{ config, lib, ... }:
|
2012-01-12 08:54:09 +01:00
|
|
|
|
2014-04-14 16:26:48 +02:00
|
|
|
with lib;
|
2012-01-12 08:54:09 +01:00
|
|
|
|
2018-05-04 19:33:42 +02:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.powerManagement.scsiLinkPolicy;
|
|
|
|
|
|
|
|
kernel = config.boot.kernelPackages.kernel;
|
|
|
|
|
|
|
|
allowedValues = [
|
|
|
|
"min_power"
|
|
|
|
"max_performance"
|
|
|
|
"medium_power"
|
|
|
|
"med_power_with_dipm"
|
|
|
|
];
|
|
|
|
|
|
|
|
in
|
2015-10-25 18:58:48 +01:00
|
|
|
|
2012-01-12 08:54:09 +01:00
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2012-10-05 05:25:11 +02:00
|
|
|
|
2012-01-12 08:54:09 +01:00
|
|
|
powerManagement.scsiLinkPolicy = mkOption {
|
2015-10-25 18:58:48 +01:00
|
|
|
default = null;
|
2018-05-04 19:33:42 +02:00
|
|
|
type = types.nullOr (types.enum allowedValues);
|
2022-08-03 22:46:41 +02:00
|
|
|
description = lib.mdDoc ''
|
2015-10-25 18:58:48 +01:00
|
|
|
SCSI link power management policy. The kernel default is
|
|
|
|
"max_performance".
|
2022-08-02 17:34:22 +02:00
|
|
|
|
2018-05-04 19:33:42 +02:00
|
|
|
"med_power_with_dipm" is supported by kernel versions
|
|
|
|
4.15 and newer.
|
2012-01-12 08:54:09 +01:00
|
|
|
'';
|
|
|
|
};
|
2012-10-05 05:25:11 +02:00
|
|
|
|
2012-01-12 08:54:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2015-10-25 18:58:48 +01:00
|
|
|
config = mkIf (cfg != null) {
|
2018-05-04 19:33:42 +02:00
|
|
|
|
|
|
|
assertions = singleton {
|
|
|
|
assertion = (cfg == "med_power_with_dipm") -> versionAtLeast kernel.version "4.15";
|
|
|
|
message = "med_power_with_dipm is not supported for kernels older than 4.15";
|
|
|
|
};
|
|
|
|
|
2015-10-25 18:58:48 +01:00
|
|
|
services.udev.extraRules = ''
|
|
|
|
SUBSYSTEM=="scsi_host", ACTION=="add", KERNEL=="host*", ATTR{link_power_management_policy}="${cfg}"
|
|
|
|
'';
|
2012-01-12 08:54:09 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|