services: port amdgpu services from private config
This commit is contained in:
		
							
								
								
									
										71
									
								
								modules/services/hardware/amdgpu-fan.nix
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										71
									
								
								modules/services/hardware/amdgpu-fan.nix
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,71 @@ | ||||
| { config, lib, pkgs, ... }: | ||||
|  | ||||
| with lib; | ||||
|  | ||||
| let | ||||
|  | ||||
|   acfg = config.services.amdgpu; | ||||
|   cfg = config.services.amdgpu.fan; | ||||
|  | ||||
| in | ||||
|  | ||||
| { | ||||
|   options.services.amdgpu.fan = { | ||||
|     enable = mkEnableOption "amdgpu-fan"; | ||||
|  | ||||
|     speedMatrix = mkOption { | ||||
|       type = with types; listOf (listOf int); | ||||
|       # Translated from upstream default config. Since it tries to write the | ||||
|       # config if it's not found, we want some kind of default. | ||||
|       default = [ | ||||
|         [ 0 0 ] | ||||
|         [ 30 33 ] | ||||
|         [ 45 50 ] | ||||
|         [ 60 66 ] | ||||
|         [ 65 69 ] | ||||
|         [ 70 75 ] | ||||
|         [ 75 89 ] | ||||
|         [ 80 100 ] | ||||
|       ]; | ||||
|       example = literalExample '' | ||||
|         [ | ||||
|           [ 0 0 ] | ||||
|           [ 40 30 ] | ||||
|           [ 60 50 ] | ||||
|           [ 80 100 ] | ||||
|         ] | ||||
|       ''; | ||||
|       description = '' | ||||
|         A list of temperature-fan speed pairs. The temperature is specified in | ||||
|         degrees celcius, and speed is specified in %. | ||||
|       ''; | ||||
|     }; | ||||
|   }; | ||||
|  | ||||
|   config = mkIf cfg.enable { | ||||
|     assertions = singleton { | ||||
|       assertion = all (speeds: length speeds == 2) cfg.speedMatrix; | ||||
|       message = "services.amdgpu-fan.speedMatrix must be a list of paired lists"; | ||||
|     }; | ||||
|  | ||||
|     environment.etc."amdgpu-fan.yml".text = builtins.toJSON { | ||||
|       speed_matrix = cfg.speedMatrix; | ||||
|       cards = acfg.cards; | ||||
|     }; | ||||
|  | ||||
|     powerManagement.resumeCommands = "${pkgs.systemd}/bin/systemctl try-restart amdgpu-fan"; | ||||
|  | ||||
|     # Translated from the upstream service file. | ||||
|     systemd.services = { | ||||
|       amdgpu-fan = { | ||||
|         description = "amdgpu fan controller"; | ||||
|         wantedBy = [ "default.target" ]; | ||||
|         after = [ "enable-manual-amdgpu-fan.service" ]; | ||||
|         serviceConfig = { | ||||
|           ExecStart = "${pkgs.amdgpu-fan}/bin/amdgpu-fan"; | ||||
|           Restart = "always"; | ||||
|         }; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
| } | ||||
		Reference in New Issue
	
	Block a user