2019-09-22 17:54:16 +02:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
...
|
|
|
|
}:
|
2024-12-10 20:26:33 +01:00
|
|
|
|
2024-04-26 20:16:54 -06:00
|
|
|
let
|
|
|
|
cfg = config.services.shiori;
|
2019-09-22 17:54:16 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.shiori = {
|
2024-04-26 20:16:54 -06:00
|
|
|
enable = lib.mkEnableOption "Shiori simple bookmarks manager";
|
2019-09-22 17:54:16 +02:00
|
|
|
|
2024-04-26 20:16:54 -06:00
|
|
|
package = lib.mkPackageOption pkgs "shiori" { };
|
2019-09-22 17:54:16 +02:00
|
|
|
|
2024-04-26 20:16:54 -06:00
|
|
|
address = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2019-09-22 17:54:16 +02:00
|
|
|
default = "";
|
|
|
|
description = ''
|
|
|
|
The IP address on which Shiori will listen.
|
|
|
|
If empty, listens on all interfaces.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-04-26 20:16:54 -06:00
|
|
|
port = lib.mkOption {
|
|
|
|
type = lib.types.port;
|
2019-09-22 17:54:16 +02:00
|
|
|
default = 8080;
|
|
|
|
description = "The port of the Shiori web application";
|
|
|
|
};
|
2023-10-11 16:26:10 +13:00
|
|
|
|
2024-04-26 20:16:54 -06:00
|
|
|
webRoot = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2023-10-11 16:26:10 +13:00
|
|
|
default = "/";
|
|
|
|
example = "/shiori";
|
|
|
|
description = "The root of the Shiori web application";
|
|
|
|
};
|
2024-04-26 20:16:54 -06:00
|
|
|
|
|
|
|
environmentFile = lib.mkOption {
|
2024-06-30 12:57:31 +02:00
|
|
|
type = lib.types.nullOr lib.types.path;
|
2024-04-26 20:16:54 -06:00
|
|
|
default = null;
|
|
|
|
example = "/path/to/environmentFile";
|
|
|
|
description = ''
|
|
|
|
Path to file containing environment variables.
|
|
|
|
Useful for passing down secrets.
|
|
|
|
<https://github.com/go-shiori/shiori/blob/master/docs/Configuration.md#overall-configuration>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
databaseUrl = lib.mkOption {
|
2024-06-30 12:57:31 +02:00
|
|
|
type = lib.types.nullOr lib.types.str;
|
2024-04-26 20:16:54 -06:00
|
|
|
default = null;
|
2024-06-30 13:41:06 +02:00
|
|
|
example = "postgres:///shiori?host=/run/postgresql";
|
2024-04-26 20:16:54 -06:00
|
|
|
description = "The connection URL to connect to MySQL or PostgreSQL";
|
|
|
|
};
|
2019-09-22 17:54:16 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-26 20:16:54 -06:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
systemd.services.shiori = {
|
2019-09-22 17:54:16 +02:00
|
|
|
description = "Shiori simple bookmarks manager";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-04-26 20:16:54 -06:00
|
|
|
after = [
|
2025-05-02 14:58:46 +02:00
|
|
|
"postgresql.target"
|
2024-04-26 20:16:54 -06:00
|
|
|
"mysql.service"
|
|
|
|
];
|
|
|
|
environment =
|
|
|
|
{
|
|
|
|
SHIORI_DIR = "/var/lib/shiori";
|
|
|
|
}
|
|
|
|
// lib.optionalAttrs (cfg.databaseUrl != null) {
|
|
|
|
SHIORI_DATABASE_URL = cfg.databaseUrl;
|
|
|
|
};
|
2020-10-02 20:31:38 +02:00
|
|
|
|
2019-09-22 17:54:16 +02:00
|
|
|
serviceConfig = {
|
2024-04-26 20:16:54 -06:00
|
|
|
ExecStart = "${cfg.package}/bin/shiori server --address '${cfg.address}' --port '${toString cfg.port}' --webroot '${cfg.webRoot}'";
|
2020-10-02 20:31:38 +02:00
|
|
|
|
2019-09-22 17:54:16 +02:00
|
|
|
DynamicUser = true;
|
|
|
|
StateDirectory = "shiori";
|
2020-10-02 20:31:38 +02:00
|
|
|
# As the RootDirectory
|
|
|
|
RuntimeDirectory = "shiori";
|
|
|
|
|
|
|
|
# Security options
|
2024-04-26 20:16:54 -06:00
|
|
|
EnvironmentFile = lib.optional (cfg.environmentFile != null) cfg.environmentFile;
|
2020-10-02 20:31:38 +02:00
|
|
|
BindReadOnlyPaths =
|
|
|
|
[
|
|
|
|
"/nix/store"
|
2024-12-10 20:26:33 +01:00
|
|
|
|
2020-10-02 20:31:38 +02:00
|
|
|
# For SSL certificates, and the resolv.conf
|
|
|
|
"/etc"
|
2024-06-30 13:03:54 +02:00
|
|
|
]
|
|
|
|
++ lib.optional (
|
|
|
|
config.services.postgresql.enable
|
|
|
|
&& cfg.databaseUrl != null
|
|
|
|
&& lib.strings.hasPrefix "postgres://" cfg.databaseUrl
|
|
|
|
) "/run/postgresql"
|
|
|
|
++ lib.optional (
|
|
|
|
config.services.mysql.enable
|
|
|
|
&& cfg.databaseUrl != null
|
|
|
|
&& lib.strings.hasPrefix "mysql://" cfg.databaseUrl
|
|
|
|
) "/var/run/mysqld";
|
2020-10-02 20:31:38 +02:00
|
|
|
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
|
|
|
|
DeviceAllow = "";
|
|
|
|
|
|
|
|
LockPersonality = true;
|
|
|
|
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
|
|
|
|
RestrictNamespaces = true;
|
2024-04-26 20:16:54 -06:00
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
"AF_UNIX"
|
|
|
|
];
|
2020-10-02 20:31:38 +02:00
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
|
|
|
|
RootDirectory = "/run/shiori";
|
|
|
|
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
2024-04-26 20:16:54 -06:00
|
|
|
"~@cpu-emulation"
|
|
|
|
"~@debug"
|
|
|
|
"~@keyring"
|
|
|
|
"~@memlock"
|
|
|
|
"~@obsolete"
|
|
|
|
"~@privileged"
|
|
|
|
"~@setuid"
|
2020-10-02 20:31:38 +02:00
|
|
|
];
|
2019-09-22 17:54:16 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-04-26 20:16:54 -06:00
|
|
|
meta.maintainers = with lib.maintainers; [
|
|
|
|
minijackson
|
|
|
|
CaptainJawZ
|
|
|
|
];
|
2019-09-22 17:54:16 +02:00
|
|
|
}
|