feat(host/faunus-ater): systemd services for scsi disk configuration
This commit is contained in:
parent
e188da2c56
commit
358c7fd01a
|
@ -20,6 +20,7 @@ in {
|
||||||
./modules/paperless.nix
|
./modules/paperless.nix
|
||||||
./modules/photoprism.nix
|
./modules/photoprism.nix
|
||||||
./modules/restic.nix
|
./modules/restic.nix
|
||||||
|
./modules/sdparm.nix
|
||||||
./modules/seaweedfs.nix
|
./modules/seaweedfs.nix
|
||||||
./modules/timetagger.nix
|
./modules/timetagger.nix
|
||||||
./modules/trilium.nix
|
./modules/trilium.nix
|
||||||
|
|
68
hosts/faunus-ater/modules/sdparm.nix
Normal file
68
hosts/faunus-ater/modules/sdparm.nix
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
{
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
mkScript = disk: settings:
|
||||||
|
pkgs.writeShellApplication {
|
||||||
|
name = "sdparm-${disk}";
|
||||||
|
runtimeInputs = [pkgs.coreutils pkgs.sdparm];
|
||||||
|
text = let
|
||||||
|
diskPath = "/dev/disk/by-id/${disk}";
|
||||||
|
attrList = builtins.concatStringsSep "," (builtins.attrNames settings);
|
||||||
|
joinWithAssign = key: value: "${key}=${builtins.toString value}";
|
||||||
|
assignmentList = builtins.concatStringsSep "," (lib.mapAttrsToList joinWithAssign settings);
|
||||||
|
in ''
|
||||||
|
echo "=== BEFORE ====================="
|
||||||
|
sdparm --get "${attrList}" "${diskPath}"
|
||||||
|
echo "================================"
|
||||||
|
|
||||||
|
sdparm --set "${assignmentList}" --save "${diskPath}"
|
||||||
|
|
||||||
|
echo "=== AFTER ======================"
|
||||||
|
sdparm --get "${attrList}" "${diskPath}"
|
||||||
|
echo "================================"
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
mkService = disk: settings: {
|
||||||
|
name = "sdparm-${disk}";
|
||||||
|
value = {
|
||||||
|
description = "Configure sdparm settings for SCSI ${disk}";
|
||||||
|
serviceConfig.Type = "oneshot";
|
||||||
|
serviceConfig.ExecStart = "${mkScript disk settings}/bin/sdparm-${disk}";
|
||||||
|
wantedBy = ["multi-user.target"];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
diskConfiguration = let
|
||||||
|
cfg = {
|
||||||
|
# Disable Y Standby
|
||||||
|
STANDBY_Y = 0;
|
||||||
|
# Enable Z Standby
|
||||||
|
STANDBY_Z = 1;
|
||||||
|
# Enable Idle A
|
||||||
|
IDLE_A = 1;
|
||||||
|
# Enable Idle B
|
||||||
|
IDLE_B = 1;
|
||||||
|
# Disable Idle C
|
||||||
|
IDLE_C = 0;
|
||||||
|
# 2 secondes until idle A
|
||||||
|
IACT = 20;
|
||||||
|
# 10 minutes until idle B
|
||||||
|
IBCT = 6000;
|
||||||
|
# 15 minutes until standby
|
||||||
|
SZCT = 9000;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
scsi-35000cca05c71c09c = cfg;
|
||||||
|
scsi-35000cca05c72eb4c = cfg;
|
||||||
|
scsi-35000cca05c730e70 = cfg;
|
||||||
|
scsi-35000cca05c737ba0 = cfg;
|
||||||
|
scsi-35000cca05c73efd4 = cfg;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
# Create systemd services to configure my SCSI drives
|
||||||
|
# to spin down eventually to save some money and noise
|
||||||
|
config.systemd.services = lib.mapAttrs' mkService diskConfiguration;
|
||||||
|
}
|
Loading…
Reference in a new issue