Skip to content

Commit 2746707

Browse files
authored
Cleaned up storage configuration (#3)
1 parent cc1aa71 commit 2746707

File tree

5 files changed

+49
-57
lines changed

5 files changed

+49
-57
lines changed

src/src/hosts/dummy/modules/constants/default.nix

+12
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
type = lib.types.str;
2525
};
2626

27+
storage = {
28+
disks = {
29+
main = {
30+
device = lib.mkOption {
31+
default = "/dev/sda";
32+
description = "Device path of the main disk";
33+
type = lib.types.str;
34+
};
35+
};
36+
};
37+
};
38+
2739
vm = {
2840
cpu = {
2941
cores = lib.mkOption {

src/src/hosts/dummy/modules/install/default.nix

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
# Provide values to substitute
2727
flake = inputs.self;
2828
host = config.constants.name;
29+
main = config.constants.storage.disks.main.device;
2930
}
3031
);
3132
};

src/src/hosts/dummy/modules/install/install.sh

+4-21
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,28 @@
44

55
FLAKE='@flake@'
66
HOST='@host@'
7+
MAIN='@main@'
78

89
### HELPER FUNCTIONS ###
910

1011
print_usage() {
1112
# Print script usage
1213

1314
cat <<EOF
14-
Usage: $0 --main DEVICE [-k KEYFILE] [OPTIONS]
15+
Usage: $0 [-k KEYFILE] [OPTIONS]
1516
Install the system on this machine.
1617
17-
--main path to the device with the main disk
1818
-k, --keyfile path to the age key file
1919
EOF
2020
}
2121

2222
### PARSE ARGUMENTS ###
2323

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

2827
while [[ -n ${1:-} ]]; do
2928
case "$1" in
30-
--main)
31-
shift
32-
main="$1"
33-
;;
3429
-k | --keyfile)
3530
shift
3631
keyfile="$1"
@@ -52,29 +47,17 @@ done
5247
# shellcheck disable=SC2086
5348
set -- ${unparsed}
5449

55-
if [[ -z ${main} ]]; then
56-
printf '%s\n' 'Error: --main is required.' >&2
57-
print_usage >&2
58-
exit 1
59-
fi
60-
61-
if [[ ! -e ${main} ]]; then
62-
printf '%s\n' "Error: Device ${main} does not exist." >&2
63-
print_usage >&2
64-
exit 2
65-
fi
66-
6750
if [[ ! -e ${keyfile} ]]; then
6851
printf '%s\n' "Error: Key file ${keyfile} does not exist." >&2
6952
print_usage >&2
70-
exit 3
53+
exit 1
7154
fi
7255

7356
### MAIN ###
7457

7558
disko-install \
7659
--flake "${FLAKE}#${HOST}" \
77-
--disk main "${main}" \
60+
--disk main "${MAIN}" \
7861
--extra-files "${keyfile}" /var/lib/sops/age/keys.txt \
7962
--write-efi-boot-entries \
8063
"$@"

src/src/hosts/dummy/modules/storage/default.nix

+29-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Storage configuration
2-
{inputs, ...}: {
2+
{
3+
config,
4+
inputs,
5+
...
6+
}: {
37
imports = [
48
# Import Disko modules
59
inputs.disko.nixosModules.disko
@@ -10,46 +14,52 @@
1014
disk = {
1115
main = {
1216
content = {
13-
# Use GPT partition table
14-
type = "gpt";
15-
1617
partitions = {
1718
boot = {
18-
# Size of the boot partition
19-
size = "512M";
20-
21-
# EFI system partition
22-
type = "EF00";
23-
2419
content = {
25-
# This partition contains a filesystem
26-
type = "filesystem";
27-
2820
# Format the partition as FAT
2921
format = "vfat";
3022

3123
# Mount the partition at /boot
3224
mountpoint = "/boot";
25+
26+
# This partition contains a filesystem
27+
type = "filesystem";
3328
};
29+
30+
# Size of the boot partition
31+
size = "1G";
32+
33+
# EFI system partition
34+
type = "EF00";
3435
};
3536

3637
main = {
37-
# Use the rest of the disk for the main partition
38-
size = "100%";
39-
4038
content = {
41-
# This partition contains a filesystem
42-
type = "filesystem";
43-
4439
# Format the partition as ext4
4540
format = "ext4";
4641

4742
# Mount the partition at /
4843
mountpoint = "/";
44+
45+
# This partition contains a filesystem
46+
type = "filesystem";
4947
};
48+
49+
# Use the rest of the disk for the main partition
50+
size = "100%";
51+
52+
# Linux filesystem partition
53+
type = "8300";
5054
};
5155
};
56+
57+
# Use GPT partition table
58+
type = "gpt";
5259
};
60+
61+
device = config.constants.storage.disks.main.device;
62+
type = "disk";
5363
};
5464
};
5565
};

src/{% if docs %}docs{% endif %}/docs/02-Installation.md.jinja

+3-17
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,15 @@ private keys on the target machine either in `~/.config/sops/age/keys.txt`
2323
or somewhere else with `SOPS_AGE_KEY_FILE` environment variable set.
2424
The installation script will copy the keys to persistent storage.
2525

26-
Pick the host configuration you want to install
27-
and the devices for disks referenced in the configuration.
28-
For example, if you want to install the `dummy` host configuration
29-
and you have a single disk `/dev/sda`, run:
26+
Change the HOST variable to the name of the host configuration
27+
you want to install and run:
3028

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

3331
```sh
34-
sudo nix --experimental-features 'nix-command flakes' run github:{{ accountname }}/{{ reponame }}#dummy-install-script -- --main /dev/sda
32+
sudo nix --experimental-features 'nix-command flakes' run "github:{{ accountname }}/{{ reponame }}#${HOST}-install-script"
3533
```
3634

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

3937
and then reboot the machine.
40-
41-
Installation scripts are customized for each host configuration.
42-
If you want more information about available options, use the `--help` flag.
43-
For example for the `dummy` host configuration:
44-
45-
<!-- markdownlint-disable line-length -->
46-
47-
```sh
48-
sudo nix --experimental-features 'nix-command flakes' run github:{{ accountname }}/{{ reponame }}#dummy-install-script -- --help
49-
```
50-
51-
<!-- markdownlint-enable line-length -->

0 commit comments

Comments
 (0)