You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 satır
2.0KB

  1. {
  2. description = "NixOS MariaDB server";
  3. inputs = {
  4. nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";
  5. };
  6. outputs = { self, nixpkgs, ... }: {
  7. nixosModules.mariadb = { config, lib, pkgs, ... }:
  8. let
  9. cfg = config.mariadb;
  10. in
  11. {
  12. options.mariadb = {
  13. enable = lib.mkOption {
  14. type = lib.types.bool;
  15. };
  16. rootPasswordFile = lib.mkOption {
  17. type = lib.types.path;
  18. description = "Path to file containing the root password.";
  19. };
  20. nextcloudPasswordFile = lib.mkOption {
  21. type = lib.types.path;
  22. description = "Path to file containing the nextcloud user password.";
  23. };
  24. };
  25. config = lib.mkIf cfg.enable {
  26. services.mysql = {
  27. #enable = true;
  28. enable = false;
  29. package = pkgs.mariadb;
  30. #ensureDatabases = [ "nextcloud" ];
  31. #ensureUsers = [
  32. # {
  33. # name = "nextcloud";
  34. # ensurePermissions = { "nextcloud.*" = "ALL PRIVILEGES"; };
  35. # }
  36. # ];
  37. };
  38. # systemd script to set up users passwords
  39. # systemd.services.mariadb-set-nextcloud-password = {
  40. # description = "Set MariaDB user passwords from file";
  41. # after = [ "mysql.service" ];
  42. # requires = [ "mysql.service" ];
  43. # wantedBy = [ "multi-user.target" ];
  44. # serviceConfig = {
  45. # Type = "oneshot";
  46. # RemainAfterExit = true;
  47. # };
  48. # script = ''
  49. # set -euo pipefail
  50. # echo "Setting nextcloud user password..."
  51. # PASSWORD=$(cat "${cfg.nextcloudPasswordFile}")
  52. # ${pkgs.mariadb}/bin/mysql -u root -p"$(cat ${cfg.rootPasswordFile})" -e "ALTER USER 'nextcloud'@'localhost' IDENTIFIED BY '$PASSWORD';"
  53. # echo "Nextcloud user password set."
  54. # '';
  55. # };
  56. };
  57. };
  58. };
  59. }