I’m trying to run mysql80 package from nixpkgs on ubuntu, I have initialized the data directory and ran the mysqld command with --initialize-insecure option but I still can’t login to mysql, (shows access denied for root@localhost).
I think this maybe related to the fact that mysql is usually run using the mysql user.
Just wondering if someone’s figured out a way to run mysql like this
There’s actually two different questions here. I’m not familiar enough with MySQL to tell why it’s not letting you log in, but I am familiar enough with how Nix works to tell you you can’t really run “proper” system services from a flake, especially on non-NixOS. It’s entirely possible to have a completely user-level Nix install that does not have any sort of root access, and thus can’t manage “real” system services for something like systemd. The only real option here is to use a userspace process manager like supervisord and configure everything to run as the current user, without assuming you can get any level of system access.
But yes, as @K900 says, nix on other distros is purely a package manager. NixOS modules make a lot of assumptions about the underlying system, even if some services could in theory work the same on other distros it’d be far too difficult to make sure all of them do, and either way the entire symlink-based infra would be hard to force into a ubuntu host.
home-manager is an example of how you could nonetheless write a deployment manager, but the existing service configurations won’t be of use to you.
I don’t get this either. Homebrew can give me a running postgres install rather easily but with Nix I’m hunting around for weird documentation and have to patch something together myself?
It looks like mysqld is built with defaults for datadir and socket that might need to be overridden. Just guessed at this from the help docs and error messages.
Thanks. That’s great. I just wish that nix would print that out or that would be on the package page.
Homebrew spits out a message how to run a particular service. I have done this once too often and don’t really want to have to bother figuring out again.
So if I pack that into apps I can do nix run and have it go.
error: app program './result/bin/mysqld --datadir `pwd`/mysqld/datadir --initialize-insecure; ./result/bin/mysqld --socket `pwd`/mysqld/socket --datadir /tmp/mysqld/datadir;' is not in the Nix store
I find the whole app concept in flake.nix to be a bit odd, partly for what you’re finding. I can’t speak to the particular design choices.
The only times I’ve used it, I’ve used pkgs.writeShellScript to do what you’re trying to do. For example, something like (riffing here, I have a slightly different setup and didn’t test this snippet):
initialize_db = {
type = "app";
program = (pkgs.writeShellScript ''
${pkgs.mysql80}/bin/mysqld --datadir /Users/alper/Code/contrib/nestjs-realworld-example-app/mysqld/datadir --initialize-insecure
'').outPath;
};
I think there should be a type = "script" for exactly this use case. Or a suite of types around development processes. But that would probably not make it into nix, given nix doesn’t really have a good way to integrate something like writeShellScript.
Turns out that there is a facility in devenv to run mysql and other services relatively easily.
I just don’t think it’s reasonable to ask me to install two more dependencies (Cachix + devenv) to use this. Can’t .services be a part of the flake format?
If a project uses devenv, it should automatically add devenv/whatever to its dev shell (the one that’s sourced with direnv ideally), then you don’t need to install anything on top.
Can’t .services be a part of the flake format?
Wouldn’t that mean that all the magic behind this would need to be backed into nix as well?
I mean, you can add services to the output already, flakes don’t prohibit arbitrary output attributes.