cleanup nixos modules a bit

This commit is contained in:
Pim Kunis 2023-12-29 13:46:12 +01:00
parent 1f5d121fd0
commit 7222254c22
7 changed files with 90 additions and 110 deletions

View file

@ -3,7 +3,7 @@
name = "jefke";
hostName = "jefke.hyp";
nixosModule.custom = {
nixosModule.lab = {
dataDisk.enable = true;
terraformDatabase.enable = true;
# k3s.enable = true;
@ -21,7 +21,7 @@
name = "atlas";
hostName = "atlas.hyp";
nixosModule.custom = {
nixosModule.lab = {
disko.osDiskDevice = "/dev/nvme0n1";
ssh = {
@ -36,7 +36,7 @@
name = "lewis";
hostName = "lewis.hyp";
nixosModule.custom = {
nixosModule.lab = {
disko.osDiskDevice = "/dev/sda";
backups.enable = true;

View file

@ -1,6 +1,6 @@
{ pkgs, lib, config, ... }:
let
cfg = config.custom.backups;
cfg = config.lab.backups;
snapshotFile = "/tmp/snapshot.qcow2";
snapshotMount = "/tmp/snapshot";
beforeEverything = pkgs.writeShellScriptBin "beforeEverything" ''
@ -38,7 +38,7 @@ let
};
in
{
options.custom.backups = {
options.lab.backups = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
@ -48,7 +48,7 @@ in
};
repoLocation = lib.mkOption {
default = "${config.custom.dataDisk.mountPoint}/backups/thecloud-data.borg";
default = "${config.lab.dataDisk.mountPoint}/backups/thecloud-data.borg";
type = lib.types.str;
description = ''
Location of the Borg repository to back up to.

View file

@ -1,9 +1,7 @@
{ lib, config, ... }:
let cfg = config.custom.dataDisk;
let cfg = config.lab.dataDisk;
in {
options = {
custom = {
dataDisk = {
options.lab.dataDisk = {
enable = lib.mkOption {
default = false;
type = lib.types.bool;
@ -28,8 +26,6 @@ in {
'';
};
};
};
};
config = lib.mkIf cfg.enable {
fileSystems.${cfg.mountPoint} = { device = cfg.devicePath; };

View file

@ -1,16 +1,12 @@
{ lib, config, ... }:
let cfg = config.custom.disko;
let cfg = config.lab.disko;
in {
options = {
custom = {
disko.osDiskDevice = lib.mkOption {
options.lab.disko.osDiskDevice = lib.mkOption {
type = lib.types.str;
description = ''
The disk device to be used for the operating system.
'';
};
};
};
# TODO: rename this to 'osDisk'. Unfortunately, we would need to run nixos-anywhere again then
config.disko.devices.disk.vdb = {

View file

@ -1,17 +1,13 @@
{ pkgs, lib, config, kubenix, ... }:
let cfg = config.custom.k3s;
let cfg = config.lab.k3s;
in {
options = {
custom = {
k3s.enable = lib.mkOption {
options.lab.k3s.enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to start k3s with custom configuration.
'';
};
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ pkgs.k3s ];
@ -20,7 +16,7 @@ in {
services.k3s = {
enable = true;
role = "server";
extraFlags = "--tls-san ${config.networking.fqdn} --data-dir ${config.custom.dataDisk.mountPoint}/k3s";
extraFlags = "--tls-san ${config.networking.fqdn} --data-dir ${config.lab.dataDisk.mountPoint}/k3s";
};
system.activationScripts.k3s-bootstrap.text =
@ -30,7 +26,7 @@ in {
}).config.kubernetes.result;
in
''
ln -sf ${k3sBootstrapFile} ${config.custom.dataDisk.mountPoint}/k3s/server/manifests/k3s-bootstrap.json
ln -sf ${k3sBootstrapFile} ${config.lab.dataDisk.mountPoint}/k3s/server/manifests/k3s-bootstrap.json
'';
};
}

View file

@ -1,13 +1,11 @@
{ lib, config, ... }:
let
cfg = config.custom.ssh;
cfg = config.lab.ssh;
hostCert = builtins.toFile "host_ed25519-cert.pub" cfg.hostCert;
userCert = builtins.toFile "user_ed25519-cert.pub" cfg.userCert;
in
{
options = {
custom = {
ssh = {
options.lab.ssh = {
useCertificates = lib.mkOption {
type = lib.types.bool;
default = false;
@ -48,8 +46,6 @@ in
'';
};
};
};
};
config = lib.mkIf cfg.useCertificates {
services.openssh = {

View file

@ -1,27 +1,25 @@
{ pkgs, lib, config, ... }:
let cfg = config.custom.terraformDatabase;
let cfg = config.lab.terraformDatabase;
in {
options = {
custom = {
terraformDatabase.enable = lib.mkOption {
options.lab.terraformDatabase.enable = lib.mkOption {
default = false;
type = lib.types.bool;
description = ''
Whether to start a postgreSQL database for Terraform states
'';
};
};
};
config = lib.mkIf cfg.enable {
networking.firewall.allowedTCPPorts = [ 5432 ];
services.postgresql = {
enable = true;
ensureDatabases = [ "terraformstates" ];
package = pkgs.postgresql_15;
enableTCPIP = true;
dataDir = lib.mkIf config.custom.dataDisk.enable
"${config.custom.dataDisk.mountPoint}/postgresql/${config.services.postgresql.package.psqlSchema}";
dataDir = lib.mkIf config.lab.dataDisk.enable
"${config.lab.dataDisk.mountPoint}/postgresql/${config.services.postgresql.package.psqlSchema}";
authentication = ''
hostssl terraformstates terraform all cert
@ -45,8 +43,6 @@ in {
}];
};
networking.firewall.allowedTCPPorts = [ 5432 ];
age.secrets."postgresql_server.key" = {
file = ../secrets/postgresql_server.key.age;
mode = "400";