Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{shoko-webui,shoko,nixos/shoko}: init #350065

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,7 @@
./services/misc/safeeyes.nix
./services/misc/sdrplay.nix
./services/misc/serviio.nix
./services/misc/shoko.nix
./services/misc/sickbeard.nix
./services/misc/signald.nix
./services/misc/siproxd.nix
Expand Down
87 changes: 87 additions & 0 deletions nixos/modules/services/misc/shoko.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
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 ];
}
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ in {
shadow = handleTest ./shadow.nix {};
shadowsocks = handleTest ./shadowsocks {};
shattered-pixel-dungeon = handleTest ./shattered-pixel-dungeon.nix {};
shoko = handleTest ./shoko.nix {};
shiori = handleTest ./shiori.nix {};
signal-desktop = handleTest ./signal-desktop.nix {};
silverbullet = handleTest ./silverbullet.nix {};
Expand Down
18 changes: 18 additions & 0 deletions nixos/tests/shoko.nix
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 ];
}
)
20 changes: 20 additions & 0 deletions pkgs/by-name/sh/shoko-webui/no-commit-hash.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
diff --git a/vite.config.mjs b/vite.config.mjs
index 481b319..186ba94 100644
--- a/vite.config.mjs
+++ b/vite.config.mjs
@@ -1,6 +1,5 @@
import path from 'path';
import { writeFile } from 'fs/promises';
-import childProcess from 'child_process';
import pkg from './package.json';

import { defineConfig } from 'vite';
@@ -54,7 +53,7 @@ export default defineConfig(async () => {
});

async function setupEnv(isDebug) {
- const gitHash = childProcess.execSync("git log --pretty=format:'%h' -n 1").toString().replace(/["']/g, '');
+ const gitHash = '';
const appVersion = pkg.version;

process.env.VITE_GITHASH = gitHash;
57 changes: 57 additions & 0 deletions pkgs/by-name/sh/shoko-webui/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
stdenvNoCC,
fetchFromGitHub,
nodejs,
pnpm,
diniamo marked this conversation as resolved.
Show resolved Hide resolved
lib,
shoko,
nix-update-script,
}:
stdenvNoCC.mkDerivation (finalAttrs: {
pname = "shoko-webui";
version = "2.2.0";

src = fetchFromGitHub {
owner = "ShokoAnime";
repo = "Shoko-WebUI";
tag = "v${finalAttrs.version}";
hash = "sha256-plXTAN3V0tcAe+uMs4XwYHO1UC9DCAxcMPVNKdFobcY=";
};

# Avoid requiring git as a build time dependency. It's used for version
# checking in the updater, which shouldn't be used if the webui is managed
# declaratively anyway.
patches = [ ./no-commit-hash.patch ];

nativeBuildInputs = [
nodejs
pnpm.configHook
];

pnpmDeps = pnpm.fetchDeps {
inherit (finalAttrs) pname version src;
hash = "sha256-9/6y8LhH0I6RAry+3shvsymLZb7ndugq3EGG3S/yrIA=";
};

buildPhase = ''
runHook preBuild
pnpm build
runHook postBuild
'';

installPhase = ''
runHook preInstall
cp -r dist $out
runHook postInstall
'';

passthru.updateSript = nix-update-script { };

meta = {
homepage = "https://github.com/ShokoAnime/Shoko-WebUI";
diniamo marked this conversation as resolved.
Show resolved Hide resolved
changelog = "https://github.com/ShokoAnime/Shoko-WebUI/releases/tag/v${finalAttrs.version}";
description = "Web-based frontend for the Shoko anime management system";
maintainers = [ lib.maintainers.diniamo ];
inherit (shoko.meta) license platforms;
};
})
Loading