Add provision() to configure users for profiles (#4254)

This commit is contained in:
codefiles 2026-02-21 15:53:58 -05:00 committed by GitHub
parent a9c939cb86
commit d86daa531a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 6 deletions

View File

@ -7,6 +7,7 @@ from archinstall.lib.translationhandler import tr
if TYPE_CHECKING: if TYPE_CHECKING:
from ..lib.installer import Installer from ..lib.installer import Installer
from ..lib.models.users import User
class ProfileType(Enum): class ProfileType(Enum):
@ -103,6 +104,13 @@ class Profile:
are needed are needed
""" """
def provision(self, install_session: Installer, users: list[User]) -> None:
"""
Hook that will be called when the installation process is
finished and user configuration for specific default_profiles
is needed
"""
def json(self) -> dict[str, str]: def json(self) -> dict[str, str]:
""" """
Returns a json representation of the profile Returns a json representation of the profile

View File

@ -11,6 +11,7 @@ from archinstall.tui.ui.result import ResultType
if TYPE_CHECKING: if TYPE_CHECKING:
from archinstall.lib.installer import Installer from archinstall.lib.installer import Installer
from archinstall.lib.models.users import User
class ServerProfile(Profile): class ServerProfile(Profile):
@ -53,6 +54,11 @@ class ServerProfile(Profile):
case ResultType.Reset: case ResultType.Reset:
return SelectResult.ResetCurrent return SelectResult.ResetCurrent
@override
def provision(self, install_session: Installer, users: list[User]) -> None:
for profile in self.current_selection:
profile.provision(install_session, users)
@override @override
def post_install(self, install_session: Installer) -> None: def post_install(self, install_session: Installer) -> None:
for profile in self.current_selection: for profile in self.current_selection:

View File

@ -6,6 +6,7 @@ from archinstall.default_profiles.profile import Profile, ProfileType
if TYPE_CHECKING: if TYPE_CHECKING:
from archinstall.lib.installer import Installer from archinstall.lib.installer import Installer
from archinstall.lib.models.users import User
class DockerProfile(Profile): class DockerProfile(Profile):
@ -26,9 +27,6 @@ class DockerProfile(Profile):
return ['docker'] return ['docker']
@override @override
def post_install(self, install_session: Installer) -> None: def provision(self, install_session: Installer, users: list[User]) -> None:
from archinstall.lib.args import arch_config_handler for user in users:
install_session.arch_chroot(f'usermod -a -G docker {user.username}')
if auth_config := arch_config_handler.config.auth_config:
for user in auth_config.users:
install_session.arch_chroot(f'usermod -a -G docker {user.username}')

View File

@ -123,8 +123,10 @@ def perform_installation(
config.profile_config, config.profile_config,
) )
users = None
if config.auth_config: if config.auth_config:
if config.auth_config.users: if config.auth_config.users:
users = config.auth_config.users
installation.create_users(config.auth_config.users) installation.create_users(config.auth_config.users)
auth_handler.setup_auth(installation, config.auth_config, config.hostname) auth_handler.setup_auth(installation, config.auth_config, config.hostname)
@ -153,6 +155,9 @@ def perform_installation(
if (profile_config := config.profile_config) and profile_config.profile: if (profile_config := config.profile_config) and profile_config.profile:
profile_config.profile.post_install(installation) profile_config.profile.post_install(installation)
if users:
profile_config.profile.provision(installation, users)
# If the user provided a list of services to be enabled, pass the list to the enable_service function. # If the user provided a list of services to be enabled, pass the list to the enable_service function.
# Note that while it's called enable_service, it can actually take a list of services and iterate it. # Note that while it's called enable_service, it can actually take a list of services and iterate it.
if services := config.services: if services := config.services: