mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-10-26 08:48:38 +03:00
nixos/kavita: accept freeform settings, ensure locales in tests
This commit is contained in:
parent
44cdc74071
commit
477dce3b9a
@ -2,7 +2,18 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.kavita;
|
cfg = config.services.kavita;
|
||||||
in {
|
settingsFormat = pkgs.formats.json { };
|
||||||
|
appsettings = settingsFormat.generate "appsettings.json" ({ TokenKey = "@TOKEN@"; } // cfg.settings);
|
||||||
|
in
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
(lib.mkChangedOptionModule [ "services" "kavita" "ipAdresses" ] [ "services" "kavita" "settings" "IpAddresses" ] (config:
|
||||||
|
let value = lib.getAttrFromPath [ "services" "kavita" "ipAdresses" ] config; in
|
||||||
|
lib.concatStringsSep "," value
|
||||||
|
))
|
||||||
|
(lib.mkRenamedOptionModule [ "services" "kavita" "port" ] [ "services" "kavita" "settings" "Port" ])
|
||||||
|
];
|
||||||
|
|
||||||
options.services.kavita = {
|
options.services.kavita = {
|
||||||
enable = lib.mkEnableOption (lib.mdDoc "Kavita reading server");
|
enable = lib.mkEnableOption (lib.mdDoc "Kavita reading server");
|
||||||
|
|
||||||
@ -27,16 +38,31 @@ in {
|
|||||||
It can be generated with `head -c 32 /dev/urandom | base64`.
|
It can be generated with `head -c 32 /dev/urandom | base64`.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
port = lib.mkOption {
|
|
||||||
|
settings = lib.mkOption {
|
||||||
|
default = { };
|
||||||
|
description = lib.mdDoc ''
|
||||||
|
Kavita configuration options, as configured in {file}`appsettings.json`.
|
||||||
|
'';
|
||||||
|
type = lib.types.submodule {
|
||||||
|
freeformType = settingsFormat.type;
|
||||||
|
|
||||||
|
options = {
|
||||||
|
Port = lib.mkOption {
|
||||||
default = 5000;
|
default = 5000;
|
||||||
type = lib.types.port;
|
type = lib.types.port;
|
||||||
description = lib.mdDoc "Port to bind to.";
|
description = lib.mdDoc "Port to bind to.";
|
||||||
};
|
};
|
||||||
ipAdresses = lib.mkOption {
|
|
||||||
default = ["0.0.0.0" "::"];
|
IpAddresses = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
default = "0.0.0.0,::";
|
||||||
description = lib.mdDoc "IP Addresses to bind to. The default is to bind
|
type = lib.types.commas;
|
||||||
to all IPv4 and IPv6 addresses.";
|
description = lib.mdDoc ''
|
||||||
|
IP Addresses to bind to. The default is to bind to all IPv4 and IPv6 addresses.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,18 +72,15 @@ in {
|
|||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
umask u=rwx,g=rx,o=
|
install -m600 ${appsettings} ${lib.escapeShellArg cfg.dataDir}/config/appsettings.json
|
||||||
cat > "${cfg.dataDir}/config/appsettings.json" <<EOF
|
${pkgs.replace-secret}/bin/replace-secret '@TOKEN@' \
|
||||||
{
|
''${CREDENTIALS_DIRECTORY}/token \
|
||||||
"TokenKey": "$(cat ${cfg.tokenKeyFile})",
|
'${cfg.dataDir}/config/appsettings.json'
|
||||||
"Port": ${toString cfg.port},
|
|
||||||
"IpAddresses": "${lib.concatStringsSep "," cfg.ipAdresses}"
|
|
||||||
}
|
|
||||||
EOF
|
|
||||||
'';
|
'';
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
WorkingDirectory = cfg.dataDir;
|
WorkingDirectory = cfg.dataDir;
|
||||||
ExecStart = "${lib.getExe cfg.package}";
|
LoadCredential = [ "token:${cfg.tokenKeyFile}" ];
|
||||||
|
ExecStart = lib.getExe cfg.package;
|
||||||
Restart = "always";
|
Restart = "always";
|
||||||
User = cfg.user;
|
User = cfg.user;
|
||||||
};
|
};
|
||||||
|
@ -8,20 +8,20 @@ import ./make-test-python.nix ({ pkgs, ...} : {
|
|||||||
kavita = { config, pkgs, ... }: {
|
kavita = { config, pkgs, ... }: {
|
||||||
services.kavita = {
|
services.kavita = {
|
||||||
enable = true;
|
enable = true;
|
||||||
port = 5000;
|
tokenKeyFile = builtins.toFile "kavita.key" "d26ba694b455271a8872415830fb7b5c58f8da98f9ef7f58b2ca4c34bd406512";
|
||||||
tokenKeyFile = builtins.toFile "kavita.key" "QfpjFvjT83BLtZ74GE3U3Q==";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = let
|
testScript =
|
||||||
|
let
|
||||||
regUrl = "http://kavita:5000/api/Account/register";
|
regUrl = "http://kavita:5000/api/Account/register";
|
||||||
payload = builtins.toFile "payload.json" (builtins.toJSON {
|
loginUrl = "http://kavita:5000/api/Account/login";
|
||||||
username = "foo";
|
localeUrl = "http://kavita:5000/api/locale";
|
||||||
password = "correcthorsebatterystaple";
|
in
|
||||||
email = "foo@bar";
|
''
|
||||||
});
|
import json
|
||||||
in ''
|
|
||||||
kavita.start
|
kavita.start
|
||||||
kavita.wait_for_unit("kavita.service")
|
kavita.wait_for_unit("kavita.service")
|
||||||
|
|
||||||
@ -29,8 +29,14 @@ import ./make-test-python.nix ({ pkgs, ...} : {
|
|||||||
kavita.wait_until_succeeds("curl http://kavita:5000/site.webmanifest | grep Kavita")
|
kavita.wait_until_succeeds("curl http://kavita:5000/site.webmanifest | grep Kavita")
|
||||||
|
|
||||||
# Check that registration is working
|
# Check that registration is working
|
||||||
kavita.succeed("curl -fX POST ${regUrl} --json @${payload}")
|
kavita.succeed("""curl -fX POST ${regUrl} --json '{"username": "foo", "password": "correcthorsebatterystaple"}'""")
|
||||||
# But only for the first one
|
# But only for the first one
|
||||||
kavita.fail("curl -fX POST ${regUrl} --json @${payload}")
|
kavita.fail("""curl -fX POST ${regUrl} --json '{"username": "foo", "password": "correcthorsebatterystaple"}'""")
|
||||||
|
|
||||||
|
# Log in and retrieve token
|
||||||
|
session = json.loads(kavita.succeed("""curl -fX POST ${loginUrl} --json '{"username": "foo", "password": "correcthorsebatterystaple"}'"""))
|
||||||
|
# Check list of locales
|
||||||
|
locales = json.loads(kavita.succeed(f"curl -fX GET ${localeUrl} -H 'Authorization: Bearer {session['token']}'"))
|
||||||
|
assert len(locales) > 0, "expected a list of locales"
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user