nixpkgs/nixos/modules/services/web-apps/shiori.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

137 lines
3.9 KiB
Nix
Raw Normal View History

2019-09-22 15:54:16 +00:00
{ config, lib, pkgs, ... }:
2024-04-27 02:16:54 +00:00
let cfg = config.services.shiori;
2019-09-22 15:54:16 +00:00
in {
options = {
services.shiori = {
2024-04-27 02:16:54 +00:00
enable = lib.mkEnableOption "Shiori simple bookmarks manager";
2019-09-22 15:54:16 +00:00
2024-04-27 02:16:54 +00:00
package = lib.mkPackageOption pkgs "shiori" { };
2019-09-22 15:54:16 +00:00
2024-04-27 02:16:54 +00:00
address = lib.mkOption {
type = lib.types.str;
2019-09-22 15:54:16 +00:00
default = "";
description = ''
The IP address on which Shiori will listen.
If empty, listens on all interfaces.
'';
};
2024-04-27 02:16:54 +00:00
port = lib.mkOption {
type = lib.types.port;
2019-09-22 15:54:16 +00:00
default = 8080;
description = "The port of the Shiori web application";
};
2024-04-27 02:16:54 +00:00
webRoot = lib.mkOption {
type = lib.types.str;
default = "/";
example = "/shiori";
description = "The root of the Shiori web application";
};
2024-04-27 02:16:54 +00:00
environmentFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
2024-04-27 02:16:54 +00: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 {
type = lib.types.nullOr lib.types.str;
2024-04-27 02:16:54 +00:00
default = null;
2024-06-30 11:41:06 +00:00
example = "postgres:///shiori?host=/run/postgresql";
2024-04-27 02:16:54 +00:00
description = "The connection URL to connect to MySQL or PostgreSQL";
};
2019-09-22 15:54:16 +00:00
};
};
2024-04-27 02:16:54 +00:00
config = lib.mkIf cfg.enable {
systemd.services.shiori = {
2019-09-22 15:54:16 +00:00
description = "Shiori simple bookmarks manager";
wantedBy = [ "multi-user.target" ];
2024-04-27 02:16:54 +00:00
after = [ "postgresql.service" "mysql.service" ];
environment = {
SHIORI_DIR = "/var/lib/shiori";
} // lib.optionalAttrs (cfg.databaseUrl != null) {
SHIORI_DATABASE_URL = cfg.databaseUrl;
};
2019-09-22 15:54:16 +00:00
serviceConfig = {
2024-04-27 02:16:54 +00:00
ExecStart =
"${cfg.package}/bin/shiori server --address '${cfg.address}' --port '${
toString cfg.port
}' --webroot '${cfg.webRoot}'";
2019-09-22 15:54:16 +00:00
DynamicUser = true;
StateDirectory = "shiori";
# As the RootDirectory
RuntimeDirectory = "shiori";
# Security options
2024-04-27 02:16:54 +00:00
EnvironmentFile =
lib.optional (cfg.environmentFile != null) cfg.environmentFile;
BindReadOnlyPaths = [
"/nix/store"
# For SSL certificates, and the resolv.conf
"/etc"
] ++ 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";
CapabilityBoundingSet = "";
2024-04-27 02:16:54 +00:00
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
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-27 02:16:54 +00:00
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
RestrictRealtime = true;
RestrictSUIDSGID = true;
RootDirectory = "/run/shiori";
SystemCallArchitectures = "native";
SystemCallErrorNumber = "EPERM";
SystemCallFilter = [
"@system-service"
2024-04-27 02:16:54 +00:00
"~@cpu-emulation"
"~@debug"
"~@keyring"
"~@memlock"
"~@obsolete"
"~@privileged"
"~@setuid"
];
2019-09-22 15:54:16 +00:00
};
};
};
2024-04-27 02:16:54 +00:00
meta.maintainers = with lib.maintainers; [ minijackson CaptainJawZ ];
2019-09-22 15:54:16 +00:00
}