feat(systemModules:host): add initial host configuration module
used to define general host configuration, including: - hardware - name - admin - type - role
This commit is contained in:
		
							parent
							
								
									6db577fbf5
								
							
						
					
					
						commit
						7a74befde3
					
				
					 19 changed files with 538 additions and 0 deletions
				
			
		
							
								
								
									
										13
									
								
								system/modules/host/hardware/features/backlight/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								system/modules/host/hardware/features/backlight/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,13 @@ | |||
| { lib, config, ... }: | ||||
| 
 | ||||
| let | ||||
|   features = config.systemModules.host.hardware.features; | ||||
|   inherit (lib) mkIf; | ||||
|   inherit (builtins) elem; | ||||
| in | ||||
| 
 | ||||
| { | ||||
|   config = mkIf (elem "backlight" features) { | ||||
|     hardware.brillo.enable = true; | ||||
|   }; | ||||
| } | ||||
							
								
								
									
										94
									
								
								system/modules/host/hardware/features/battery/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								system/modules/host/hardware/features/battery/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | |||
| 
 | ||||
| { lib, config, pkgs, ... }: | ||||
| 
 | ||||
| let | ||||
|   features = config.systemModules.host.hardware.features; | ||||
|   cfg = config.systemModules.host.hardware.battery; | ||||
|   inherit (lib) mkIf mkDefault mkOption types; | ||||
|   inherit (builtins) elem; | ||||
|   MHz = x: x * 1000; | ||||
| in | ||||
|    | ||||
| { | ||||
|   options.systemModules.host.hardware.battery = { | ||||
|     powersave = { | ||||
|       minFreq = mkOption { | ||||
|         type = types.int; | ||||
|         default = 800; | ||||
|         description = "Minimum frequency for powersave mode in MHz"; | ||||
|       }; | ||||
|       maxFreq = mkOption { | ||||
|         type = types.int; | ||||
|         default = 1100; | ||||
|         description = "Maximum frequency for powersave mode in MHz"; | ||||
|       }; | ||||
|     }; | ||||
|     performance = { | ||||
|       minFreq = mkOption { | ||||
|         type = types.int; | ||||
|         default = 1500; | ||||
|         description = "Minimum frequency for performance mode in MHz"; | ||||
|       }; | ||||
|       maxFreq = mkOption { | ||||
|         type = types.int; | ||||
|         default = 2600; | ||||
|         description = "Maximum frequency for performance mode in MHz"; | ||||
|       }; | ||||
|     }; | ||||
|   }; | ||||
| 
 | ||||
|   config = mkIf (elem "battery" features) { | ||||
|     boot = { | ||||
|       kernelModules = ["acpi_call"]; | ||||
|       extraModulePackages = with config.boot.kernelPackages; [ | ||||
|         acpi_call | ||||
|         cpupower | ||||
|       ]; | ||||
|     }; | ||||
| 
 | ||||
|     services = { | ||||
|       auto-cpufreq = { | ||||
|         enable = true; | ||||
|         settings = { | ||||
|           battery = { | ||||
|             governor = "powersave"; | ||||
|             scaling_min_freq = mkDefault (MHz cfg.powersave.minFreq); | ||||
|             scaling_max_freq = mkDefault (MHz cfg.powersave.maxFreq); | ||||
|             turbo = "never"; | ||||
|           }; | ||||
|           charger = { | ||||
|             governor = "performance"; | ||||
|             scaling_min_freq = mkDefault (MHz cfg.performance.minFreq); | ||||
|             scaling_max_freq = mkDefault (MHz cfg.performance.maxFreq); | ||||
|             turbo = "auto"; | ||||
|           }; | ||||
|         }; | ||||
|       }; | ||||
| 
 | ||||
|       upower = { | ||||
|         enable = true; | ||||
|         percentageLow = 25; | ||||
|         percentageCritical = 5; | ||||
|         percentageAction = 3; | ||||
|         criticalPowerAction = "Hibernate"; | ||||
|       }; | ||||
| 
 | ||||
|       undervolt = { | ||||
|         enable = true; | ||||
|         tempBat = 65; | ||||
|       }; | ||||
| 
 | ||||
|       thermald.enable = true; | ||||
| 
 | ||||
|       power-profiles-daemon.enable = true; | ||||
| 
 | ||||
|       logind = { | ||||
|         lidSwitch = "suspend"; | ||||
|       }; | ||||
|     }; | ||||
|     environment.systemPackages = with pkgs; [ | ||||
|       acpi | ||||
|       powertop | ||||
|     ]; | ||||
|   }; | ||||
| } | ||||
							
								
								
									
										24
									
								
								system/modules/host/hardware/features/bluetooth/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								system/modules/host/hardware/features/bluetooth/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,24 @@ | |||
| { config, lib, pkgs, ... }: | ||||
| 
 | ||||
| let | ||||
|   features = config.systemModules.host.hardware.features; | ||||
|   inherit (lib) mkIf; | ||||
|   inherit (builtins) elem; | ||||
| in | ||||
| 
 | ||||
| { | ||||
|   config = mkIf (elem "bluetooth" features) { | ||||
|     hardware.bluetooth = { | ||||
|       enable = true; | ||||
|       package = pkgs.bluez5-experimental; | ||||
|     }; | ||||
|    | ||||
|     environment.systemPackages = with pkgs; [ | ||||
|       live-buds-cli | ||||
|   	  bluetuith | ||||
|   	]; | ||||
| 
 | ||||
|     # https://github.com/NixOS/nixpkgs/issues/114222 | ||||
|     systemd.user.services.telephony_client.enable = false; | ||||
|   }; | ||||
| } | ||||
							
								
								
									
										20
									
								
								system/modules/host/hardware/features/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								system/modules/host/hardware/features/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,20 @@ | |||
| { lib, config, ... }: | ||||
| 
 | ||||
| let | ||||
|   inherit (lib) types mkOption; | ||||
| in | ||||
| 
 | ||||
| { | ||||
|   imports = [ | ||||
|     ./bluetooth | ||||
|     ./backlight | ||||
|     ./battery | ||||
|     ./ssd | ||||
|   ]; | ||||
| 
 | ||||
|   options.systemModules.host.hardware.features = mkOption { | ||||
|     type = with types; listOf (enum ["bluetooth" "backlight" "battery" "ssd"]); | ||||
|     default = []; | ||||
|     description = "What extra hardware feature system modules to use"; | ||||
|   }; | ||||
| } | ||||
							
								
								
									
										23
									
								
								system/modules/host/hardware/features/ssd/default.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								system/modules/host/hardware/features/ssd/default.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,23 @@ | |||
| { lib, config, ... }: | ||||
| 
 | ||||
| let | ||||
|   features = config.systemModules.host.hardware.ssd; | ||||
|   inherit (lib) mkIf; | ||||
|   inherit (builtins) elem; | ||||
| in | ||||
| 
 | ||||
| { | ||||
|   config = mkIf (elem "ssd" features) { | ||||
|     services.fstrim = { | ||||
|       enable = true; | ||||
|     }; | ||||
|     # only run fstrim while connected on AC | ||||
|     systemd.services.fstrim = { | ||||
|       unitConfig.ConditionACPower = true; | ||||
|       serviceConfig = { | ||||
|         Nice = 19; | ||||
|         IOSchedulingClass = "idle"; | ||||
|       }; | ||||
|     };  | ||||
|   }; | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue