mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-17 04:58:19 -04:00
added nix store dataset
This commit is contained in:
@@ -110,9 +110,9 @@ def create_zfs_pool(pool_disks: Sequence[str], mnt_dir: str) -> None:
|
|||||||
"-O normalization=formD "
|
"-O normalization=formD "
|
||||||
"-O relatime=on "
|
"-O relatime=on "
|
||||||
"-O xattr=sa "
|
"-O xattr=sa "
|
||||||
"-O mountpoint=none "
|
"-O mountpoint=legacy "
|
||||||
"-O primarycache=metadata "
|
|
||||||
"-O compression=zstd "
|
"-O compression=zstd "
|
||||||
|
"-O atime=off "
|
||||||
"root_pool "
|
"root_pool "
|
||||||
)
|
)
|
||||||
if len(pool_disks) == 1:
|
if len(pool_disks) == 1:
|
||||||
@@ -130,11 +130,11 @@ def create_zfs_pool(pool_disks: Sequence[str], mnt_dir: str) -> None:
|
|||||||
|
|
||||||
def create_zfs_datasets() -> None:
|
def create_zfs_datasets() -> None:
|
||||||
"""Create ZFS datasets."""
|
"""Create ZFS datasets."""
|
||||||
default_options = "-o compression=zstd -o atime=off -o mountpoint=legacy"
|
|
||||||
|
|
||||||
bash_wrapper(f"zfs create {default_options} -o canmount=noauto root_pool/root")
|
bash_wrapper("zfs create -o canmount=noauto root_pool/root")
|
||||||
for dataset in ("home", "var"):
|
bash_wrapper("zfs create root_pool/home")
|
||||||
bash_wrapper(f"zfs create {default_options} root_pool/{dataset}")
|
bash_wrapper("zfs create root_pool/var")
|
||||||
|
bash_wrapper("zfs create -o compression=zstd-9 root_pool/nix")
|
||||||
|
|
||||||
datasets = bash_wrapper("zfs list -o name")
|
datasets = bash_wrapper("zfs list -o name")
|
||||||
|
|
||||||
@@ -150,6 +150,7 @@ def install_nixos(mnt_dir: str, disks: Sequence[str], encrypt: bool) -> None:
|
|||||||
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/root {mnt_dir}")
|
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/root {mnt_dir}")
|
||||||
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/home {mnt_dir}/home")
|
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/home {mnt_dir}/home")
|
||||||
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/var {mnt_dir}/var")
|
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/var {mnt_dir}/var")
|
||||||
|
bash_wrapper(f"mount -o X-mount.mkdir -t zfs root_pool/nix {mnt_dir}/nix")
|
||||||
|
|
||||||
for disk in disks:
|
for disk in disks:
|
||||||
bash_wrapper(f"mkfs.vfat -n EFI {disk}-part1")
|
bash_wrapper(f"mkfs.vfat -n EFI {disk}-part1")
|
||||||
@@ -224,8 +225,6 @@ def installer(
|
|||||||
|
|
||||||
|
|
||||||
class Cursor:
|
class Cursor:
|
||||||
"""Cursor class to handle cursor movement and navigation."""
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.x_position = 0
|
self.x_position = 0
|
||||||
self.y_position = 0
|
self.y_position = 0
|
||||||
@@ -282,8 +281,6 @@ class Cursor:
|
|||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
"""State class to store the state of the program."""
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.key = 0
|
self.key = 0
|
||||||
self.cursor = Cursor()
|
self.cursor = Cursor()
|
||||||
@@ -298,12 +295,6 @@ class State:
|
|||||||
|
|
||||||
|
|
||||||
def get_device(raw_device: str) -> dict[str, str]:
|
def get_device(raw_device: str) -> dict[str, str]:
|
||||||
"""get device information from raw device string
|
|
||||||
Args:
|
|
||||||
raw_device (str): the raw device string
|
|
||||||
Returns:
|
|
||||||
dict[str, str]: the device information
|
|
||||||
"""
|
|
||||||
raw_device_components = raw_device.split(" ")
|
raw_device_components = raw_device.split(" ")
|
||||||
return {
|
return {
|
||||||
thing.split("=")[0].lower(): thing.split("=")[1].strip('"')
|
thing.split("=")[0].lower(): thing.split("=")[1].strip('"')
|
||||||
@@ -312,10 +303,7 @@ def get_device(raw_device: str) -> dict[str, str]:
|
|||||||
|
|
||||||
|
|
||||||
def get_devices() -> list[dict[str, str]]:
|
def get_devices() -> list[dict[str, str]]:
|
||||||
"""Get a list of devices.
|
"""Get a list of devices."""
|
||||||
Returns:
|
|
||||||
list[dict[str, str]]: the list of devices
|
|
||||||
"""
|
|
||||||
# --bytes
|
# --bytes
|
||||||
raw_devices = bash_wrapper("lsblk --paths --pairs").splitlines()
|
raw_devices = bash_wrapper("lsblk --paths --pairs").splitlines()
|
||||||
return [get_device(raw_device) for raw_device in raw_devices]
|
return [get_device(raw_device) for raw_device in raw_devices]
|
||||||
@@ -334,16 +322,6 @@ def draw_device_menu(
|
|||||||
menu_start_y: int = 0,
|
menu_start_y: int = 0,
|
||||||
menu_start_x: int = 0,
|
menu_start_x: int = 0,
|
||||||
) -> State:
|
) -> State:
|
||||||
"""draw the device menu and handle user input
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
devices (list[dict[str, str]]): the list of devices to draw
|
|
||||||
state (State): the state object to update
|
|
||||||
menu_start_y (int, optional): the y position to start drawing the menu. Defaults to 0.
|
|
||||||
menu_start_x (int, optional): the x position to start drawing the menu. Defaults to 0.
|
|
||||||
Returns:
|
|
||||||
State: the updated state object
|
|
||||||
"""
|
|
||||||
padding = 2
|
padding = 2
|
||||||
|
|
||||||
name_padding = calculate_device_menu_padding(devices, "name", padding)
|
name_padding = calculate_device_menu_padding(devices, "name", padding)
|
||||||
@@ -387,11 +365,6 @@ def draw_device_menu(
|
|||||||
|
|
||||||
|
|
||||||
def debug_menu(std_screen: curses.window, key: int) -> None:
|
def debug_menu(std_screen: curses.window, key: int) -> None:
|
||||||
"""draw debug menu
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
key (int): the last key pressed
|
|
||||||
"""
|
|
||||||
height, width = std_screen.getmaxyx()
|
height, width = std_screen.getmaxyx()
|
||||||
width_height = "Width: {}, Height: {}".format(width, height)
|
width_height = "Width: {}, Height: {}".format(width, height)
|
||||||
std_screen.addstr(height - 4, 0, width_height, curses.color_pair(5))
|
std_screen.addstr(height - 4, 0, width_height, curses.color_pair(5))
|
||||||
@@ -411,13 +384,6 @@ def status_bar(
|
|||||||
width: int,
|
width: int,
|
||||||
height: int,
|
height: int,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""draw status bar
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
cursor (Cursor): the cursor object
|
|
||||||
width (int): the width of the screen
|
|
||||||
height (int): the height of the screen
|
|
||||||
"""
|
|
||||||
std_screen.attron(curses.A_REVERSE)
|
std_screen.attron(curses.A_REVERSE)
|
||||||
std_screen.attron(curses.color_pair(3))
|
std_screen.attron(curses.color_pair(3))
|
||||||
|
|
||||||
@@ -439,15 +405,6 @@ def set_color() -> None:
|
|||||||
|
|
||||||
|
|
||||||
def get_text_input(std_screen: curses.window, prompt: str, y: int, x: int) -> str:
|
def get_text_input(std_screen: curses.window, prompt: str, y: int, x: int) -> str:
|
||||||
"""get text input from the user
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
prompt (str): the prompt to display
|
|
||||||
y (int): the y position to start drawing the prompt
|
|
||||||
x (int): the x position to start drawing the prompt
|
|
||||||
Returns:
|
|
||||||
str: the input string
|
|
||||||
"""
|
|
||||||
curses.echo()
|
curses.echo()
|
||||||
std_screen.addstr(y, x, prompt)
|
std_screen.addstr(y, x, prompt)
|
||||||
input_str = ""
|
input_str = ""
|
||||||
@@ -473,14 +430,6 @@ def swap_size_input(
|
|||||||
state: State,
|
state: State,
|
||||||
swap_offset: int,
|
swap_offset: int,
|
||||||
) -> State:
|
) -> State:
|
||||||
"""draw swap size input
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
state (State): the state object to update
|
|
||||||
swap_offset (int): the y position to start drawing the swap size input
|
|
||||||
Returns:
|
|
||||||
State: the updated state object
|
|
||||||
"""
|
|
||||||
swap_size_text = "Swap size (GB): "
|
swap_size_text = "Swap size (GB): "
|
||||||
std_screen.addstr(swap_offset, 0, f"{swap_size_text}{state.swap_size}")
|
std_screen.addstr(swap_offset, 0, f"{swap_size_text}{state.swap_size}")
|
||||||
if state.key == ord("\n") and state.cursor.get_y() == swap_offset:
|
if state.key == ord("\n") and state.cursor.get_y() == swap_offset:
|
||||||
@@ -506,14 +455,6 @@ def reserve_size_input(
|
|||||||
state: State,
|
state: State,
|
||||||
reserve_offset: int,
|
reserve_offset: int,
|
||||||
) -> State:
|
) -> State:
|
||||||
"""draw reserve size input
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
state (State): the state object to update
|
|
||||||
reserve_offset (int): the y position to start drawing the reserve size input
|
|
||||||
Returns:
|
|
||||||
State: the updated state object
|
|
||||||
"""
|
|
||||||
reserve_size_text = "reserve size (GB): "
|
reserve_size_text = "reserve size (GB): "
|
||||||
std_screen.addstr(reserve_offset, 0, f"{reserve_size_text}{state.reserve_size}")
|
std_screen.addstr(reserve_offset, 0, f"{reserve_size_text}{state.reserve_size}")
|
||||||
if state.key == ord("\n") and state.cursor.get_y() == reserve_offset:
|
if state.key == ord("\n") and state.cursor.get_y() == reserve_offset:
|
||||||
@@ -537,12 +478,6 @@ def reserve_size_input(
|
|||||||
|
|
||||||
|
|
||||||
def draw_menu(std_screen: curses.window) -> State:
|
def draw_menu(std_screen: curses.window) -> State:
|
||||||
"""draw the menu and handle user input
|
|
||||||
Args:
|
|
||||||
std_screen (curses.window): the curses window to draw on
|
|
||||||
Returns:
|
|
||||||
State: the state object
|
|
||||||
"""
|
|
||||||
# Clear and refresh the screen for a blank canvas
|
# Clear and refresh the screen for a blank canvas
|
||||||
std_screen.clear()
|
std_screen.clear()
|
||||||
std_screen.refresh()
|
std_screen.refresh()
|
||||||
@@ -598,7 +533,6 @@ def draw_menu(std_screen: curses.window) -> State:
|
|||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""Main."""
|
|
||||||
configure_logger("DEBUG")
|
configure_logger("DEBUG")
|
||||||
|
|
||||||
state = curses.wrapper(draw_menu)
|
state = curses.wrapper(draw_menu)
|
||||||
|
|||||||
Reference in New Issue
Block a user