Skip to content

Commit

Permalink
Fix 1934 - audio server regression (#1946)
Browse files Browse the repository at this point in the history
* Audio configuration

* Update

* Update schema

---------

Co-authored-by: Daniel Girtler <[email protected]>
  • Loading branch information
svartkanin and svartkanin authored Jul 25, 2023
1 parent d76f4a0 commit 439bb54
Show file tree
Hide file tree
Showing 12 changed files with 137 additions and 82 deletions.
3 changes: 3 additions & 0 deletions archinstall/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ def load_config():
if arguments.get('bootloader', None) is not None:
arguments['bootloader'] = models.Bootloader.from_arg(arguments['bootloader'])

if arguments.get('audio_config', None) is not None:
arguments['audio_config'] = models.AudioConfiguration.parse_arg(arguments['audio_config'])

if arguments.get('disk_encryption', None) is not None and disk_config is not None:
password = arguments.get('encryption_password', '')
arguments['disk_encryption'] = disk.DiskEncryption.parse_arg(
Expand Down
27 changes: 16 additions & 11 deletions archinstall/lib/global_menu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Any, List, Optional, Union, Dict, TYPE_CHECKING
from typing import Any, List, Optional, Dict, TYPE_CHECKING

from . import disk
from .general import secret
Expand All @@ -9,6 +9,7 @@
from .mirrors import MirrorConfiguration, MirrorMenu
from .models import NetworkConfiguration, NicType
from .models.bootloader import Bootloader
from .models.audio_configuration import Audio, AudioConfiguration
from .models.users import User
from .output import FormattedOutput
from .profile.profile_menu import ProfileConfiguration
Expand Down Expand Up @@ -109,12 +110,11 @@ def setup_selection_menu_options(self):
display_func=lambda x: x.profile.name if x else '',
preview_func=self._prev_profile
)
self._menu_options['audio'] = \
self._menu_options['audio_config'] = \
Selector(
_('Audio'),
lambda preset: self._select_audio(preset),
display_func=lambda x: x if x else '',
default=None
display_func=lambda x: self._display_audio(x)
)
self._menu_options['parallel downloads'] = \
Selector(
Expand Down Expand Up @@ -421,13 +421,18 @@ def _select_profile(self, current_profile: Optional[ProfileConfiguration]):
profile_config = ProfileMenu(store, preset=current_profile).run()
return profile_config

def _select_audio(self, current: Union[str, None]) -> Optional[str]:
profile_config: Optional[ProfileConfiguration] = self._menu_options['profile_config'].current_selection
if profile_config and profile_config.profile:
is_desktop = profile_config.profile.is_desktop_profile() if profile_config else False
selection = ask_for_audio_selection(is_desktop, current)
return selection
return None
def _select_audio(
self,
current: Optional[AudioConfiguration] = None
) -> Optional[AudioConfiguration]:
selection = ask_for_audio_selection(current)
return selection

def _display_audio(self, current: Optional[AudioConfiguration]) -> str:
if not current:
return Audio.no_audio_text()
else:
return current.audio.name

def _create_user_account(self, defined_users: List[User]) -> List[User]:
users = ask_for_additional_users(defined_users=defined_users)
Expand Down
30 changes: 23 additions & 7 deletions archinstall/lib/interactions/general_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from ..locale import list_timezones, list_keyboard_languages
from ..menu import MenuSelectionType, Menu, TextInput
from ..models.audio_configuration import Audio, AudioConfiguration
from ..output import warn
from ..packages.packages import validate_package_list
from ..storage import storage
Expand Down Expand Up @@ -55,16 +56,31 @@ def ask_for_a_timezone(preset: Optional[str] = None) -> Optional[str]:
return None


def ask_for_audio_selection(desktop: bool = True, preset: Optional[str] = None) -> Optional[str]:
no_audio = str(_('No audio server'))
choices = ['pipewire', 'pulseaudio'] if desktop else ['pipewire', 'pulseaudio', no_audio]
default = 'pipewire' if desktop else no_audio
def ask_for_audio_selection(
current: Optional[AudioConfiguration] = None
) -> Optional[AudioConfiguration]:
choices = [
Audio.Pipewire.name,
Audio.Pulseaudio.name,
Audio.no_audio_text()
]

choice = Menu(_('Choose an audio server'), choices, preset_values=preset, default_option=default).run()
preset = current.audio.name if current else None

choice = Menu(
_('Choose an audio server'),
choices,
preset_values=preset
).run()

match choice.type_:
case MenuSelectionType.Skip: return preset
case MenuSelectionType.Selection: return choice.single_value
case MenuSelectionType.Skip: return current
case MenuSelectionType.Selection:
value = choice.single_value
if value == Audio.no_audio_text():
return None
else:
return AudioConfiguration(Audio[value])

return None

Expand Down
1 change: 1 addition & 0 deletions archinstall/lib/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
from .bootloader import Bootloader
from .gen import VersionDef, PackageSearchResult, PackageSearch, LocalPackage
from .users import PasswordStrength, User
from .audio_configuration import Audio, AudioConfiguration
54 changes: 54 additions & 0 deletions archinstall/lib/models/audio_configuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from dataclasses import dataclass
from enum import Enum
from typing import Any, TYPE_CHECKING, Dict

from ..hardware import SysInfo
from ..output import info
from ...default_profiles.applications.pipewire import PipewireProfile

if TYPE_CHECKING:
_: Any


@dataclass
class Audio(Enum):
Pipewire = 'pipewire'
Pulseaudio = 'pulseaudio'

@staticmethod
def no_audio_text() -> str:
return str(_('No audio server'))


@dataclass
class AudioConfiguration:
audio: Audio

def __dump__(self) -> Dict[str, Any]:
return {
'audio': self.audio.value
}

@staticmethod
def parse_arg(arg: Dict[str, Any]) -> 'AudioConfiguration':
return AudioConfiguration(
Audio(arg['audio'])
)

def install_audio_config(
self,
installation: Any
):
info(f'Installing audio server: {self.audio.name}')

match self.audio:
case Audio.Pipewire:
PipewireProfile().install(installation)
case Audio.Pulseaudio:
installation.add_additional_packages("pulseaudio")

if SysInfo.requires_sof_fw():
installation.add_additional_packages('sof-firmware')

if SysInfo.requires_alsa_fw():
installation.add_additional_packages('alsa-firmware')
19 changes: 5 additions & 14 deletions archinstall/scripts/guided.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
from archinstall.lib import locale
from archinstall.lib import disk
from archinstall.lib.global_menu import GlobalMenu
from archinstall.default_profiles.applications.pipewire import PipewireProfile
from archinstall.lib.configuration import ConfigurationOutput
from archinstall.lib.installer import Installer
from archinstall.lib.menu import Menu
from archinstall.lib.mirrors import use_mirrors, add_custom_mirrors
from archinstall.lib.models import AudioConfiguration
from archinstall.lib.models.bootloader import Bootloader
from archinstall.lib.models.network_configuration import NetworkConfiguration
from archinstall.lib.networking import check_mirror_reachable
Expand Down Expand Up @@ -70,7 +70,7 @@ def ask_user_questions():
global_menu.enable('profile_config')

# Ask about audio server selection if one is not already set
global_menu.enable('audio')
global_menu.enable('audio_config')

# Ask for preferred kernel:
global_menu.enable('kernels', mandatory=True)
Expand Down Expand Up @@ -172,18 +172,9 @@ def perform_installation(mountpoint: Path):
if users := archinstall.arguments.get('!users', None):
installation.create_users(users)

if audio := archinstall.arguments.get('audio', None):
info(f'Installing audio server: {audio}')
if audio == 'pipewire':
PipewireProfile().install(installation)
elif audio == 'pulseaudio':
installation.add_additional_packages("pulseaudio")

if SysInfo.requires_sof_fw():
installation.add_additional_packages('sof-firmware')

if SysInfo.requires_alsa_fw():
installation.add_additional_packages('alsa-firmware')
audio_config: Optional[AudioConfiguration] = archinstall.arguments.get('audio_config', None)
if audio_config:
audio_config.install_audio_config(installation)
else:
info("No audio server will be installed")

Expand Down
19 changes: 8 additions & 11 deletions archinstall/scripts/swiss.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import os
from enum import Enum
from pathlib import Path
from typing import TYPE_CHECKING, Any, Dict
from typing import TYPE_CHECKING, Any, Dict, Optional

import archinstall
from archinstall import SysInfo, info, debug
from archinstall.lib import mirrors
from archinstall.lib import models
from archinstall.lib import disk
from archinstall.lib import locale
from archinstall.lib.models import AudioConfiguration
from archinstall.lib.networking import check_mirror_reachable
from archinstall.lib.profile.profiles_handler import profile_handler
from archinstall.lib import menu
from archinstall.lib.global_menu import GlobalMenu
from archinstall.lib.installer import Installer
from archinstall.lib.configuration import ConfigurationOutput
from archinstall.default_profiles.applications.pipewire import PipewireProfile

if TYPE_CHECKING:
_: Any
Expand Down Expand Up @@ -95,7 +95,7 @@ def setup_selection_menu_options(self):
options_list = [
'mirror_config', 'disk_config',
'disk_encryption', 'swap', 'bootloader', 'hostname', '!root-password',
'!users', 'profile_config', 'audio', 'kernels', 'packages', 'additional-repositories', 'network_config',
'!users', 'profile_config', 'audio_config', 'kernels', 'packages', 'additional-repositories', 'network_config',
'timezone', 'ntp'
]

Expand All @@ -109,7 +109,7 @@ def setup_selection_menu_options(self):
case ExecutionMode.Only_OS:
options_list = [
'mirror_config','bootloader', 'hostname',
'!root-password', '!users', 'profile_config', 'audio', 'kernels',
'!root-password', '!users', 'profile_config', 'audio_config', 'kernels',
'packages', 'additional-repositories', 'network_config', 'timezone', 'ntp'
]

Expand Down Expand Up @@ -236,14 +236,11 @@ def perform_installation(mountpoint: Path, exec_mode: ExecutionMode):
if users := archinstall.arguments.get('!users', None):
installation.create_users(users)

if audio := archinstall.arguments.get('audio', None):
info(f'Installing audio server: {audio}')
if audio == 'pipewire':
PipewireProfile().install(installation)
elif audio == 'pulseaudio':
installation.add_additional_packages("pulseaudio")
audio_config: Optional[AudioConfiguration] = archinstall.arguments.get('audio_config', None)
if audio_config:
audio_config.install_audio_config(installation)
else:
info("No audio server will be installed.")
info("No audio server will be installed")

if profile_config := archinstall.arguments.get('profile_config', None):
profile_handler.install_profile_config(installation, profile_config)
Expand Down
2 changes: 1 addition & 1 deletion docs/installing/guided.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ There are three different configuration files, all of which are optional.
.. code-block:: json
{
"audio": "pipewire",
"audio_config": {"audio": "pipewire"},
"bootloader": "systemd-bootctl",
"custom-commands": [
"cd /home/devel; git clone https://aur.archlinux.org/paru.git",
Expand Down
22 changes: 8 additions & 14 deletions examples/config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"config_version": "2.5.2",
"additional-repositories": [],
"archinstall-language": "English",
"audio": "pipewire",
"audio_config": {"audio": "pipewire"},
"bootloader": "Systemd-boot",
"debug": false,
"disk_config": {
Expand Down Expand Up @@ -99,19 +99,13 @@
"http://archlinux.mirror.digitalpacific.com.au/$repo/os/$arch": true,
}
},
"network_config": {
"nics": [
{
"dhcp": false,
"dns": [
"3.3.3.3"
],
"gateway": "2.2.2.2",
"iface": "enp0s31f6",
"ip": "1.1.1.1"
}
],
"type": "manual"
"nic": {
"dhcp": true,
"dns": null,
"gateway": null,
"iface": null,
"ip": null,
"type": "nm"
},
"no_pkg_lookups": false,
"ntp": true,
Expand Down
1 change: 0 additions & 1 deletion examples/custom-command-sample.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dry_run": true,
"audio": "none",
"bootloader": "systemd-bootctl",
"debug": false,
"harddrives": [
Expand Down
22 changes: 6 additions & 16 deletions examples/interactive_installation.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Optional

import archinstall
from archinstall import Installer
from archinstall import profile
from archinstall import SysInfo
from archinstall import mirrors
from archinstall.default_profiles.applications.pipewire import PipewireProfile
from archinstall import disk
from archinstall import menu
from archinstall import models
Expand Down Expand Up @@ -49,7 +48,7 @@ def ask_user_questions():
global_menu.enable('profile_config')

# Ask about audio server selection if one is not already set
global_menu.enable('audio')
global_menu.enable('audio_config')

# Ask for preferred kernel:
global_menu.enable('kernels', mandatory=True)
Expand Down Expand Up @@ -151,20 +150,11 @@ def perform_installation(mountpoint: Path):
if users := archinstall.arguments.get('!users', None):
installation.create_users(users)

if audio := archinstall.arguments.get('audio', None):
info(f'Installing audio server: {audio}')
if audio == 'pipewire':
PipewireProfile().install(installation)
elif audio == 'pulseaudio':
installation.add_additional_packages("pulseaudio")

if SysInfo.requires_sof_fw():
installation.add_additional_packages('sof-firmware')

if SysInfo.requires_alsa_fw():
installation.add_additional_packages('alsa-firmware')
audio_config: Optional[models.AudioConfiguration] = archinstall.arguments.get('audio_config', None)
if audio_config:
audio_config.install_audio_config(installation)
else:
info("No audio server will be installed.")
info("No audio server will be installed")

if profile_config := archinstall.arguments.get('profile_config', None):
profile.profile_handler.install_profile_config(installation, profile_config)
Expand Down
Loading

0 comments on commit 439bb54

Please sign in to comment.