From 9c22cd380cce15f624d4e1b2d953c49304a46a1d Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Sun, 27 Sep 2015 20:31:17 -0700 Subject: [PATCH 1/3] calibre-server service: init --- nixos/modules/misc/ids.nix | 2 + nixos/modules/module-list.nix | 1 + .../modules/services/misc/calibre-server.nix | 77 +++++++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 nixos/modules/services/misc/calibre-server.nix 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; + }); + + }; + +} From a41d07074d3934aa25bedb5d7e67983f5179a91d Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Sat, 3 Oct 2015 05:48:46 -0700 Subject: [PATCH 2/3] calibre-server service: configuration improvements based on @eldostra feedback: * remove user and group configuration, because it is probably unnecessary * remove libraryDir default * capitalize and shorten service description --- .../modules/services/misc/calibre-server.nix | 29 +++++-------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/nixos/modules/services/misc/calibre-server.nix b/nixos/modules/services/misc/calibre-server.nix index a59e68edd84..b8648770ff4 100644 --- a/nixos/modules/services/misc/calibre-server.nix +++ b/nixos/modules/services/misc/calibre-server.nix @@ -19,24 +19,11 @@ in 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."; - }; - }; }; @@ -48,11 +35,11 @@ in systemd.services.calibre-server = { - description = "calibre-server, an OPDS server for a Calibre library"; + description = "Calibre Server"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; serviceConfig = { - User = "${cfg.user}"; + User = "calibre-server"; Restart = "always"; ExecStart = "${pkgs.calibre}/bin/calibre-server --with-library=${cfg.libraryDir}"; }; @@ -61,16 +48,14 @@ in environment.systemPackages = [ pkgs.calibre ]; - users.extraUsers = optionalAttrs (cfg.user == "calibre-server") (singleton - { name = "calibre-server"; - group = cfg.group; + users.extraUsers.calibre-server = { uid = config.ids.uids.calibre-server; - }); + group = "calibre-server"; + }; - users.extraGroups = optionalAttrs (cfg.group == "calibre-server") (singleton - { name = "calibre-server"; + users.extraGroups.calibre-server = { gid = config.ids.gids.calibre-server; - }); + }; }; From 922bf3986b108b91908bf2d82389cdeae59332ca Mon Sep 17 00:00:00 2001 From: Ryan Mulligan Date: Sat, 31 Oct 2015 14:21:56 -0700 Subject: [PATCH 3/3] calibre-server service: add type to libraryDir option --- nixos/modules/services/misc/calibre-server.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/modules/services/misc/calibre-server.nix b/nixos/modules/services/misc/calibre-server.nix index b8648770ff4..a920aa22ccd 100644 --- a/nixos/modules/services/misc/calibre-server.nix +++ b/nixos/modules/services/misc/calibre-server.nix @@ -22,6 +22,7 @@ in description = '' The directory where the Calibre library to serve is. ''; + type = types.path; }; };