Skip to content

Commit 341cc84

Browse files
2025_09_02
1 parent 7ae7233 commit 341cc84

14 files changed

+622
-47
lines changed

desktop/l/configuration.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,17 @@
3737
./grafana.nix
3838
# clickhouse
3939
./clickhouse-service.nix
40+
# GPU fan control
41+
./gpu-fan-control.nix
42+
# Corsair fan control
43+
./corsair-fan-control.nix
4044
#./docker-compose.nix
4145
./docker-daemon.nix
4246
#./smokeping.nix
4347
#./distributed-builds.nix
4448
#./hyprland.nix
49+
./nginx.nix
50+
./ollama-service.nix
4551
];
4652

4753
boot = {
@@ -67,6 +73,8 @@
6773
# #"nomodeset"
6874
# ];
6975

76+
kernelParams = [ "acpi_enforce_resources=lax" ];
77+
7078
initrd.kernelModules = [
7179
"amdgpu"
7280
];

desktop/l/corsair-fan-control.nix

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#
2+
# Corsair Commander Fan Control Service
3+
#
4+
# This service sets the fan speed for Corsair Commander controlled fans at boot time.
5+
# Uses liquidctl to control the fan speed.
6+
#
7+
8+
{ config, lib, pkgs, ... }:
9+
10+
let
11+
# Configuration - modify these values for your setup
12+
fanNumber = "fan1"; # Change this to control different fans (fan1, fan2, fan3, etc.)
13+
fanSpeed = 100; # Change this to desired fan speed (0-100)
14+
15+
# Script to set fan speed using liquidctl
16+
corsairFanControlScript = pkgs.writeShellScript "corsair-fan-control" ''
17+
#!/bin/sh
18+
set -eu
19+
20+
FAN_NUMBER="${fanNumber}"
21+
FAN_SPEED="${toString fanSpeed}"
22+
23+
echo "Setting Corsair Commander ${fanNumber} speed to ${toString fanSpeed}%"
24+
25+
# Check if liquidctl is available
26+
if ! command -v liquidctl >/dev/null 2>&1; then
27+
echo "Error: liquidctl not found. Please install it first."
28+
exit 1
29+
fi
30+
31+
# Set the fan speed
32+
# Note: fanSpeed is interpolated by Nix, so we use toString to convert the integer to string
33+
if liquidctl --match corsair set "$FAN_NUMBER" speed "$FAN_SPEED"; then
34+
echo "Fan speed set successfully to ${toString fanSpeed}%"
35+
exit 0
36+
else
37+
echo "Failed to set fan speed"
38+
exit 1
39+
fi
40+
'';
41+
42+
in {
43+
44+
systemd.services.corsair-fan-control = {
45+
description = "Set Corsair Commander fan speed at boot";
46+
wantedBy = [ "multi-user.target" ];
47+
after = [ "multi-user.target" "udev.service" ];
48+
49+
serviceConfig = {
50+
Type = "oneshot";
51+
ExecStart = "${corsairFanControlScript}";
52+
RemainAfterExit = true;
53+
StandardOutput = "journal";
54+
StandardError = "journal";
55+
# Run as root since liquidctl needs elevated privileges
56+
User = "root";
57+
Group = "root";
58+
};
59+
};
60+
61+
# Optional: Add a manual service for runtime fan control
62+
systemd.user.services.corsair-fan-control-manual = {
63+
description = "Manual Corsair fan control (user service)";
64+
wantedBy = [ "default.target" ];
65+
66+
serviceConfig = {
67+
Type = "oneshot";
68+
ExecStart = "${corsairFanControlScript}";
69+
RemainAfterExit = true;
70+
StandardOutput = "journal";
71+
StandardError = "journal";
72+
# Note: This will need sudo privileges to work
73+
};
74+
};
75+
76+
}

desktop/l/flake.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

desktop/l/gpu-fan-control.nix

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#
2+
# GPU Fan Control Service
3+
#
4+
# This service sets the fan speed for AMD GPUs at boot time.
5+
# Configure the GPU bus address and desired fan speed below.
6+
#
7+
8+
{ config, lib, pkgs, ... }:
9+
10+
let
11+
# Configuration - modify these values for your setup
12+
gpuBus = "0000:63:00.0"; # Change this to your GPU's bus address
13+
14+
#[nix-shell:~]$ lspci | grep -i radeon
15+
#44:00.0 Display controller: Advanced Micro Devices, Inc. [AMD/ATI] Vega 20 [Radeon Pro VII/Radeon Instinct MI50 32GB]
16+
#63:00.0 VGA compatible controller: Advanced Micro Devices, Inc. [AMD/ATI] Navi 10 [Radeon Pro W5700]
17+
18+
fanSpeedPercent = 50; # Change this to desired fan speed (0-100)
19+
20+
# Calculate the actual PWM value based on percentage
21+
fanSpeedPWM = builtins.toString (fanSpeedPercent * 255 / 100);
22+
23+
# Script to set fan speed
24+
fanControlScript = pkgs.writeShellScript "gpu-fan-control" ''
25+
#!/bin/sh
26+
set -eu
27+
28+
BUS="${gpuBus}"
29+
FAN_SPEED="${fanSpeedPWM}"
30+
31+
echo "Setting GPU fan speed to ${toString fanSpeedPercent}% (PWM: $FAN_SPEED) for bus $BUS"
32+
33+
# Find the GPU device and set fan speed
34+
for dev in /sys/class/drm/card*/device; do
35+
if grep -q "PCI_SLOT_NAME=$BUS" "$dev/uevent" 2>/dev/null; then
36+
echo "Found GPU device at $dev"
37+
38+
# Find the hwmon directory
39+
for hwmon in "$dev"/hwmon/hwmon*; do
40+
if [ -d "$hwmon" ]; then
41+
echo "Found hwmon at $hwmon"
42+
43+
# Check if fan control files exist
44+
if [ -f "$hwmon/pwm1_enable" ] && [ -f "$hwmon/pwm1" ]; then
45+
echo "Setting fan control mode to manual"
46+
echo 1 > "$hwmon/pwm1_enable"
47+
48+
# Get max PWM value
49+
max_pwm=$(cat "$hwmon/pwm1_max" 2>/dev/null || echo 255)
50+
echo "Max PWM: $max_pwm"
51+
52+
# Calculate actual PWM value based on percentage
53+
# Note: fanSpeedPercent is interpolated by Nix as a literal number, so we use it directly in Bash arithmetic
54+
actual_pwm=$(( max_pwm * ${fanSpeedPercent} / 100 ))
55+
echo "Setting PWM to $actual_pwm"
56+
echo "$actual_pwm" > "$hwmon/pwm1"
57+
58+
echo "Fan speed set successfully"
59+
exit 0
60+
else
61+
echo "Fan control files not found in $hwmon"
62+
fi
63+
fi
64+
done
65+
66+
echo "No hwmon directory found for device $dev"
67+
exit 1
68+
fi
69+
done
70+
71+
echo "GPU with bus $BUS not found"
72+
exit 1
73+
'';
74+
75+
in {
76+
77+
systemd.services.gpu-fan-control = {
78+
description = "Set AMD GPU fan speed at boot";
79+
wantedBy = [ "multi-user.target" ];
80+
after = [ "multi-user.target" "udev.service" ];
81+
82+
serviceConfig = {
83+
Type = "oneshot";
84+
ExecStart = "${fanControlScript}";
85+
RemainAfterExit = true;
86+
StandardOutput = "journal";
87+
StandardError = "journal";
88+
};
89+
};
90+
91+
# Optional: Add a manual service for runtime fan control
92+
systemd.user.services.gpu-fan-control-manual = {
93+
description = "Manual GPU fan control (user service)";
94+
wantedBy = [ "default.target" ];
95+
96+
serviceConfig = {
97+
Type = "oneshot";
98+
ExecStart = "${fanControlScript}";
99+
RemainAfterExit = true;
100+
StandardOutput = "journal";
101+
StandardError = "journal";
102+
};
103+
};
104+
105+
}

desktop/l/hardware-configuration.nix

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" ];
1212
boot.initrd.kernelModules = [ ];
13-
boot.kernelModules = [ "kvm-amd" ];
13+
boot.kernelModules = [ "kvm-amd" "nct6775" "it87" "acpi_ec_sensors" ];
1414
boot.extraModulePackages = [ ];
1515

1616
fileSystems."/" =
@@ -38,5 +38,9 @@
3838
# networking.interfaces.enp1s0.useDHCP = lib.mkDefault true;
3939

4040
nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
41+
4142
hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
43+
44+
hardware.i2c.enable = true;
45+
#hardware.sensor.hddtemp.enable = true;
4246
}

0 commit comments

Comments
 (0)