mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-17 13:08: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 relatime=on "
|
||||
"-O xattr=sa "
|
||||
"-O mountpoint=none "
|
||||
"-O primarycache=metadata "
|
||||
"-O mountpoint=legacy "
|
||||
"-O compression=zstd "
|
||||
"-O atime=off "
|
||||
"root_pool "
|
||||
)
|
||||
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:
|
||||
"""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")
|
||||
for dataset in ("home", "var"):
|
||||
bash_wrapper(f"zfs create {default_options} root_pool/{dataset}")
|
||||
bash_wrapper("zfs create -o canmount=noauto root_pool/root")
|
||||
bash_wrapper("zfs create root_pool/home")
|
||||
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")
|
||||
|
||||
@@ -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/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/nix {mnt_dir}/nix")
|
||||
|
||||
for disk in disks:
|
||||
bash_wrapper(f"mkfs.vfat -n EFI {disk}-part1")
|
||||
@@ -224,8 +225,6 @@ def installer(
|
||||
|
||||
|
||||
class Cursor:
|
||||
"""Cursor class to handle cursor movement and navigation."""
|
||||
|
||||
def __init__(self):
|
||||
self.x_position = 0
|
||||
self.y_position = 0
|
||||
@@ -282,8 +281,6 @@ class Cursor:
|
||||
|
||||
|
||||
class State:
|
||||
"""State class to store the state of the program."""
|
||||
|
||||
def __init__(self):
|
||||
self.key = 0
|
||||
self.cursor = Cursor()
|
||||
@@ -298,12 +295,6 @@ class State:
|
||||
|
||||
|
||||
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(" ")
|
||||
return {
|
||||
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]]:
|
||||
"""Get a list of devices.
|
||||
Returns:
|
||||
list[dict[str, str]]: the list of devices
|
||||
"""
|
||||
"""Get a list of devices."""
|
||||
# --bytes
|
||||
raw_devices = bash_wrapper("lsblk --paths --pairs").splitlines()
|
||||
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_x: int = 0,
|
||||
) -> 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
|
||||
|
||||
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:
|
||||
"""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()
|
||||
width_height = "Width: {}, Height: {}".format(width, height)
|
||||
std_screen.addstr(height - 4, 0, width_height, curses.color_pair(5))
|
||||
@@ -411,13 +384,6 @@ def status_bar(
|
||||
width: int,
|
||||
height: int,
|
||||
) -> 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.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:
|
||||
"""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()
|
||||
std_screen.addstr(y, x, prompt)
|
||||
input_str = ""
|
||||
@@ -473,14 +430,6 @@ def swap_size_input(
|
||||
state: State,
|
||||
swap_offset: int,
|
||||
) -> 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): "
|
||||
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:
|
||||
@@ -506,14 +455,6 @@ def reserve_size_input(
|
||||
state: State,
|
||||
reserve_offset: int,
|
||||
) -> 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): "
|
||||
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:
|
||||
@@ -537,12 +478,6 @@ def reserve_size_input(
|
||||
|
||||
|
||||
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
|
||||
std_screen.clear()
|
||||
std_screen.refresh()
|
||||
@@ -598,7 +533,6 @@ def draw_menu(std_screen: curses.window) -> State:
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Main."""
|
||||
configure_logger("DEBUG")
|
||||
|
||||
state = curses.wrapper(draw_menu)
|
||||
|
||||
Reference in New Issue
Block a user