From 97ce42a93946eb8d0c7bf58802478596d179ec15 Mon Sep 17 00:00:00 2001 From: Sebastian Pietras Date: Thu, 2 May 2024 23:32:45 +0000 Subject: [PATCH] Cleaned up storage configuration --- docs/docs/02-Installation.md | 20 +++------------ src/hosts/xenon/modules/constants/default.nix | 12 +++++++++ src/hosts/xenon/modules/install/default.nix | 1 + src/hosts/xenon/modules/install/install.sh | 25 +++---------------- src/hosts/xenon/modules/storage/default.nix | 8 +++++- 5 files changed, 27 insertions(+), 39 deletions(-) diff --git a/docs/docs/02-Installation.md b/docs/docs/02-Installation.md index c35c915..9c31125 100644 --- a/docs/docs/02-Installation.md +++ b/docs/docs/02-Installation.md @@ -23,29 +23,15 @@ private keys on the target machine either in `~/.config/sops/age/keys.txt` or somewhere else with `SOPS_AGE_KEY_FILE` environment variable set. The installation script will copy the keys to persistent storage. -Pick the host configuration you want to install -and the devices for disks referenced in the configuration. -For example, if you want to install the `dummy` host configuration -and you have a single disk `/dev/sda`, run: +Change the HOST variable to the name of the host configuration +you want to install and run: ```sh -sudo nix --experimental-features 'nix-command flakes' run github:spietras/systems#dummy-install-script -- --main /dev/sda +sudo nix --experimental-features 'nix-command flakes' run "github:spietras/systems#${HOST}-install-script" ``` and then reboot the machine. - -Installation scripts are customized for each host configuration. -If you want more information about available options, use the `--help` flag. -For example for the `dummy` host configuration: - - - -```sh -sudo nix --experimental-features 'nix-command flakes' run github:spietras/systems#dummy-install-script -- --help -``` - - diff --git a/src/hosts/xenon/modules/constants/default.nix b/src/hosts/xenon/modules/constants/default.nix index 424cfb4..e250fe7 100644 --- a/src/hosts/xenon/modules/constants/default.nix +++ b/src/hosts/xenon/modules/constants/default.nix @@ -174,6 +174,18 @@ type = lib.types.str; }; + storage = { + disks = { + main = lib.mkOption { + device = lib.mkOption { + default = "/dev/disk/by-id/ata-TEAM_T253240GB_TPBF2209020010203322"; + description = "Device path of the main disk"; + type = lib.types.str; + }; + }; + }; + }; + vm = { cpu = { cores = lib.mkOption { diff --git a/src/hosts/xenon/modules/install/default.nix b/src/hosts/xenon/modules/install/default.nix index 3de22c9..175e142 100644 --- a/src/hosts/xenon/modules/install/default.nix +++ b/src/hosts/xenon/modules/install/default.nix @@ -23,6 +23,7 @@ # Provide values to substitute flake = inputs.self; host = config.constants.name; + main = config.constants.storage.disks.main.device; } ); }; diff --git a/src/hosts/xenon/modules/install/install.sh b/src/hosts/xenon/modules/install/install.sh index 8ba1fb6..83f3dad 100755 --- a/src/hosts/xenon/modules/install/install.sh +++ b/src/hosts/xenon/modules/install/install.sh @@ -4,6 +4,7 @@ FLAKE='@flake@' HOST='@host@' +MAIN='@main@' ### HELPER FUNCTIONS ### @@ -11,26 +12,20 @@ print_usage() { # Print script usage cat <&2 - print_usage >&2 - exit 1 -fi - -if [[ ! -e ${main} ]]; then - printf '%s\n' "Error: Device ${main} does not exist." >&2 - print_usage >&2 - exit 2 -fi - if [[ ! -e ${keyfile} ]]; then printf '%s\n' "Error: Key file ${keyfile} does not exist." >&2 print_usage >&2 - exit 3 + exit 1 fi ### MAIN ### disko-install \ --flake "${FLAKE}#${HOST}" \ - --disk main "${main}" \ + --disk main "${MAIN}" \ --extra-files "${keyfile}" /var/lib/sops/age/keys.txt \ --write-efi-boot-entries \ "$@" diff --git a/src/hosts/xenon/modules/storage/default.nix b/src/hosts/xenon/modules/storage/default.nix index af52c3b..9dc31cc 100644 --- a/src/hosts/xenon/modules/storage/default.nix +++ b/src/hosts/xenon/modules/storage/default.nix @@ -1,5 +1,9 @@ # Storage configuration -{inputs, ...}: { +{ + config, + inputs, + ... +}: { imports = [ # Import Disko modules inputs.disko.nixosModules.disko @@ -50,6 +54,8 @@ }; }; }; + + device = config.constants.storage.disks.main.device; }; }; };