[Nix-dev] Multiple MySQL instances (or nginx/apache/...)

Marc Weber marco-oweber at gmx.de
Sat Jan 3 14:23:14 CET 2015


How should this be written in the future ?

I've submitted a pull request which tries to change not much lines to
reach my goal - however I agree that it might not be the perfect
solution yet: https://github.com/NixOS/nixpkgs/pull/5542

This change adds a parameter moduleName to the mysql module which then
gets used for most defaults (pid file, data dir and so on)

    { moduleName ? "mysql"}: # eg pass mysql2 to add a second mysql

        services.${moduleName} = {
     
           enable = mkOption {
             default = false;
           };
     
           user = mkOption {
             default = moduleName;
    [...]


Final usage look like this:

   imports = [
        (import (<nixpkgs>+"/nixos/modules/services/databases/mysql.nix") {moduleName = "mysql_on_tmp"; })
    ]

    services.mysql_on_tmp.enable = true;
    services.mysql_on_tmp.port = 3307;
    services.mysql_on_tmp.package = pkgs.mysql55;
    services.mysql_on_tmp.dataDir = "/tmp/mysql";
    services.mysql_on_tmp.socketDir = "/tmp/mysql_tmpfs.socket";

    ids.uids.mysql_on_tmp = 20000;
    ids.gids.mysql_on_tmp = 20000;



If there are existing beter solutions let me know and or comment to
either the pull request or this thread.


I guess the most interesting point is uid/gid handling.

Introducing a style will affect almost all services ..


lethalman proposes such style:

  services.mysql.instances.<name> = ...

I agree that this style is nicer. Do you agree?
Should services.mysql be mapped to services.mysql.instances.default then?
Then backward compatibility could be preserved.

Marc Weber


More information about the nix-dev mailing list