From 4560d7ed7029408bbbc940aabbbfea10d32e62ac Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Fri, 15 May 2020 17:53:07 +0200 Subject: nixos/calibre-server: Allow multiple libraries Also add options for group and user. --- nixos/modules/services/misc/calibre-server.nix | 49 +++++++++++++++++++------- 1 file changed, 36 insertions(+), 13 deletions(-) (limited to 'nixos') diff --git a/nixos/modules/services/misc/calibre-server.nix b/nixos/modules/services/misc/calibre-server.nix index 84c04f403d3a3..2467d34b524a5 100644 --- a/nixos/modules/services/misc/calibre-server.nix +++ b/nixos/modules/services/misc/calibre-server.nix @@ -9,24 +9,42 @@ let in { + imports = [ + (mkChangedOptionModule [ "services" "calibre-server" "libraryDir" ] [ "services" "calibre-server" "libraries" ] + (config: + let libraryDir = getAttrFromPath [ "services" "calibre-server" "libraryDir" ] config; + in [ libraryDir ] + ) + ) + ]; ###### interface options = { - services.calibre-server = { enable = mkEnableOption "calibre-server"; - libraryDir = mkOption { + libraries = mkOption { description = '' - The directory where the Calibre library to serve is. - ''; - type = types.path; + The directories of the libraries to serve. They must be readable for the user under which the server runs. + ''; + type = types.listOf types.path; }; - }; + 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"; + }; + }; }; @@ -34,29 +52,34 @@ in config = mkIf cfg.enable { - systemd.services.calibre-server = - { + systemd.services.calibre-server = { description = "Calibre Server"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { - User = "calibre-server"; + User = cfg.user; Restart = "always"; - ExecStart = "${pkgs.calibre}/bin/calibre-server ${cfg.libraryDir}"; + ExecStart = "${pkgs.calibre}/bin/calibre-server ${lib.concatStringsSep " " cfg.libraries}"; }; }; environment.systemPackages = [ pkgs.calibre ]; - users.users.calibre-server = { + users.users = optionalAttrs (cfg.user == "calibre-server") { + calibre-server = { + home = "/var/lib/calibre-server"; + createHome = true; uid = config.ids.uids.calibre-server; - group = "calibre-server"; + group = cfg.group; }; + }; - users.groups.calibre-server = { + users.groups = optionalAttrs (cfg.group == "calibre-server") { + calibre-server = { gid = config.ids.gids.calibre-server; }; + }; }; -- cgit 1.4.1