Skip to content

Commit

Permalink
Cleaned up storage configuration (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
spietras authored May 2, 2024
1 parent ce1f311 commit a8dee45
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
20 changes: 3 additions & 17 deletions docs/docs/02-Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

<!-- markdownlint-disable line-length -->

```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"
```

<!-- markdownlint-enable line-length -->

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:

<!-- markdownlint-disable line-length -->

```sh
sudo nix --experimental-features 'nix-command flakes' run github:spietras/systems#dummy-install-script -- --help
```

<!-- markdownlint-enable line-length -->
12 changes: 12 additions & 0 deletions src/hosts/xenon/modules/constants/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/hosts/xenon/modules/install/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# Provide values to substitute
flake = inputs.self;
host = config.constants.name;
main = config.constants.storage.disks.main.device;
}
);
};
Expand Down
25 changes: 4 additions & 21 deletions src/hosts/xenon/modules/install/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,28 @@

FLAKE='@flake@'
HOST='@host@'
MAIN='@main@'

### HELPER FUNCTIONS ###

print_usage() {
# Print script usage

cat <<EOF
Usage: $0 --main DEVICE [-k KEYFILE] [OPTIONS]
Usage: $0 [-k KEYFILE] [OPTIONS]
Install the system on this machine.
--main path to the device with the main disk
-k, --keyfile path to the age key file
EOF
}

### PARSE ARGUMENTS ###

main=''
keyfile="${SOPS_AGE_KEY_FILE:-${SOPS_AGE_KEY_DIR:-${XDG_CONFIG_HOME:-${HOME}/.config}/sops/age}/keys.txt}"
unparsed=''

while [[ -n ${1:-} ]]; do
case "$1" in
--main)
shift
main="$1"
;;
-k | --keyfile)
shift
keyfile="$1"
Expand All @@ -52,29 +47,17 @@ done
# shellcheck disable=SC2086
set -- ${unparsed}

if [[ -z ${main} ]]; then
printf '%s\n' 'Error: --main is required.' >&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 \
"$@"
8 changes: 7 additions & 1 deletion src/hosts/xenon/modules/storage/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Storage configuration
{inputs, ...}: {
{
config,
inputs,
...
}: {
imports = [
# Import Disko modules
inputs.disko.nixosModules.disko
Expand Down Expand Up @@ -50,6 +54,8 @@
};
};
};

device = config.constants.storage.disks.main.device;
};
};
};
Expand Down

0 comments on commit a8dee45

Please sign in to comment.