2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.calibre-server;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
2020-09-25 04:45:31 +00:00
|
|
|
imports = [
|
|
|
|
(mkChangedOptionModule [ "services" "calibre-server" "libraryDir" ] [ "services" "calibre-server" "libraries" ]
|
|
|
|
(config:
|
|
|
|
let libraryDir = getAttrFromPath [ "services" "calibre-server" "libraryDir" ] config;
|
|
|
|
in [ libraryDir ]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.calibre-server = {
|
|
|
|
|
|
|
|
enable = mkEnableOption "calibre-server";
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
libraries = mkOption {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = ''
|
2020-09-25 04:45:31 +00:00
|
|
|
The directories of the libraries to serve. They must be readable for the user under which the server runs.
|
|
|
|
'';
|
|
|
|
type = types.listOf types.path;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
user = mkOption {
|
|
|
|
description = "The user under which calibre-server runs.";
|
|
|
|
type = types.str;
|
|
|
|
default = "calibre-server";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
description = "The group under which calibre-server runs.";
|
|
|
|
type = types.str;
|
|
|
|
default = "calibre-server";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
systemd.services.calibre-server = {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Calibre Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = {
|
2020-09-25 04:45:31 +00:00
|
|
|
User = cfg.user;
|
2020-04-24 23:36:52 +00:00
|
|
|
Restart = "always";
|
2020-09-25 04:45:31 +00:00
|
|
|
ExecStart = "${pkgs.calibre}/bin/calibre-server ${lib.concatStringsSep " " cfg.libraries}";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.calibre ];
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
users.users = optionalAttrs (cfg.user == "calibre-server") {
|
|
|
|
calibre-server = {
|
|
|
|
home = "/var/lib/calibre-server";
|
|
|
|
createHome = true;
|
2020-04-24 23:36:52 +00:00
|
|
|
uid = config.ids.uids.calibre-server;
|
2020-09-25 04:45:31 +00:00
|
|
|
group = cfg.group;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
users.groups = optionalAttrs (cfg.group == "calibre-server") {
|
|
|
|
calibre-server = {
|
2020-04-24 23:36:52 +00:00
|
|
|
gid = config.ids.gids.calibre-server;
|
|
|
|
};
|
2020-09-25 04:45:31 +00:00
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|