From 9c22cd380cce15f624d4e1b2d953c49304a46a1d Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Sun, 27 Sep 2015 20:31:17 -0700 Subject: calibre-server service: init --- nixos/modules/services/misc/calibre-server.nix | 77 ++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 nixos/modules/services/misc/calibre-server.nix (limited to 'nixos/modules/services/misc/calibre-server.nix') diff --git a/nixos/modules/services/misc/calibre-server.nix b/nixos/modules/services/misc/calibre-server.nix new file mode 100644 index 00000000000..a59e68edd84 --- /dev/null +++ b/nixos/modules/services/misc/calibre-server.nix @@ -0,0 +1,77 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.services.calibre-server; + +in + +{ + + ###### interface + + options = { + + services.calibre-server = { + + enable = mkEnableOption "calibre-server"; + + libraryDir = mkOption { + default = "/tmp/calibre-server"; + description = '' + The directory where the Calibre library to serve is. + ''; + }; + + user = mkOption { + type = types.str; + default = "calibre-server"; + description = "User account under which calibre-server runs."; + }; + + group = mkOption { + type = types.str; + default = "calibre-server"; + description = "Group account under which calibre-server runs."; + }; + + }; + + }; + + + ###### implementation + + config = mkIf cfg.enable { + + systemd.services.calibre-server = + { + description = "calibre-server, an OPDS server for a Calibre library"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + User = "${cfg.user}"; + Restart = "always"; + ExecStart = "${pkgs.calibre}/bin/calibre-server --with-library=${cfg.libraryDir}"; + }; + + }; + + environment.systemPackages = [ pkgs.calibre ]; + + users.extraUsers = optionalAttrs (cfg.user == "calibre-server") (singleton + { name = "calibre-server"; + group = cfg.group; + uid = config.ids.uids.calibre-server; + }); + + users.extraGroups = optionalAttrs (cfg.group == "calibre-server") (singleton + { name = "calibre-server"; + gid = config.ids.gids.calibre-server; + }); + + }; + +} -- cgit 1.4.1