11from dataclasses import dataclass
22from typing import override
33
4+ from archinstall .lib .disk .encryption_menu import DiskEncryptionMenu
45from archinstall .lib .models .device_model import (
56 BtrfsOptions ,
7+ DiskEncryption ,
68 DiskLayoutConfiguration ,
79 DiskLayoutType ,
10+ EncryptionType ,
811 LvmConfiguration ,
912 SnapshotConfig ,
1013 SnapshotType ,
@@ -25,6 +28,7 @@ class DiskMenuConfig:
2528 disk_config : DiskLayoutConfiguration | None
2629 lvm_config : LvmConfiguration | None
2730 btrfs_snapshot_config : SnapshotConfig | None
31+ disk_encryption : DiskEncryption | None
2832
2933
3034class DiskLayoutConfigurationMenu (AbstractSubMenu [DiskLayoutConfiguration ]):
@@ -34,13 +38,15 @@ def __init__(self, disk_layout_config: DiskLayoutConfiguration | None):
3438 disk_config = None ,
3539 lvm_config = None ,
3640 btrfs_snapshot_config = None ,
41+ disk_encryption = None ,
3742 )
3843 else :
3944 snapshot_config = disk_layout_config .btrfs_options .snapshot_config if disk_layout_config .btrfs_options else None
4045
4146 self ._disk_menu_config = DiskMenuConfig (
4247 disk_config = disk_layout_config ,
4348 lvm_config = disk_layout_config .lvm_config ,
49+ disk_encryption = disk_layout_config .disk_encryption ,
4450 btrfs_snapshot_config = snapshot_config ,
4551 )
4652
@@ -70,6 +76,13 @@ def _define_menu_options(self) -> list[MenuItem]:
7076 dependencies = [self ._check_dep_lvm ],
7177 key = 'lvm_config' ,
7278 ),
79+ MenuItem (
80+ text = tr ('Disk encryption' ),
81+ action = self ._disk_encryption ,
82+ preview_action = self ._prev_disk_encryption ,
83+ dependencies = ['disk_config' ],
84+ key = 'disk_encryption' ,
85+ ),
7386 MenuItem (
7487 text = 'Btrfs snapshots' ,
7588 action = self ._select_btrfs_snapshots ,
@@ -87,6 +100,7 @@ def run(self) -> DiskLayoutConfiguration | None:
87100 if self ._disk_menu_config .disk_config :
88101 self ._disk_menu_config .disk_config .lvm_config = self ._disk_menu_config .lvm_config
89102 self ._disk_menu_config .disk_config .btrfs_options = BtrfsOptions (snapshot_config = self ._disk_menu_config .btrfs_snapshot_config )
103+ self ._disk_menu_config .disk_config .disk_encryption = self ._disk_menu_config .disk_encryption
90104 return self ._disk_menu_config .disk_config
91105
92106 return None
@@ -107,11 +121,25 @@ def _check_dep_btrfs(self) -> bool:
107121
108122 return False
109123
124+ def _disk_encryption (self , preset : DiskEncryption | None ) -> DiskEncryption | None :
125+ disk_config : DiskLayoutConfiguration | None = self ._item_group .find_by_key ('disk_config' ).value
126+
127+ if not disk_config :
128+ # this should not happen as the encryption menu has the disk_config as dependency
129+ raise ValueError ('No disk layout specified' )
130+
131+ if not DiskEncryption .validate_enc (disk_config ):
132+ return None
133+
134+ disk_encryption = DiskEncryptionMenu (disk_config , preset = preset ).run ()
135+ return disk_encryption
136+
110137 def _select_disk_layout_config (self , preset : DiskLayoutConfiguration | None ) -> DiskLayoutConfiguration | None :
111138 disk_config = select_disk_config (preset )
112139
113140 if disk_config != preset :
114141 self ._menu_item_group .find_by_key ('lvm_config' ).value = None
142+ self ._menu_item_group .find_by_key ('disk_encryption' ).value = None
115143
116144 return disk_config
117145
@@ -217,3 +245,29 @@ def _prev_btrfs_snapshots(self, item: MenuItem) -> str | None:
217245
218246 snapshot_config : SnapshotConfig = item .value
219247 return tr ('Snapshot type: {}' ).format (snapshot_config .snapshot_type .value )
248+
249+ def _prev_disk_encryption (self , item : MenuItem ) -> str | None :
250+ disk_config : DiskLayoutConfiguration | None = self ._item_group .find_by_key ('disk_config' ).value
251+ enc_config : DiskEncryption | None = item .value
252+
253+ if disk_config and not DiskEncryption .validate_enc (disk_config ):
254+ return tr ('LVM disk encryption with more than 2 partitions is currently not supported' )
255+
256+ if enc_config :
257+ enc_type = EncryptionType .type_to_text (enc_config .encryption_type )
258+ output = tr ('Encryption type' ) + f': { enc_type } \n '
259+
260+ if enc_config .encryption_password :
261+ output += tr ('Password' ) + f': { enc_config .encryption_password .hidden ()} \n '
262+
263+ if enc_config .partitions :
264+ output += f'Partitions: { len (enc_config .partitions )} selected\n '
265+ elif enc_config .lvm_volumes :
266+ output += f'LVM volumes: { len (enc_config .lvm_volumes )} selected\n '
267+
268+ if enc_config .hsm_device :
269+ output += f'HSM: { enc_config .hsm_device .manufacturer } '
270+
271+ return output
272+
273+ return None
0 commit comments