83 lines
1.9 KiB
Nix
Executable file
83 lines
1.9 KiB
Nix
Executable file
{
|
|
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 <literal>*</literal> 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 = {
|
|
wantedBy = ["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 ./package.nix}/bin/shoko";
|
|
User = "shoko";
|
|
PermissionsStartOnly = true;
|
|
Restart = "always";
|
|
};
|
|
};
|
|
}
|