nixos/services.calibre-server: remove with lib;

This commit is contained in:
Felix Buehler
2024-08-30 23:00:14 +02:00
parent 02617d5a2a
commit 5e8ed975ef
+25 -28
View File
@@ -1,7 +1,4 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.calibre-server;
@@ -9,21 +6,21 @@ let
documentationLink = "https://manual.calibre-ebook.com";
generatedDocumentationLink = documentationLink + "/generated/en/calibre-server.html";
execFlags = (concatStringsSep " "
(mapAttrsToList (k: v: "${k} ${toString v}") (filterAttrs (name: value: value != null) {
execFlags = (lib.concatStringsSep " "
(lib.mapAttrsToList (k: v: "${k} ${toString v}") (lib.filterAttrs (name: value: value != null) {
"--listen-on" = cfg.host;
"--port" = cfg.port;
"--auth-mode" = cfg.auth.mode;
"--userdb" = cfg.auth.userDb;
}) ++ [(optionalString (cfg.auth.enable == true) "--enable-auth")])
}) ++ [(lib.optionalString (cfg.auth.enable == true) "--enable-auth")])
);
in
{
imports = [
(mkChangedOptionModule [ "services" "calibre-server" "libraryDir" ] [ "services" "calibre-server" "libraries" ]
(lib.mkChangedOptionModule [ "services" "calibre-server" "libraryDir" ] [ "services" "calibre-server" "libraries" ]
(config:
let libraryDir = getAttrFromPath [ "services" "calibre-server" "libraryDir" ] config;
let libraryDir = lib.getAttrFromPath [ "services" "calibre-server" "libraryDir" ] config;
in [ libraryDir ]
)
)
@@ -32,11 +29,11 @@ in
options = {
services.calibre-server = {
enable = mkEnableOption "calibre-server (e-book software)";
enable = lib.mkEnableOption "calibre-server (e-book software)";
package = lib.mkPackageOption pkgs "calibre" { };
libraries = mkOption {
type = types.listOf types.path;
libraries = lib.mkOption {
type = lib.types.listOf lib.types.path;
default = [ "/var/lib/calibre-server" ];
description = ''
Make sure each library path is initialized before service startup.
@@ -45,20 +42,20 @@ in
'';
};
user = mkOption {
type = types.str;
user = lib.mkOption {
type = lib.types.str;
default = "calibre-server";
description = "The user under which calibre-server runs.";
};
group = mkOption {
type = types.str;
group = lib.mkOption {
type = lib.types.str;
default = "calibre-server";
description = "The group under which calibre-server runs.";
};
host = mkOption {
type = types.str;
host = lib.mkOption {
type = lib.types.str;
default = "0.0.0.0";
example = "::1";
description = ''
@@ -67,9 +64,9 @@ in
'';
};
port = mkOption {
port = lib.mkOption {
default = 8080;
type = types.port;
type = lib.types.port;
description = ''
The port on which to listen for connections.
See the [calibre-server documentation](${generatedDocumentationLink}#cmdoption-calibre-server-port) for details.
@@ -77,8 +74,8 @@ in
};
auth = {
enable = mkOption {
type = types.bool;
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Password based authentication to access the server.
@@ -86,8 +83,8 @@ in
'';
};
mode = mkOption {
type = types.enum [ "auto" "basic" "digest" ];
mode = lib.mkOption {
type = lib.types.enum [ "auto" "basic" "digest" ];
default = "auto";
description = ''
Choose the type of authentication used.
@@ -96,9 +93,9 @@ in
'';
};
userDb = mkOption {
userDb = lib.mkOption {
default = null;
type = types.nullOr types.path;
type = lib.types.nullOr lib.types.path;
description = ''
Choose users database file to use for authentication.
Make sure users database file is initialized before service startup.
@@ -109,7 +106,7 @@ in
};
};
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
systemd.services.calibre-server = {
description = "Calibre Server";
@@ -125,7 +122,7 @@ in
environment.systemPackages = [ pkgs.calibre ];
users.users = optionalAttrs (cfg.user == "calibre-server") {
users.users = lib.optionalAttrs (cfg.user == "calibre-server") {
calibre-server = {
home = "/var/lib/calibre-server";
createHome = true;
@@ -134,7 +131,7 @@ in
};
};
users.groups = optionalAttrs (cfg.group == "calibre-server") {
users.groups = lib.optionalAttrs (cfg.group == "calibre-server") {
calibre-server = {
gid = config.ids.gids.calibre-server;
};