Can't connect to mariadb socket in devenv

I am trying to setup a MariaDB - PHP - Node / Elm devenv. I am following this topic to install mariadb in a flake.

My flake.nix:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
    systems.url = "github:nix-systems/default";
    devenv.url = "github:cachix/devenv";
  };

  outputs = { self, nixpkgs, devenv, systems, ... }@inputs:
    let forEachSystem = nixpkgs.lib.genAttrs (import systems);
    in {
      devShells = forEachSystem (system:
        let pkgs = nixpkgs.legacyPackages.${system};
        in {
          default = devenv.lib.mkShell {
            inherit inputs pkgs;
            modules = [{
              packages = with pkgs; [
                dhall
                asciidoctor-with-extensions
                phpPackages.composer
                php82Packages.deployer
                php
                nodejs
                inotify-tools
                elmPackages.elm
                sass
                mariadb
              ];
              dotenv.enable = true;
              # https://devenv.sh/reference/options/
              services.mysql.package = pkgs.mariadb;
              services.mysql.enable = true;
              
              # https://shyim.me/blog/devenv-compose-developer-environment-for-php-with-nix/
              services.mysql.initialDatabases = [{ name = "app"; }];
              services.mysql.ensureUsers = [
                {
                  name = "app";
                  password = "app";
                  ensurePermissions = { "app.*" = "ALL PRIVILEGES"; };
                }
              ];

              # Project specific MySQL config like require always a primary key
              services.mysql.settings.mysqld = {
                "sql_require_primary_key" = "on";
              };
            }];
          };
        });
    };
}

I am starting the devenv using nix develop --impure . I am trying to connect using mariadb -uapp -p but then receive

Enter password: 
ERROR 2002 (HY000): Can't connect to local server through socket '/run/mysqld/mysqld.sock' (2)

It seems mysql is not running as ps aux | grep mysql only shows the grep task.

How can I resolve/debug this issue? Is there any log to check?

❯ nix --version                 
nix (Nix) 2.11.1

Could you paste the logs from devenv up?

I first run nix develop --impure. Then devenv up results in the following output:

$ devenv up
warning: Git tree '/home/Documents/repos/collect' is dirty
error: flake 'git+file:///home/Documents/repos/collect' does not provide attribute 'packages.x86_64-linux.devenv-up', 'legacyPackages.x86_64-linux.devenv-up' or 'devenv-up'

I assume direnv should not interfere with this?

I don’t think devenv up is necessary when using flakes.

The devenv command is for use standalone with a devenv.nix or devenv.yaml file. Since you’re building the dev shell yourself you can run nix develop to use it, no need for the devenv command.
https://www.reddit.com/r/Nix/comments/15aa6up/unable_to_use_devenv_up_with_flake_flake_does_not/

So nix develop --impure should be sufficient. However I do not understand why the mysql service does not exist within the develop shell:

 systemctl status mariadb
Unit mariadb.service could not be found.
(devenv) 
1 Like

Hey, were you able to figure out this?