2024-03-23 02:30:39 +01:00
|
|
|
{ materusArg, config, lib, pkgs, ... }:
|
|
|
|
{
|
|
|
|
options.waffentragerService.elements.enable = materusArg.pkgs.lib.mkBoolOpt false "Enable elements drive";
|
|
|
|
options.waffentragerService.elements.path = lib.mkOption { default = "/var/lib/elements"; };
|
|
|
|
options.waffentragerService.elements.uuid = lib.mkOption { default = "e32039c6-e98d-44b0-8e7d-120994bf7be1"; };
|
2024-03-23 12:33:10 +01:00
|
|
|
options.waffentragerService.elements.postgresqlDir = lib.mkOption { default = "${config.waffentragerService.elements.path}/services/postgresql"; };
|
2024-03-25 19:46:18 +01:00
|
|
|
options.waffentragerService.elements.nextcloudDir = lib.mkOption { default = "${config.waffentragerService.elements.path}/services/nextcloud"; };
|
2024-07-13 15:44:07 +02:00
|
|
|
options.waffentragerService.elements.lldapDir = lib.mkOption { default = "${config.waffentragerService.elements.path}/services/lldap"; };
|
2024-08-08 20:45:42 +02:00
|
|
|
options.waffentragerService.elements.jellyfinDir = lib.mkOption { default = "${config.waffentragerService.elements.path}/services/jellyfin"; };
|
2024-09-12 11:55:35 +02:00
|
|
|
options.waffentragerService.elements.malojaDir = lib.mkOption { default = "${config.waffentragerService.elements.path}/services/maloja"; };
|
|
|
|
|
2024-03-23 02:30:39 +01:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
cfg = config.waffentragerService.elements;
|
|
|
|
in
|
|
|
|
lib.mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.elements-mount = {
|
2024-03-23 15:48:51 +01:00
|
|
|
description = "Decrypt and mount elements drive";
|
2024-03-23 02:30:39 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
path = [ pkgs.cryptsetup pkgs.coreutils pkgs.util-linux ];
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = true;
|
|
|
|
script = ''
|
|
|
|
mkdir -p ${cfg.path}
|
|
|
|
cryptsetup luksOpen /dev/disk/by-uuid/${cfg.uuid} elements -d ${config.sops.secrets.elements.path}
|
|
|
|
mount /dev/mapper/elements ${cfg.path}
|
2024-09-12 11:56:18 +02:00
|
|
|
''
|
|
|
|
|
|
|
|
;
|
|
|
|
preStop = ''
|
|
|
|
umount ${cfg.path}
|
|
|
|
cryptsetup luksClose elements
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.elements-dirmake = {
|
|
|
|
description = "Create dirs in elements drive";
|
|
|
|
path = [ pkgs.cryptsetup pkgs.coreutils pkgs.util-linux ];
|
|
|
|
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.RemainAfterExit = false;
|
|
|
|
script = lib.optionalString config.waffentragerService.postgresql.enable ''
|
2024-03-23 12:42:02 +01:00
|
|
|
mkdir -p ${cfg.postgresqlDir}/${config.waffentragerService.postgresql.version}
|
2024-03-23 12:33:10 +01:00
|
|
|
chown -R postgres:postgres ${cfg.postgresqlDir}
|
2024-03-25 19:46:18 +01:00
|
|
|
'' + lib.optionalString config.waffentragerService.nextcloud.enable ''
|
|
|
|
mkdir -p ${cfg.nextcloudDir}
|
|
|
|
chown -R nextcloud:nextcloud ${cfg.nextcloudDir}
|
2024-07-13 15:44:07 +02:00
|
|
|
'' + lib.optionalString config.waffentragerService.auth.lldap.enable ''
|
|
|
|
mkdir -p ${cfg.lldapDir}
|
|
|
|
chown -R lldap:lldap ${cfg.lldapDir}
|
2024-08-08 20:45:42 +02:00
|
|
|
'' + lib.optionalString config.waffentragerService.jellyfin.enable ''
|
|
|
|
mkdir -p ${cfg.jellyfinDir}
|
|
|
|
chown -R materus:nextcloud ${cfg.jellyfinDir}
|
2024-09-12 11:55:35 +02:00
|
|
|
'' + lib.optionalString config.waffentragerService.scrobbling.enable ''
|
|
|
|
mkdir -p ${cfg.malojaDir}/multi-scrobbler
|
2024-09-12 11:56:18 +02:00
|
|
|
chown -R scrobbler:scrobbler ${cfg.malojaDir}
|
2024-03-23 12:33:10 +01:00
|
|
|
''
|
|
|
|
|
2024-09-12 11:55:35 +02:00
|
|
|
|
2024-03-23 12:33:10 +01:00
|
|
|
;
|
2024-03-23 02:30:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|