-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
5 changed files
with
141 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
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,120 @@ | ||
{ | ||
lib, | ||
config, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
inherit (lib) | ||
mkOption | ||
types | ||
mkIf | ||
mkEnableOption | ||
mkPackageOption | ||
getExe | ||
concatMapStringsSep | ||
optionalString | ||
; | ||
|
||
cfg = config.services.shokoserver; | ||
in | ||
{ | ||
options = { | ||
services.shokoserver = { | ||
enable = mkEnableOption "ShokoServer"; | ||
|
||
package = mkPackageOption pkgs "shokoserver" { }; | ||
webui = mkPackageOption pkgs "shoko-webui" { nullable = true; }; | ||
plugins = mkOption { | ||
type = types.listOf types.path; | ||
default = [ ]; | ||
description = "The plugins to install."; | ||
}; | ||
|
||
dataDir = mkOption { | ||
type = types.str; | ||
default = "/var/lib/shoko"; | ||
description = "The directory where ShokoServer stores its data files."; | ||
}; | ||
|
||
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."; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
# 1. Create the data directory. | ||
# 2. If the webui is managed declaratively, delete the version that was | ||
# there, if the webui wasn't managed declaratively beforehand | ||
# (ShokoServer always copies a placeholder, or installs the real one | ||
# if the user presses the specific button). | ||
# 3. Create the plugins directory if it doesn't exist, and remove every | ||
# plugin that's a link to the nix store (this allows us to have | ||
# imperative plugins as well), then symlink the specified plugins. | ||
system.activationScripts.shokoserver = | ||
'' | ||
install -dm700 '${cfg.dataDir}' | ||
'' | ||
+ optionalString (cfg.webui != null) '' | ||
rm -rf '${cfg.dataDir}/webui' | ||
ln -s '${cfg.webui}' '${cfg.dataDir}/webui' | ||
'' | ||
+ optionalString (cfg.plugins != [ ]) '' | ||
mkdir -p '${cfg.dataDir}/plugins' | ||
for file in '${cfg.dataDir}'/plugins/*; do | ||
[[ "$(readlink "$file")" == /nix/store/* ]] && rm -f "$file" | ||
done | ||
${concatMapStringsSep "\n" (p: "ln -sf ${p} ${cfg.dataDir}/plugins") cfg.plugins} | ||
''; | ||
|
||
users = { | ||
users.shoko = mkIf (cfg.user == "shoko") { | ||
inherit (cfg) group; | ||
home = cfg.dataDir; | ||
uid = config.ids.uids.shoko; | ||
# It's created in the activation script to avoid ambiguity with which comes first | ||
# (this, or the activation script) | ||
createHome = false; | ||
}; | ||
|
||
groups.shoko.gid = mkIf (cfg.group == "shoko") config.ids.gids.shoko; | ||
}; | ||
|
||
networking.firewall.allowedTCPPorts = mkIf cfg.openFirewall [ 8111 ]; | ||
|
||
systemd.services.shokoserver = { | ||
description = "ShokoServer"; | ||
after = [ "network.target" ]; | ||
wantedBy = [ "multi-user.target" ]; | ||
|
||
environment.SHOKO_HOME = cfg.dataDir; | ||
|
||
serviceConfig = { | ||
Type = "simple"; | ||
User = cfg.user; | ||
Group = cfg.group; | ||
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,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 ]; | ||
} | ||
) |