I’ve been working on getting neo4j (a graph DBMS) working with flakes, although I believe the basic idea extends out to any DBMS. The main issue I’ve had is with where to put the DB, logs, and run. I am trying to find a solution that fits the principles of flakes, keeping the flake computer independent such that it should be possible to reproduce the DB on another computer by running the flake.
I’ve made some progress with my neo4j flake, which installs the community edition of neo4j and provides a wrapper to allow project specific plugin management and DBs. This requires supplying a path to the project’s DB, which means it’s dependent on the DB existing on the computer and therefore not a proper flake solution (worse yet, this generally requires hard-coding a user’s home directory into the path).
The ideal solution
I would like to have the DBs stored within /nix/store
. In this way we could add a derivation maker for DBs that would describe how to generate the database in a reproducible manner (such as downloading data and importing it into neo4j). You would then write a flake for each DB and use that flake as another input for the neo4j wrapper. This would allow multiple flakes to use the same DB and an individual flake could have a normal DB and a separate test DB that would be provided to checkInputs
(and, if needed, it would be easy to switch out the normal DB for the test DB to interactively play around on a smaller db).
Side note on storage
This raises the issue of storage, generally data is going to be much larger than software so having multiple copies in /nix/store
is potentially unacceptable. The data, however, should be largely static, once it has been properly set up nix should not have a reason to regenerate it unless it’s been specifically modified so I don’t believe this will actually be a problem and shouldn’t require any more rebuilds than would be required outside of using nix management. Though it would potentially warrant a method for aggressively garbage collecting old DBs.
Problem
Nix store is read-only to normal users, this makes it unsuitable for storing logs and placing run. Additionally, neo4j will not run if the DB is read-only. (Though I’m leaning towards preferring a read-only DB as running any commands that modifies the DB makes it non-reproducible so I’m hoping there’s a solution on the neo4j side that allows me to use a RO DB.) One solution would be to run as su but for obvious reasons I don’t think neo4j should be run with root privileges as it really shouldn’t need to be given that much power.
Is there a way to get systemctl
to handle this while keeping everything contained in a flake? Are there any ideas from other DBMSs for where we could put logs, run, and the DB such that a normal user would be able to access it? Could I make a directory under /var
that a normal user would own and then put everything there and have a the DB derivations be symlinks to the DBs in /var/neo4j/db
or something like that?