55 lines
1.2 KiB
Nix
55 lines
1.2 KiB
Nix
# Module: roles/dbserver-mariadb
|
|
# Enables a database server running MariaDB
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
pkgsUnstable,
|
|
inputs,
|
|
...
|
|
}:
|
|
|
|
with lib;
|
|
|
|
let
|
|
cfg = config.dbserver-mariadb;
|
|
defaultDBPackage = pkgs.mariadb;
|
|
defaultPyMySQLPackage = pkgs.python313Packages.pymysql;
|
|
in
|
|
{
|
|
options.dbserver-mariadb = {
|
|
enable = mkEnableOption "Enables dbserver-mariadb role";
|
|
|
|
dbPackage = mkOption {
|
|
type = types.package;
|
|
default = defaultDBPackage;
|
|
description = "Package to use for the database server";
|
|
example = mariadb;
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
environment.systemPackages = with pkgs; [
|
|
cfg.dbPackage
|
|
(python3.withPackages (ps: [ ps.pymysql ]))
|
|
];
|
|
|
|
services.mysql = {
|
|
enable = true;
|
|
package = cfg.dbPackage;
|
|
};
|
|
|
|
environment.etc."alloy/mariadb.alloy".text = ''
|
|
prometheus.exporter.mysql "mariadb" {
|
|
data_source_name = "{{ mariadb_role_alloy }}@(localhost)/"
|
|
enable_collectors = ["heartbeat", "mysql.user"]
|
|
}
|
|
|
|
prometheus.scrape "mariadb_scrape" {
|
|
targets = prometheus.exporter.mysql.mariadb.targets
|
|
forward_to = [prometheus.remote_write.default.receiver]
|
|
}
|
|
'';
|
|
};
|
|
}
|