Compare commits

...

2 Commits

Author SHA1 Message Date
nyanloutre d7de965eda flake.lock: Update 2021-10-19 14:31:22 +02:00
nyanloutre 1383d2574d ajout script ipmihddtemp 2021-10-19 14:27:42 +02:00
3 changed files with 87 additions and 12 deletions

View File

@ -2,16 +2,31 @@
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1634327140,
"narHash": "sha256-d5L7oMjUVC6VU0cQMsF0tceAPkmzuAQ51DWBFNChbEQ=",
"owner": "nixos",
"lastModified": 1634551044,
"narHash": "sha256-HOHemrQt3wA7eS5YT8n+X0OdB9+X4O08YUPTrFMBG60=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "83667ff60a88e22b76ef4b0bdf5334670b39c2b6",
"rev": "f001876680c0e32a89bced8d02d2c61250684e17",
"type": "github"
},
"original": {
"owner": "nixos",
"id": "nixpkgs",
"ref": "nixos-21.05",
"type": "indirect"
}
},
"nixpkgs-nyanloutre-pysmart": {
"locked": {
"lastModified": 1634643555,
"narHash": "sha256-Fu0JVScZt0fUqfeo2tsTUcoehtpalBU7+15pxy1Ld+Y=",
"owner": "nyanloutre",
"repo": "nixpkgs",
"rev": "256d8d34f05c8badeaf3ecb615d3af08a4b492d6",
"type": "github"
},
"original": {
"owner": "nyanloutre",
"ref": "pysmart-init",
"repo": "nixpkgs",
"type": "github"
}
@ -20,16 +35,15 @@
"locked": {
"lastModified": 1634436779,
"narHash": "sha256-D/nrXTWpe1bPIjFy85sgiLHYqu+AeaC6v5/+KlA9PRg=",
"owner": "nixos",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9aeeb7574fb784eaf6395f4400705b5f619e6cc3",
"type": "github"
},
"original": {
"owner": "nixos",
"id": "nixpkgs",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
"type": "indirect"
}
},
"nixpkgs_2": {
@ -50,6 +64,7 @@
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"nixpkgs-nyanloutre-pysmart": "nixpkgs-nyanloutre-pysmart",
"nixpkgs-unstable": "nixpkgs-unstable",
"simple-nixos-mailserver": "simple-nixos-mailserver"
}

View File

@ -1,11 +1,12 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-21.05";
nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs.url = "flake:nixpkgs/nixos-21.05";
nixpkgs-unstable.url = "flake:nixpkgs/nixos-unstable";
nixpkgs-nyanloutre-pysmart.url = "github:nyanloutre/nixpkgs/pysmart-init";
simple-nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver/nixos-21.05";
};
outputs = { self, nixpkgs, nixpkgs-unstable, simple-nixos-mailserver }: {
outputs = { self, nixpkgs, nixpkgs-unstable, simple-nixos-mailserver, nixpkgs-nyanloutre-pysmart }: {
nixosConfigurations.loutreos = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
@ -18,6 +19,23 @@
"${nixpkgs-unstable}/nixos/modules/services/audio/navidrome.nix"
simple-nixos-mailserver.nixosModule
./systems/LoutreOS/configuration.nix
({ pkgs, ... }: {
systemd.services.ipmihddtemp = {
description = "IPMI HDD temp fan control";
wantedBy = ["multi-user.target"];
path = with pkgs;[ ipmitool smartmontools ];
serviceConfig = {
ExecStart = with nixpkgs-nyanloutre-pysmart.legacyPackages.x86_64-linux;
let env = python3Packages.python.buildEnv.override {
extraLibs = with python3Packages;[ pysmart ];
ignoreCollisions = true;
};
in "${pkgs.writeShellScriptBin "run.sh" ''
${env}/bin/python ${pkgs.writeScript "ipmihddtemp.py" "${builtins.readFile ./ipmihddtemp.py}"}
''}/bin/run.sh";
};
};
})
];
};

42
ipmihddtemp.py Normal file
View File

@ -0,0 +1,42 @@
import math
import subprocess
import time
from pySMART import DeviceList
MIN_FAN_SPEED = 30
MAX_FAN_SPEED = 100
MIN_HDD_TEMP = 30
MAX_HDD_TEMP = 50
devlist = DeviceList()
# Put fans in full speed mode
subprocess.run(["ipmitool", "raw", "0x30", "0x45", "0x01", "0x01"])
while True:
for device in devlist:
device.update()
# Linear fan speed between MIN_FAN_SPEED and MAX_FAN_SPEED
fan_speed = max(
min(
math.ceil(
MIN_FAN_SPEED
+ (
(MAX_FAN_SPEED - MIN_FAN_SPEED)
* (
(max([x.temperature for x in devlist]) - MIN_HDD_TEMP)
/ (MAX_HDD_TEMP - MIN_HDD_TEMP)
)
)
),
MAX_FAN_SPEED,
),
MIN_FAN_SPEED,
)
subprocess.run(["ipmitool", "raw", "0x30", "0x70", "0x66", "0x01", "0x00", hex(fan_speed)])
time.sleep(10)