summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--nixos/modules/misc/ids.nix2
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/misc/calibre-server.nix77
3 files changed, 80 insertions, 0 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index 0d2700a126f..de9a318fdd2 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -234,6 +234,7 @@
       #lxd = 210; # unused
       kibana = 211;
       xtreemfs = 212;
+      calibre-server = 213;
 
       # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
 
@@ -446,6 +447,7 @@
       lxd = 210; # unused
       #kibana = 211;
       xtreemfs = 212;
+      calibre-server = 213;
 
       # When adding a gid, make sure it doesn't match an existing
       # uid. Users and groups with the same name should have equal
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index c890eac4991..9f21ffb99af 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -187,6 +187,7 @@
   ./services/misc/apache-kafka.nix
   #./services/misc/autofs.nix
   ./services/misc/canto-daemon.nix
+  ./services/misc/calibre-server.nix
   ./services/misc/cpuminer-cryptonight.nix
   ./services/misc/cgminer.nix
   ./services/misc/confd.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;
+      });
+
+  };
+
+}