parameterize data disk mount point

This commit is contained in:
Pim Kunis 2023-12-15 15:20:28 +01:00
parent b6a37eabbd
commit 38fce7d2b4
3 changed files with 28 additions and 12 deletions

View file

@ -3,17 +3,35 @@ let cfg = config.custom.dataDisk;
in { in {
options = { options = {
custom = { custom = {
dataDisk.enable = lib.mkOption { dataDisk = {
enable = lib.mkOption {
default = false; default = false;
type = lib.types.bool; type = lib.types.bool;
description = '' description = ''
Whether to automatically mount /dev/sda1 on /mnt/data Whether to automatically mount a disk to be used as a data disk.
''; '';
}; };
mountPoint = lib.mkOption {
default = "/mnt/data";
type = lib.types.str;
description = ''
Mount point of the data disk (if enabled).
'';
};
devicePath = lib.mkOption {
default = "/dev/sda1";
type = lib.types.str;
description = ''
Path of the device to be used as a data disk.
'';
};
};
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {
fileSystems."/mnt/data" = { device = "/dev/sda1"; }; fileSystems.${cfg.mountPoint} = { device = cfg.devicePath; };
}; };
} }

View file

@ -17,17 +17,15 @@ in {
environment.systemPackages = [ pkgs.k3s ]; environment.systemPackages = [ pkgs.k3s ];
services.k3s.enable = true; services.k3s.enable = true;
services.k3s.role = "server"; services.k3s.role = "server";
# TODO: parameterize data disk mount point. services.k3s.extraFlags = "--tls-san ${config.networking.fqdn} --data-dir ${config.custom.dataDisk.mountPoint}/k3s";
services.k3s.extraFlags = "--tls-san ${config.networking.fqdn} --data-dir /mnt/data/k3s";
# TODO: parameterize data disk mount point.
# TODO: use kubenix for this. # TODO: use kubenix for this.
system.activationScripts.k3s-bootstrap.text = system.activationScripts.k3s-bootstrap.text =
let let
k3sBootstrapFile = pkgs.writeText "k3s-bootstrap" (builtins.readFile ./k3s-bootstrap.yaml); k3sBootstrapFile = pkgs.writeText "k3s-bootstrap" (builtins.readFile ./k3s-bootstrap.yaml);
in in
'' ''
ln -sf ${k3sBootstrapFile} /mnt/data/k3s/server/manifests/k3s-bootstrap.yaml ln -sf ${k3sBootstrapFile} ${config.custom.dataDisk.mountPoint}/k3s/server/manifests/k3s-bootstrap.yaml
''; '';
}; };
} }

View file

@ -20,7 +20,7 @@ in {
package = pkgs.postgresql_15; package = pkgs.postgresql_15;
enableTCPIP = true; enableTCPIP = true;
dataDir = lib.mkIf config.custom.dataDisk.enable dataDir = lib.mkIf config.custom.dataDisk.enable
"/mnt/data/postgresql/${config.services.postgresql.package.psqlSchema}"; "${config.custom.dataDisk.mountPoint}/postgresql/${config.services.postgresql.package.psqlSchema}";
authentication = '' authentication = ''
hostssl terraformstates terraform all cert hostssl terraformstates terraform all cert
''; '';