Setting up calibre-server on NixOS

Setting up calibre server is not fully declarative yet, as far as I can see. Once I get more familiar with NixOS I can imagine myself contributing to try to make it possible (if even possible).

For now, this is how I managed to get it to work how I want:

My initial config looked like this

{
  services.calibre-server = {
    enable = true;
    port = 1212;
  };
}

But I soon noticed, that the service was not starting with the following error:

There is no calibre library at: /var/lib/calibre-server

I did not find a way to initialize a new library from calibre-server and the only way was to copy over my already existing library.

For completeness, this is how I did it - just rsync’ed my local calibre folder to the machine running the server

rsync -avz ./calibre/ user@machine:/tmp/cal/

Inside the machine

sudo cp -r ./cal/. /var/lib/calibre-server
sudo chown -R calibre-server:calibre-server /var/lib/calibre-server

And now, by reloading the service, it should work.

Authentication

Authentication as well is a bit hacky. As far as I can tell, there is no option to specify users, only to specify a database containing user information.

To create one (docs here)

sudo -u calibre-server calibre-server --userdb /var/lib/calibre-server/users.sqlite --manage-users

And follow the prompts to create a new user.

My final configuration looks like this

{
  services.calibre-server = {
    enable = true;
    auth = {
      enable = true;
      mode = "basic";
      userDb = "/var/lib/calibre-server/users.sqlite";
    };
    port = 1212;
  };
}

Use basic for authentication, otherwise some OPDS (tested with KOReader) won’t be able to login.
I did not set up HTTPS.

1 Like

Apparently there is a way to initialize a library without needing it to copy over with, only kind of tested

sudo -u calibre-server calibredb --with-library "/path/to/your/library" list