shoko server (maybe)

This commit is contained in:
Snorre 2025-03-04 11:52:53 +01:00
parent 77d26bdb7e
commit cf077c7867
2 changed files with 126 additions and 0 deletions

44
packages/shoko.nix Normal file
View file

@ -0,0 +1,44 @@
{
lib,
dotnetCorePackages,
buildDotnetModule,
pkgs,
fetchFromGitHub,
...
}:
buildDotnetModule rec {
pname = "shoko-${version}";
version = "5.1.0";
src = fetchFromGitHub {
owner = "ShokoAnime";
repo = "ShokoServer";
rev = "v5.1.0";
hash = "";
};
projectFile = "Shoko.Server/Shoko.Server.csproj";
executables = ["shoko"];
# nugetDeps = ./nuget-deps.json;
runtimeDeps = with pkgs; [
mediainfo
rhash
];
dotnet-sdk = dotnetCorePackages.sdk_8_0;
dotnet-runtime = dotnetCorePackages.aspnetcore_8_0;
dotnetBuildFlags = ["--no-self-contained"];
# makeWrapperArgs = [];
meta = with lib; {
description = "Shoko server for self hosted anime browsing";
homepage = "https://shokoanime.com/";
license = licenses.mit;
maintainers = with maintainers; [
# TODO: Add myself to maintainers
me
];
mainProgram = "shoko";
platforms = dotnet-runtime.meta.platforms;
};
}

82
services/shoko.nix Normal file
View file

@ -0,0 +1,82 @@
{
config,
pkgs,
lib ? pkgs.lib,
callPackage,
...
}: let
cfg = config.services.shoko;
in {
options = {
services.shoko = {
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = "Whether to enable Shoko server.";
};
host = lib.mkOption {
type = lib.types.str;
default = "*";
example = "localhost";
description = ''
The hostname or address to listen on or <literal>*</literal> to listen
on all interfaces.
'';
};
port = lib.mkOption {
type = lib.types.int;
default = 3000;
description = ''
TCP port the web server should listen to.
'';
};
baseDir = lib.mkOption {
type = lib.types.string;
default = "/var/lib/shoko";
description = ''
The folder shoko will dump its shit into
'';
};
};
};
config = lib.mkIf cfg.enable {
users.extraGroups.shoko = {};
users.extraUsers.shoko = {
description = "Shoko";
group = "shoko";
createHome = true;
home = cfg.baseDir;
useDefaultShell = true;
};
};
systemd.services.shoko-init = {
wantedeBy = ["multi-user.target"];
# TODO: Check if shoko requires a db
# requires = optional haveLocalDB "postgresql.service";
# after = optional haveLocalDB "postgresql.service";
preStart = ''
mkdir -p ${cfg.baseDir}
chown shoko.shoko ${cfg.baseDir}
chmod 0750 ${cfg.baseDir}
# the rest
'';
};
systemd.services.shoko-server = {
wantedBy = ["multi-user.target"];
requires = ["shoko-init.service"];
after = ["shoko-init.service"];
serviceConfig = {
ExecStart = "${callPackage ../packages/shoko.nix}/bin/shoko";
User = "shoko";
PermissionsStartOnly = true;
Restart = "always";
};
};
}