2018-07-20 21:56:59 +01:00
|
|
|
{ config, lib, ... }:
|
2012-01-12 07:54:09 +00:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2012-01-12 07:54:09 +00:00
|
|
|
|
2018-05-04 18:33:42 +01: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 17:58:48 +00:00
|
|
|
|
2012-01-12 07:54:09 +00:00
|
|
|
{
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
2012-10-05 04:25:11 +01:00
|
|
|
|
2012-01-12 07:54:09 +00:00
|
|
|
powerManagement.scsiLinkPolicy = mkOption {
|
2015-10-25 17:58:48 +00:00
|
|
|
default = null;
|
2018-05-04 18:33:42 +01:00
|
|
|
type = types.nullOr (types.enum allowedValues);
|
2022-08-03 21:46:41 +01:00
|
|
|
description = lib.mdDoc ''
|
2015-10-25 17:58:48 +00:00
|
|
|
SCSI link power management policy. The kernel default is
|
|
|
|
"max_performance".
|
2022-08-02 16:34:22 +01:00
|
|
|
|
2018-05-04 18:33:42 +01:00
|
|
|
"med_power_with_dipm" is supported by kernel versions
|
|
|
|
4.15 and newer.
|
2012-01-12 07:54:09 +00:00
|
|
|
'';
|
|
|
|
};
|
2012-10-05 04:25:11 +01:00
|
|
|
|
2012-01-12 07:54:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2015-10-25 17:58:48 +00:00
|
|
|
config = mkIf (cfg != null) {
|
2018-05-04 18:33:42 +01: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 17:58:48 +00:00
|
|
|
services.udev.extraRules = ''
|
|
|
|
SUBSYSTEM=="scsi_host", ACTION=="add", KERNEL=="host*", ATTR{link_power_management_policy}="${cfg}"
|
|
|
|
'';
|
2012-01-12 07:54:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|