1
0
Fork 1
mirror of https://github.com/NixOS/nixpkgs.git synced 2024-12-25 03:17:13 +00:00
nixpkgs/nixos/modules/services/misc/calibre-server.nix

87 lines
1.9 KiB
Nix
Raw Normal View History

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