-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
lib, | ||
config, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
inherit (lib) | ||
mkOption | ||
types | ||
mkIf | ||
mkEnableOption | ||
mkPackageOption | ||
getExe | ||
optionalString | ||
; | ||
|
||
cfg = config.services.shoko; | ||
in | ||
{ | ||
options = { | ||
services.shoko = { | ||
enable = mkEnableOption "Shoko"; | ||
|
||
package = mkPackageOption pkgs "shoko" { }; | ||
webui = mkPackageOption pkgs "shoko-webui" { nullable = true; }; | ||
plugins = mkOption { | ||
type = types.listOf types.package; | ||
default = [ ]; | ||
description = '' | ||
The plugins to install. | ||
Note that if there are plugins installed imperatively when this | ||
option is used, they will be deleted. | ||
''; | ||
}; | ||
|
||
openFirewall = mkOption { | ||
type = types.bool; | ||
default = false; | ||
description = '' | ||
Open ports in the firewall for the ShokoAnime api and web interface. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8111 ]; | ||
|
||
systemd.services.shoko = { | ||
description = "Shoko Server"; | ||
after = [ "network.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
# Not that it should be done, but this makes it easier to override the | ||
# StateDirectory option, if the user really wants to. | ||
environment.SHOKO_HOME = "/var/lib/${config.systemd.services.shoko.serviceConfig.StateDirectory}"; | ||
|
||
# The rm calls are here, because it's pretty easy to get into a situation | ||
# where those directories are created imperatively, in which case the ln | ||
# calls (along with the service) would just fail. | ||
preStart = optionalString (cfg.webui != null) '' | ||
rm -rf "$STATE_DIRECTORY/webui" | ||
ln -s '${cfg.webui}' "$STATE_DIRECTORY/webui" | ||
'' + optionalString (cfg.plugins != [ ]) '' | ||
rm -rf "$STATE_DIRECTORY/plugins" | ||
ln -s '${pkgs.linkFarmFromDrvs cfg.plugins}' "$STATE_DIRECTORY/plugins" | ||
''; | ||
|
||
serviceConfig = { | ||
Type = "simple"; | ||
|
||
DynamicUser = true; | ||
StateDirectory = "shoko"; | ||
StateDirectoryMode = 750; | ||
|
||
ExecStart = getExe cfg.package; | ||
Restart = "on-failure"; | ||
}; | ||
}; | ||
}; | ||
|
||
meta.maintainers = [ lib.maintainers.diniamo ]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import ./make-test-python.nix ( | ||
{ lib, ... }: | ||
{ | ||
name = "Shoko"; | ||
|
||
nodes.machine = { | ||
services.shoko.enable = true; | ||
}; | ||
|
||
testScript = '' | ||
machine.wait_for_unit("shoko.service") | ||
machine.wait_for_open_port(8111) | ||
machine.succeed("curl --fail http://localhost:8111") | ||
''; | ||
|
||
meta.maintainers = [ lib.maintainers.diniamo ]; | ||
} | ||
) |