nixos/szurubooru: Host option and fixes for backwards compatibility

Pass through alembic and waitress so that it uses the versions from the package
definition and not from the evaluation of the module. This allows the module to
be imported and used even if it is ported to NixOS versions that use a different
default python3 version. This should be more robust against divergence in
version numbers between the system and package.

Also add a `host` config option to set the bind address. Waitress would
otherwise bind to 0.0.0.0, which isn't preferable since it's usually the case
the szurubooru is being run behind a reverse proxy.
This commit is contained in:
Ankit Pandey
2025-09-11 21:06:43 -07:00
committed by Morgan Jones
parent 671168b317
commit b5e6cacb3d
3 changed files with 29 additions and 21 deletions

View File

@@ -72,6 +72,13 @@ in
'';
};
host = lib.mkOption {
type = types.str;
default = "127.0.0.1";
example = "0.0.0.0";
description = "The host address for Szurubooru to bind to.";
};
threads = mkOption {
type = types.int;
default = 4;
@@ -265,9 +272,6 @@ in
(lib.filterAttrsRecursive (_: x: x != null))
]
);
pyenv = python.buildEnv.override {
extraLibs = [ (python.pkgs.toPythonModule cfg.server.package) ];
};
in
{
description = "Server of Szurubooru, an image board engine dedicated for small and medium communities";
@@ -283,20 +287,9 @@ in
];
wants = [ "network-online.target" ];
environment = {
PYTHONPATH = "${pyenv}/${pyenv.sitePackages}/";
};
path =
with pkgs;
[
envsubst
ffmpeg_4-full
]
++ (with python.pkgs; [
alembic
waitress
]);
path = with pkgs; [
ffmpeg_4-full
];
script = ''
export SZURUBOORU_SECRET="$(<$CREDENTIALS_DIRECTORY/secret)"
@@ -307,10 +300,10 @@ in
install -m0640 ${cfg.server.package.src}/config.yaml.dist ${cfg.dataDir}/config.yaml.dist
touch ${cfg.dataDir}/config.yaml
chmod 0640 ${cfg.dataDir}/config.yaml
envsubst -i ${configFile} -o ${cfg.dataDir}/config.yaml
${lib.getExe pkgs.envsubst} -i ${configFile} -o ${cfg.dataDir}/config.yaml
sed 's|script_location = |script_location = ${cfg.server.package.src}/|' ${cfg.server.package.src}/alembic.ini > ${cfg.dataDir}/alembic.ini
alembic upgrade head
waitress-serve --port ${toString cfg.server.port} --threads ${toString cfg.server.threads} szurubooru.facade:app
${lib.getExe cfg.server.package.alembic} upgrade head
${lib.getExe cfg.server.package.waitress} --host ${cfg.server.host} --port ${toString cfg.server.port} --threads ${toString cfg.server.threads} szurubooru.facade:app
'';
serviceConfig = {

View File

@@ -26,6 +26,7 @@ import ./make-test-python.nix (
server = {
port = 6666;
host = "127.0.0.1";
settings = {
domain = "http://127.0.0.1";
secretFile = pkgs.writeText "secret" "secret";

View File

@@ -6,6 +6,7 @@
fetchPypi,
python3,
ffmpeg_4-full,
szurubooru,
}:
let
@@ -53,7 +54,6 @@ python.pkgs.buildPythonApplication {
nativeBuildInputs = with python.pkgs; [ setuptools ];
propagatedBuildInputs = with python.pkgs; [
alembic
certifi
coloredlogs
legacy-cgi
@@ -80,6 +80,20 @@ python.pkgs.buildPythonApplication {
passthru.tests.szurubooru = nixosTests.szurubooru;
# Database migration. Needs the szurubooru server in its environment for the
# migration to complete successfully.
passthru.alembic = python.pkgs.alembic.overrideAttrs (old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ [
szurubooru.server
];
});
# Waitress is used to run the serer.
passthru.waitress = python.pkgs.waitress.overrideAttrs (old: {
propagatedBuildInputs = old.propagatedBuildInputs ++ [
szurubooru.server
];
});
meta = {
description = "Server of szurubooru, an image board engine for small and medium communities";
homepage = "https://github.com/rr-/szurubooru";