Skip to content

Commit 2af8f27

Browse files
authored
Cleaned up (#4)
1 parent 2746707 commit 2af8f27

File tree

7 files changed

+64
-45
lines changed

7 files changed

+64
-45
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
availableKernelModules = [
77
# These were autodetected by nixos-generate-config
88
"ahci"
9-
"xhci_pci"
10-
"virtio_pci"
119
"sr_mod"
10+
"virtio_pci"
1211
"virtio_blk"
12+
"xhci_pci"
1313
];
1414
};
1515

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+
secrets = {
28+
sops = {
29+
age = {
30+
file = lib.mkOption {
31+
default = "/var/lib/sops/age/keys.txt";
32+
description = "Path to the file with private age keys";
33+
type = lib.types.str;
34+
};
35+
};
36+
};
37+
};
38+
2739
storage = {
2840
disks = {
2941
main = {
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
# Install script
22
{
3-
inputs,
43
config,
4+
inputs,
55
lib,
66
pkgs,
77
...
8-
}: {
9-
options = {
10-
installScript = lib.mkOption {
11-
# Create shell script
12-
default = pkgs.writeShellApplication {
13-
# Name of the script
14-
name = "install";
8+
}: let
9+
script = pkgs.writeShellApplication {
10+
# Name of the script
11+
name = "install";
1512

16-
# Packages available in the script
17-
runtimeInputs = [pkgs.coreutils pkgs.disko];
13+
# Packages available in the script
14+
runtimeInputs = [pkgs.coreutils pkgs.disko];
1815

19-
# Load the script with substituted values
20-
text = builtins.readFile (
21-
# Substitute values in the script
22-
pkgs.substituteAll {
23-
# Use this file as source
24-
src = ./install.sh;
16+
# Load the script with substituted values
17+
text = builtins.readFile (
18+
# Substitute values in the script
19+
pkgs.substituteAll {
20+
# Use this file as source
21+
src = ./install.sh;
2522

26-
# Provide values to substitute
27-
flake = inputs.self;
28-
host = config.constants.name;
29-
main = config.constants.storage.disks.main.device;
30-
}
31-
);
32-
};
23+
# Provide values to substitute
24+
flake = inputs.self;
25+
host = config.constants.name;
26+
keysFile = config.constants.secrets.sops.age.file;
27+
mainDiskDevice = config.constants.storage.disks.main.device;
28+
}
29+
);
30+
};
31+
in {
32+
options = {
33+
installScript = lib.mkOption {
34+
default = script;
3335
};
3436
};
3537
}

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,32 @@
44

55
FLAKE='@flake@'
66
HOST='@host@'
7-
MAIN='@main@'
7+
KEYS_FILE='@keysFile@'
8+
MAIN_DISK_DEVICE='@mainDiskDevice@'
89

910
### HELPER FUNCTIONS ###
1011

1112
print_usage() {
1213
# Print script usage
1314

1415
cat <<EOF
15-
Usage: $0 [-k KEYFILE] [OPTIONS]
16+
Usage: $0 [-k KEYSFILE] [OPTIONS]
1617
Install the system on this machine.
1718
18-
-k, --keyfile path to the age key file
19+
-k, --keysfile path to the age keys file
1920
EOF
2021
}
2122

2223
### PARSE ARGUMENTS ###
2324

24-
keyfile="${SOPS_AGE_KEY_FILE:-${SOPS_AGE_KEY_DIR:-${XDG_CONFIG_HOME:-${HOME}/.config}/sops/age}/keys.txt}"
25+
keysfile="${SOPS_AGE_KEY_FILE:-${SOPS_AGE_KEY_DIR:-${XDG_CONFIG_HOME:-${HOME}/.config/}/sops/age/}/keys.txt}"
2526
unparsed=''
2627

2728
while [[ -n ${1:-} ]]; do
2829
case "$1" in
29-
-k | --keyfile)
30+
-k | --keysfile)
3031
shift
31-
keyfile="$1"
32+
keysfile="$1"
3233
;;
3334
-h | --help)
3435
print_usage >&2
@@ -47,8 +48,8 @@ done
4748
# shellcheck disable=SC2086
4849
set -- ${unparsed}
4950

50-
if [[ ! -e ${keyfile} ]]; then
51-
printf '%s\n' "Error: Key file ${keyfile} does not exist." >&2
51+
if [[ ! -e ${keysfile} ]]; then
52+
printf '%s\n' "Error: Keys file ${keysfile} does not exist." >&2
5253
print_usage >&2
5354
exit 1
5455
fi
@@ -57,7 +58,7 @@ fi
5758

5859
disko-install \
5960
--flake "${FLAKE}#${HOST}" \
60-
--disk main "${MAIN}" \
61-
--extra-files "${keyfile}" /var/lib/sops/age/keys.txt \
61+
--disk main "${MAIN_DISK_DEVICE}" \
62+
--extra-files "${keysfile}" "${KEYS_FILE}" \
6263
--write-efi-boot-entries \
6364
"$@"

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
nix = {
44
settings = {
55
experimental-features = [
6-
# Enable commands
7-
"nix-command"
8-
96
# Enable flakes
107
"flakes"
8+
9+
# Enable commands
10+
"nix-command"
1111
];
1212
};
1313
};

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Secrets configuration
2-
{inputs, ...}: {
2+
{
3+
config,
4+
inputs,
5+
...
6+
}: {
37
imports = [
48
# Import sops modules
59
inputs.sops-nix.nixosModules.sops
@@ -8,7 +12,7 @@
812
sops = {
913
age = {
1014
# age private keys should be stored at this path on the host
11-
keyFile = "/var/lib/sops/age/keys.txt";
15+
keyFile = config.constants.secrets.sops.age.file;
1216

1317
# This is needed so that ssh keys are not unnecessarily picked up
1418
sshKeyPaths = [];

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@
2727

2828
# Shared directories between the virtual machine and your development machine
2929
sharedDirectories = {
30-
# This is needed to transmit your age private key to the virtual machine
31-
age-key = {
32-
# The private key should be stored at this path on your development machine
33-
source = "\${SOPS_AGE_KEY_DIR:-\${XDG_CONFIG_HOME:-$HOME/.config}/sops/age}";
30+
# This is needed to transmit your age private keys to the virtual machine
31+
sops-age-keys = {
32+
# The private keys should be stored at this path on your development machine
33+
source = "\${SOPS_AGE_KEY_DIR:-\${XDG_CONFIG_HOME:-$HOME/.config/}/sops/age/}";
3434

3535
# And will be mounted in the virtual machine at this path
36-
target = "/var/lib/sops/age";
36+
target = builtins.dirOf config.constants.secrets.sops.age.file;
3737
};
3838
};
3939
};

0 commit comments

Comments
 (0)