Added Raspi 4 Conf

This commit is contained in:
2025-11-26 15:17:08 +01:00
parent bcdb501d4d
commit c66dd11217
3 changed files with 273 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [
(python3.withPackages (ps: [ ps.smbus2 ]))
];
# Fan control service
systemd.services.argon-fan = {
description = "Argon40 Fan Control via I2C";
after = [ "multi-user.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
Restart = "always";
ExecStart = pkgs.writeScript "argon-fan.py" ''
#!${pkgs.python3.withPackages (ps: [ ps.smbus2 ])}/bin/python3
import smbus2
import time
import subprocess
bus = smbus2.SMBus(1)
while True:
try:
# Get temperature
temp_output = subprocess.check_output(['${pkgs.libraspberrypi}/bin/vcgencmd', 'measure_temp']).decode()
temp = float(temp_output.replace("temp=","").replace("'C\n",""))
# Set fan speed based on temperature (0-100)
if temp < 55:
speed = 0
elif temp < 60:
speed = 25
elif temp < 65:
speed = 50
else:
speed = 100
bus.write_byte(0x1a, speed)
print(f"Temp: {temp}°C, Fan: {speed}%")
except Exception as e:
print(f"Error: {e}")
time.sleep(30)
'';
};
};
}