nixos/mysql: use systemd StateDirectory to provision the data directory
This commit is contained in:
@@ -68,7 +68,14 @@ in
|
||||
dataDir = mkOption {
|
||||
type = types.path;
|
||||
example = "/var/lib/mysql";
|
||||
description = "Location where MySQL stores its table files.";
|
||||
description = ''
|
||||
The data directory for MySQL.
|
||||
|
||||
<note><para>
|
||||
If left as the default value of <literal>/var/lib/mysql</literal> this directory will automatically be created before the MySQL
|
||||
server starts, otherwise you are responsible for ensuring the directory exists with appropriate ownership and permissions.
|
||||
</para></note>
|
||||
'';
|
||||
};
|
||||
|
||||
configFile = mkOption {
|
||||
@@ -341,11 +348,6 @@ in
|
||||
|
||||
environment.etc."my.cnf".source = cfg.configFile;
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0700 '${cfg.user}' '${cfg.group}' - -"
|
||||
"z '${cfg.dataDir}' 0700 '${cfg.user}' '${cfg.group}' - -"
|
||||
];
|
||||
|
||||
systemd.services.mysql = let
|
||||
hasNotify = isMariaDB;
|
||||
in {
|
||||
@@ -489,7 +491,8 @@ in
|
||||
'') cfg.ensureUsers}
|
||||
'';
|
||||
|
||||
serviceConfig = {
|
||||
serviceConfig = mkMerge [
|
||||
{
|
||||
Type = if hasNotify then "notify" else "simple";
|
||||
Restart = "on-abort";
|
||||
RestartSec = "5s";
|
||||
@@ -523,7 +526,12 @@ in
|
||||
PrivateMounts = true;
|
||||
# System Call Filtering
|
||||
SystemCallArchitectures = "native";
|
||||
};
|
||||
}
|
||||
(mkIf (cfg.dataDir == "/var/lib/mysql") {
|
||||
StateDirectory = "mysql";
|
||||
StateDirectoryMode = "0700";
|
||||
})
|
||||
];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user