Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions archinstall/lib/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ class GfxPackage(Enum):
Mesa = 'mesa'
NvidiaDkms = 'nvidia-dkms'
NvidiaOpenDkms = 'nvidia-open-dkms'
Ppd = 'power-profiles-daemon'
NvidiaPrime = 'nvidia-prime'
VulkanIntel = 'vulkan-intel'
VulkanRadeon = 'vulkan-radeon'
VulkanNouveau = 'vulkan-nouveau'
VulkanSwrast = 'vulkan-swrast'
Xf86VideoAmdgpu = 'xf86-video-amdgpu'
Xf86VideoAti = 'xf86-video-ati'
Xf86VideoNouveau = 'xf86-video-nouveau'
Expand Down Expand Up @@ -134,8 +137,15 @@ def gfx_packages(self) -> list[GfxPackage]:
case GfxDriver.VMOpenSource:
packages += [
GfxPackage.Mesa,
GfxPackage.VulkanSwrast,
]

if SysInfo.is_laptop() and self.is_nvidia() and (SysInfo.has_intel_graphics() or SysInfo.has_amd_graphics()):
packages.append(GfxPackage.NvidiaPrime)

if SysInfo.is_laptop():
packages.append(GfxPackage.Ppd)

return packages


Expand Down Expand Up @@ -193,6 +203,32 @@ def loaded_modules(self) -> list[str]:

return modules

@cached_property
def form_factor(self) -> bool:
"""
Safeguards if it's a laptop
"""
for entry in Path('/sys/class/power_supply').iterdir():
present_file = entry / 'present'
if present_file.is_file() and present_file.read_text().strip() == '1':
# already know its a laptop if one is in this file but
capacity_file = entry / 'capacity'
battery_level = None
if capacity_file.is_file():
battery_level = int(capacity_file.read_text().strip())
# Could be useful to warn on low battery for installs

status_file = entry / 'status'
if status_file.is_file():
status = status_file.read_text().strip()
# status can be: "Charging", "Discharging", "Full"
# we can then ignore low battery if Charging
debug(f'Battery: {battery_level}, Status: {status}')
if battery_level and battery_level < 15 and status == 'Discharging':
debug('Warning: Low battery detected. Please charge before installing.')
return True
return False


_sys_info = _SysInfo()

Expand Down Expand Up @@ -275,6 +311,13 @@ def virtualization() -> str | None:

return None

@staticmethod
def is_laptop() -> bool:
"""
Detects if the system is a laptop by checking for battery presence
"""
return _sys_info.form_factor

@staticmethod
def is_vm() -> bool:
try:
Expand Down
7 changes: 7 additions & 0 deletions archinstall/lib/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,13 @@ def enable_periodic_trim(self) -> None:
# fstrim is owned by util-linux, a dependency of both base and systemd.
self.enable_service('fstrim.timer')

def enable_power_profiles(self) -> None:
if SysInfo.is_laptop():
info('Detected laptop form factor, enabling power-profiles-daemon')
self.enable_service('power-profiles-daemon.service')
else:
debug('Desktop/server detected, skipping power-profiles-daemon')

def enable_service(self, services: str | list[str]) -> None:
if isinstance(services, str):
services = [services]
Expand Down
3 changes: 3 additions & 0 deletions archinstall/lib/profile/profiles_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ def install_gfx_driver(self, install_session: 'Installer', driver: GfxDriver) ->
pkg_names = [p.value for p in driver_pkgs]
install_session.add_additional_packages(pkg_names)

# Enable power-profiles-daemon on laptops after graphics packages are installed
install_session.enable_power_profiles()

def install_profile_config(self, install_session: 'Installer', profile_config: ProfileConfiguration) -> None:
profile = profile_config.profile

Expand Down