Adjust MySQL socket file name generation so that no socket parameter to the client is required for a standard installation

This commit is contained in:
Sander van der Burg 2020-10-05 22:50:42 +02:00 committed by Sander van der Burg
parent de1c8b15b9
commit 1590fa145b
3 changed files with 33 additions and 11 deletions

View File

@ -624,8 +624,8 @@ these values as parameters, but a more convenient way is to instrument the
`createCredentials` function -- the above `processes.nix` expression propagates
the entire `ids` attribute set as a parameter to the constructors.
The constructors expression indirectly composes the `createCredentials` as
follows:
The constructors expression indirectly composes the `createCredentials` function
as follows:
```nix
{pkgs, ids ? {}, ...}:
@ -640,10 +640,10 @@ follows:
}
```
It propagates the `ids` to the function that composes the `createCredentials`
function. As a result, it will automatically assign the UIDs and GIDs in the
`ids.nix` expression when the user configures a user or group with a name that
exists in the `uids` and `gids` resource pools.
The `ids` attribute set is propagated to the function that composes the
`createCredentials` function. As a result, it will automatically assign the UIDs
and GIDs in the `ids.nix` expression when the user configures a user or group
with a name that exists in the `uids` and `gids` resource pools.
To make these UIDs and GIDs assignments go smoothly, it is recommended to give
a process the same process name, instance name, user and group names.

View File

@ -2,12 +2,22 @@
{port ? 3306, instanceSuffix ? "", instanceName ? "mysql${instanceSuffix}", containerName ? "mysql-database${instanceSuffix}", type}:
let
mysqlSocket = "${runtimeDir}/${instanceName}/${instanceName}.sock";
# By default, the socket file resides in $runtimeDir/mysqld/mysqld.sock.
# We only change the path component: 'mysqld' into the instance name if no
# instanceSuffix parameter is specified. Otherwise, we append the
# instanceSuffix to 'mysqld'.
#
# This construction is used to allow the mysql client executable to work
# without a socket parameter for the default configuration.
mysqlSocket =
if instanceName != "mysql" && instanceSuffix == "" then "${runtimeDir}/${instanceName}/mysqld.sock"
else "${runtimeDir}/mysqld${instanceSuffix}/mysqld.sock";
mysqlUsername = "root";
pkg = mysqlConstructorFun {
inherit port instanceName;
inherit port instanceName instanceSuffix;
postInstall = ''
# Add Dysnomia container configuration file for MySQL database
mkdir -p $out/etc/dysnomia/containers

View File

@ -1,9 +1,21 @@
{createManagedProcess, stdenv, mysql, stateDir, runtimeDir, forceDisableUserChange}:
{port ? 3306, instanceSuffix ? "", instanceName ? "mysqld${instanceSuffix}", postInstall ? ""}:
{port ? 3306, instanceSuffix ? "", instanceName ? "mysql${instanceSuffix}", postInstall ? ""}:
let
dataDir = "${stateDir}/db/${instanceName}";
instanceRuntimeDir = "${runtimeDir}/${instanceName}";
# By default, the socket file resides in $runtimeDir/mysqld/mysqld.sock.
# We only change the path component: 'mysqld' into the instance name if no
# instanceSuffix parameter is specified. Otherwise, we append the
# instanceSuffix to 'mysqld'.
#
# This construction is used to allow the mysql client executable to work
# without a socket parameter for the default configuration.
instanceRuntimeDir =
if instanceName != "mysql" && instanceSuffix == "" then "${runtimeDir}/${instanceName}"
else "${runtimeDir}/mysqld${instanceSuffix}";
user = instanceName;
group = instanceName;
in
@ -27,7 +39,7 @@ createManagedProcess {
'';
foregroundProcess = "${mysql}/bin/mysqld";
foregroundProcessArgs = [ "--basedir" mysql "--datadir" dataDir "--port" port "--socket" "${instanceRuntimeDir}/${instanceName}.sock" ]
foregroundProcessArgs = [ "--basedir" mysql "--datadir" dataDir "--port" port "--socket" "${instanceRuntimeDir}/mysqld.sock" ]
++ stdenv.lib.optionals (!forceDisableUserChange) [ "--user" user ];
credentials = {