Skip to content

Commit

Permalink
nixos/shokoserver: init
Browse files Browse the repository at this point in the history
  • Loading branch information
diniamo committed Oct 20, 2024
1 parent 3d57452 commit 1003081
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nixos/modules/misc/ids.nix
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ in
rstudio-server = 324;
localtimed = 325;
automatic-timezoned = 326;
shoko = 328;

# When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!

Expand Down Expand Up @@ -666,6 +667,7 @@ in
localtimed = 325;
automatic-timezoned = 326;
uinput = 327;
shoko = 328;

# When adding a gid, make sure it doesn't match an existing
# uid. Users and groups with the same name should have equal
Expand Down
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@
./services/misc/safeeyes.nix
./services/misc/sdrplay.nix
./services/misc/serviio.nix
./services/misc/shokoserver.nix
./services/misc/sickbeard.nix
./services/misc/signald.nix
./services/misc/siproxd.nix
Expand Down
78 changes: 78 additions & 0 deletions nixos/modules/services/misc/shokoserver.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
lib,
config,
pkgs,
...
}:
let
inherit (lib) mkOption types mkIf;

cfg = config.services.shokoserver;
in
{
options = {
services.shokoserver = {
enable = lib.mkEnableOption "ShokoServer";

package = lib.mkPackageOption pkgs "shokoserver" { };

openFirewall = mkOption {
type = types.bool;
default = false;
description = ''
Open ports in the firewall for the ShokoAnime api and web interface.
'';
};

user = mkOption {
type = types.str;
default = "shoko";
description = "User account under which ShokoServer runs.";
};

group = mkOption {
type = types.str;
default = "shoko";
description = "Group under which ShokoServer runs.";
};

dataDir = mkOption {
type = types.str;
default = "/var/lib/shoko";
description = "The directory where ShokoServer stores its data files.";
};
};
};

config = mkIf cfg.enable {
users = {
users.shoko = mkIf (cfg.user == "shoko") {
inherit (cfg) group;
home = cfg.dataDir;
uid = config.ids.uids.shoko;
createHome = true;
};

groups.shoko.gid = mkIf (cfg.group == "shoko") config.ids.gids.shoko;
};

systemd.services.shokoserver = {
description = "ShokoServer";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];

serviceConfig = {
Type = "simple";
User = cfg.user;
Group = cfg.group;
Environment = "SHOKO_HOME=${cfg.dataDir}";
ExecStart = lib.getExe pkgs.shokoserver;
Restart = "on-failure";
};
};

networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8111 ];
};

meta.maintainers = [ lib.maintainers.diniamo ];
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,7 @@ in {
shadow = handleTest ./shadow.nix {};
shadowsocks = handleTest ./shadowsocks {};
shattered-pixel-dungeon = handleTest ./shattered-pixel-dungeon.nix {};
shokoserver = handleTest ./shokoserver.nix {};
shiori = handleTest ./shiori.nix {};
signal-desktop = handleTest ./signal-desktop.nix {};
silverbullet = handleTest ./silverbullet.nix {};
Expand Down
17 changes: 17 additions & 0 deletions nixos/tests/shokoserver.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ./make-test-python.nix (
{ lib, ... }:
{
name = "ShokoServer";

nodes.machine = {
services.shokoserver.enable = true;
};
testScript = ''
machine.wait_for_unit("shokoserver.service")
machine.wait_for_open_port(8111)
machine.succeed("curl --fail http://localhost:8111")
'';

meta.maintainers = [ lib.maintainers.diniamo ];
}
)

0 comments on commit 1003081

Please sign in to comment.