From cf077c786797cecbc767d557d85ea12e886f2bdd Mon Sep 17 00:00:00 2001 From: Snorre Date: Tue, 4 Mar 2025 11:52:53 +0100 Subject: [PATCH] shoko server (maybe) --- packages/shoko.nix | 44 +++++++++++++++++++++++++ services/shoko.nix | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 packages/shoko.nix create mode 100644 services/shoko.nix diff --git a/packages/shoko.nix b/packages/shoko.nix new file mode 100644 index 0000000..9085f99 --- /dev/null +++ b/packages/shoko.nix @@ -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; + }; +} diff --git a/services/shoko.nix b/services/shoko.nix new file mode 100644 index 0000000..9dae55a --- /dev/null +++ b/services/shoko.nix @@ -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 * 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"; + }; + }; +}