mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-13 21:25:30 +03:00
nixos/mysql: use systemd StateDirectory to provision the data directory
This commit is contained in:
parent
382e4ba09a
commit
c7cac1bdc0
1 changed files with 48 additions and 40 deletions
|
@ -68,7 +68,14 @@ in
|
||||||
dataDir = mkOption {
|
dataDir = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
example = "/var/lib/mysql";
|
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 {
|
configFile = mkOption {
|
||||||
|
@ -341,11 +348,6 @@ in
|
||||||
|
|
||||||
environment.etc."my.cnf".source = cfg.configFile;
|
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
|
systemd.services.mysql = let
|
||||||
hasNotify = isMariaDB;
|
hasNotify = isMariaDB;
|
||||||
in {
|
in {
|
||||||
|
@ -489,7 +491,8 @@ in
|
||||||
'') cfg.ensureUsers}
|
'') cfg.ensureUsers}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
serviceConfig = {
|
serviceConfig = mkMerge [
|
||||||
|
{
|
||||||
Type = if hasNotify then "notify" else "simple";
|
Type = if hasNotify then "notify" else "simple";
|
||||||
Restart = "on-abort";
|
Restart = "on-abort";
|
||||||
RestartSec = "5s";
|
RestartSec = "5s";
|
||||||
|
@ -523,7 +526,12 @@ in
|
||||||
PrivateMounts = true;
|
PrivateMounts = true;
|
||||||
# System Call Filtering
|
# System Call Filtering
|
||||||
SystemCallArchitectures = "native";
|
SystemCallArchitectures = "native";
|
||||||
};
|
}
|
||||||
|
(mkIf (cfg.dataDir == "/var/lib/mysql") {
|
||||||
|
StateDirectory = "mysql";
|
||||||
|
StateDirectoryMode = "0700";
|
||||||
|
})
|
||||||
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue