nixos/tests/kavita: init
This commit is contained in:
parent
e2854d332d
commit
16b3b0c53b
5 changed files with 88 additions and 36 deletions
|
@ -12,12 +12,7 @@ in {
|
|||
description = lib.mdDoc "User account under which Kavita runs.";
|
||||
};
|
||||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
default = pkgs.kavita;
|
||||
defaultText = "pkgs.kavita";
|
||||
description = lib.mdDoc "Kavita package to use.";
|
||||
};
|
||||
package = lib.mkPackageOptionMD pkgs "kavita" { };
|
||||
|
||||
dataDir = lib.mkOption {
|
||||
default = "/var/lib/kavita";
|
||||
|
@ -40,8 +35,8 @@ in {
|
|||
ipAdresses = lib.mkOption {
|
||||
default = ["0.0.0.0" "::"];
|
||||
type = lib.types.listOf lib.types.str;
|
||||
description = lib.mdDoc "IP Adresses to bind to. The default is to bind to all IPv4
|
||||
and IPv6 addresses.";
|
||||
description = lib.mdDoc "IP Adresses to bind to. The default is to bind
|
||||
to all IPv4 and IPv6 addresses.";
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -51,7 +46,7 @@ in {
|
|||
wantedBy = [ "multi-user.target" ];
|
||||
after = [ "network.target" ];
|
||||
preStart = ''
|
||||
mkdir -p "${cfg.dataDir}/config"
|
||||
umask u=rwx,g=rx,o=
|
||||
cat > "${cfg.dataDir}/config/appsettings.json" <<EOF
|
||||
{
|
||||
"TokenKey": "$(cat ${cfg.tokenKeyFile})",
|
||||
|
@ -59,7 +54,6 @@ in {
|
|||
"IpAddresses": "${lib.concatStringsSep "," cfg.ipAdresses}"
|
||||
}
|
||||
EOF
|
||||
chmod 640 ${cfg.dataDir}/config/appsettings.json
|
||||
'';
|
||||
serviceConfig = {
|
||||
WorkingDirectory = cfg.dataDir;
|
||||
|
@ -69,13 +63,17 @@ in {
|
|||
};
|
||||
};
|
||||
|
||||
systemd.tmpfiles.rules = [
|
||||
"d '${cfg.dataDir}' 0750 ${cfg.user} ${cfg.user} - -"
|
||||
"d '${cfg.dataDir}/config' 0750 ${cfg.user} ${cfg.user} - -"
|
||||
];
|
||||
|
||||
users = {
|
||||
users.${cfg.user} = {
|
||||
description = "kavita service user";
|
||||
isSystemUser = true;
|
||||
group = cfg.user;
|
||||
home = cfg.dataDir;
|
||||
createHome = true;
|
||||
};
|
||||
groups.${cfg.user} = { };
|
||||
};
|
||||
|
|
|
@ -352,6 +352,7 @@ in {
|
|||
kafka = handleTest ./kafka.nix {};
|
||||
kanidm = handleTest ./kanidm.nix {};
|
||||
karma = handleTest ./karma.nix {};
|
||||
kavita = handleTest ./kavita.nix {};
|
||||
kbd-setfont-decompress = handleTest ./kbd-setfont-decompress.nix {};
|
||||
kbd-update-search-paths-patch = handleTest ./kbd-update-search-paths-patch.nix {};
|
||||
kea = handleTest ./kea.nix {};
|
||||
|
|
36
nixos/tests/kavita.nix
Normal file
36
nixos/tests/kavita.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
import ./make-test-python.nix ({ pkgs, ...} : {
|
||||
name = "kavita";
|
||||
meta = with pkgs.lib.maintainers; {
|
||||
maintainers = [ misterio77 ];
|
||||
};
|
||||
|
||||
nodes = {
|
||||
kavita = { config, pkgs, ... }: {
|
||||
services.kavita = {
|
||||
enable = true;
|
||||
port = 5000;
|
||||
tokenKeyFile = builtins.toFile "kavita.key" "QfpjFvjT83BLtZ74GE3U3Q==";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = let
|
||||
regUrl = "http://kavita:5000/api/Account/register";
|
||||
payload = builtins.toFile "payload.json" (builtins.toJSON {
|
||||
username = "foo";
|
||||
password = "correcthorsebatterystaple";
|
||||
email = "foo@bar";
|
||||
});
|
||||
in ''
|
||||
kavita.start
|
||||
kavita.wait_for_unit("kavita.service")
|
||||
|
||||
# Check that static assets are working
|
||||
kavita.wait_until_succeeds("curl http://kavita:5000/site.webmanifest | grep Kavita")
|
||||
|
||||
# Check that registration is working
|
||||
kavita.succeed("curl -fX POST ${regUrl} --json @${payload}")
|
||||
# But only for the first one
|
||||
kavita.fail("curl -fX POST ${regUrl} --json @${payload}")
|
||||
'';
|
||||
})
|
|
@ -13,7 +13,7 @@ index 2f5d7fce..faaf128a 100644
|
|||
public ActionResult Index()
|
||||
{
|
||||
- return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html"), "text/HTML");
|
||||
+ return PhysicalFile(Path.Combine("@WEB_ROOT@", "index.html"), "text/HTML");
|
||||
+ return PhysicalFile(Path.Combine("@web_root@", "index.html"), "text/HTML");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@ index f84ef638..7eaeb05e 100644
|
|||
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
+ FileProvider = new PhysicalFileProvider("@WEB_ROOT@"),
|
||||
+ FileProvider = new PhysicalFileProvider("@web_root@"),
|
||||
ContentTypeProvider = new FileExtensionContentTypeProvider(),
|
||||
HttpsCompression = HttpsCompressionMode.Compress,
|
||||
OnPrepareResponse = ctx =>
|
||||
|
|
|
@ -1,29 +1,47 @@
|
|||
{ lib
|
||||
, stdenvNoCC
|
||||
, fetchFromGitHub
|
||||
, buildDotnetModule
|
||||
, buildNpmPackage
|
||||
, dotnetCorePackages
|
||||
, nixosTests
|
||||
, substituteAll
|
||||
}:
|
||||
|
||||
buildDotnetModule rec {
|
||||
stdenvNoCC.mkDerivation (finalAttrs: {
|
||||
pname = "kavita";
|
||||
version = "0.7.1.4";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "kareadita";
|
||||
repo = "kavita";
|
||||
rev = "v${version}";
|
||||
rev = "v${finalAttrs.version}";
|
||||
hash = "sha256-jNhiwyz6iVSLlvMNjI689TwQYuEvTJ+QaPvvDQ4UOwc=";
|
||||
};
|
||||
|
||||
patches = [
|
||||
# So that we can set the webroot
|
||||
./change-webroot.diff
|
||||
];
|
||||
backend = buildDotnetModule {
|
||||
pname = "kavita-backend";
|
||||
inherit (finalAttrs) version src;
|
||||
|
||||
patches = [
|
||||
# The webroot is hardcoded as ./wwwroot
|
||||
(substituteAll {
|
||||
src = ./change-webroot.diff;
|
||||
web_root = "${finalAttrs.frontend}/lib/node_modules/kavita-webui/dist";
|
||||
})
|
||||
];
|
||||
|
||||
executables = [ "API" ];
|
||||
|
||||
projectFile = "API/API.csproj";
|
||||
nugetDeps = ./nuget-deps.nix;
|
||||
dotnet-sdk = dotnetCorePackages.sdk_6_0;
|
||||
dotnet-runtime = dotnetCorePackages.aspnetcore_6_0;
|
||||
};
|
||||
|
||||
frontend = buildNpmPackage {
|
||||
pname = "kavita-web";
|
||||
inherit version src;
|
||||
pname = "kavita-frontend";
|
||||
inherit (finalAttrs) version src;
|
||||
|
||||
sourceRoot = "source/UI/Web";
|
||||
|
||||
|
@ -33,28 +51,27 @@ buildDotnetModule rec {
|
|||
npmDepsHash = "sha256-w0CuTPyCQyAxULvqd6+GiZaPlO8fh4xLmbEnGA47pL8=";
|
||||
};
|
||||
|
||||
postPatch = ''
|
||||
sed -i "s:@WEB_ROOT@:$out/lib/kavita-frontend:" API/Controllers/FallbackController.cs API/Startup.cs
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
|
||||
mkdir -p $out/bin $out/lib/kavita
|
||||
ln -s $backend/lib/kavita-backend $out/lib/kavita/backend
|
||||
ln -s $frontend/lib/node_modules/kavita-webui/dist $out/lib/kavita/frontend
|
||||
ln -s $backend/bin/API $out/bin/kavita
|
||||
|
||||
runHook postInstall
|
||||
'';
|
||||
|
||||
executables = [ "API" ];
|
||||
|
||||
postFixup = ''
|
||||
cp -r $frontend/lib/node_modules/kavita-webui/dist $out/lib/kavita-frontend
|
||||
mv $out/bin/API $out/bin/kavita
|
||||
'';
|
||||
|
||||
projectFile = "API/API.csproj";
|
||||
nugetDeps = ./nuget-deps.nix;
|
||||
dotnet-sdk = dotnetCorePackages.sdk_6_0;
|
||||
dotnet-runtime = dotnetCorePackages.aspnetcore_6_0;
|
||||
passthru.tests = { inherit (nixosTests) kavita; };
|
||||
|
||||
meta = {
|
||||
description = "A fast, feature rich, cross platform reading server";
|
||||
homepage = "https://kavitareader.com";
|
||||
changelog = "https://github.com/kareadita/kavita/releases/tag/${src.rev}";
|
||||
changelog = "https://github.com/kareadita/kavita/releases/tag/${finalAttrs.src.rev}";
|
||||
license = lib.licenses.gpl3Only;
|
||||
platforms = lib.platforms.linux;
|
||||
maintainers = with lib.maintainers; [ misterio77 ];
|
||||
};
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue