2024-05-23 16:15:10 +00:00
|
|
|
{
|
|
|
|
lib,
|
2024-07-11 15:50:43 +00:00
|
|
|
config,
|
|
|
|
inputs,
|
|
|
|
pkgs,
|
2024-05-23 16:15:10 +00:00
|
|
|
...
|
2024-08-25 15:02:35 +00:00
|
|
|
}:
|
|
|
|
let
|
2024-05-23 16:15:10 +00:00
|
|
|
cfg = config.services.pixivfe;
|
2024-08-25 15:02:35 +00:00
|
|
|
in
|
|
|
|
{
|
2024-05-23 16:15:10 +00:00
|
|
|
options.services.pixivfe = {
|
|
|
|
enable = lib.mkEnableOption "PixivFE, a privacy respecting frontend for Pixiv";
|
|
|
|
|
2024-08-25 15:02:35 +00:00
|
|
|
package =
|
|
|
|
lib.mkPackageOption inputs.self.legacyPackages.${pkgs.stdenv.hostPlatform.system} "pixivfe"
|
|
|
|
{ };
|
2024-05-23 16:15:10 +00:00
|
|
|
|
|
|
|
openFirewall = lib.mkEnableOption "open ports in the firewall needed for the daemon to function";
|
|
|
|
|
|
|
|
settings = lib.mkOption {
|
|
|
|
type = lib.types.nullOr (lib.types.attrsOf lib.types.anything);
|
|
|
|
default = null;
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
{
|
|
|
|
PIXIVFE_PORT = "8282";
|
|
|
|
PIXIVFE_TOKEN = "123456_AaBbccDDeeFFggHHIiJjkkllmMnnooPP";
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Additional configuration for PixivFE, see
|
|
|
|
<https://pixivfe.pages.dev/environment-variables/> for supported values.
|
|
|
|
For secrets use `EnvironmentFile` option instead.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
EnvironmentFile = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
|
|
|
default = null;
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
/run/secrets/environment
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
File containing environment variables to be passed to the PixivFE service.
|
|
|
|
|
|
|
|
See `systemd.exec(5)` for more information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
assertions = [
|
|
|
|
{
|
2024-08-25 15:02:35 +00:00
|
|
|
assertion = if cfg.openFirewall then (cfg.settings ? PIXIVFE_PORT) else true;
|
2024-05-23 16:15:10 +00:00
|
|
|
message = ''
|
|
|
|
PIXIVFE_PORT must be specified for NixOS to open a port.
|
|
|
|
|
|
|
|
See https://pixivfe.pages.dev/environment-variables/ for more information.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
|
|
|
assertion =
|
2024-08-25 15:02:35 +00:00
|
|
|
if (cfg.EnvironmentFile == null) then
|
|
|
|
(cfg.settings ? PIXIVFE_UNIXSOCKET) || (cfg.settings ? PIXIVFE_PORT)
|
|
|
|
else
|
|
|
|
true;
|
2024-05-23 16:15:10 +00:00
|
|
|
message = ''
|
|
|
|
PIXIVFE_PORT or PIXIVFE_UNIXSOCKET must be set for PixivFE to run.
|
|
|
|
|
|
|
|
See https://pixivfe.pages.dev/environment-variables/ for more information.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
{
|
2024-08-25 15:02:35 +00:00
|
|
|
assertion = if (cfg.EnvironmentFile == null) then cfg.settings ? PIXIVFE_TOKEN else true;
|
2024-05-23 16:15:10 +00:00
|
|
|
message = ''
|
|
|
|
PIXIVFE_TOKEN must be set for PixivFE to run.
|
|
|
|
|
|
|
|
See https://pixivfe.pages.dev/environment-variables/ for more information.
|
|
|
|
'';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
systemd.services."pixivfe" = {
|
|
|
|
description = "PixivFE, a privacy respecting frontend for Pixiv.";
|
2024-08-25 15:02:35 +00:00
|
|
|
documentation = [ "https://pixivfe.pages.dev/" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wants = [ "network-online.target" ];
|
|
|
|
environment = lib.mkIf (cfg.settings != null) (
|
|
|
|
lib.mapAttrs (_: v: if lib.isBool v then lib.boolToString v else toString v) cfg.settings
|
|
|
|
);
|
2024-05-23 16:15:10 +00:00
|
|
|
serviceConfig = {
|
|
|
|
inherit (cfg) EnvironmentFile;
|
|
|
|
ExecStart = lib.getExe cfg.package;
|
|
|
|
DynamicUser = true;
|
|
|
|
|
|
|
|
### Hardening
|
2024-08-25 15:02:35 +00:00
|
|
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ]; # For ports <= 1024
|
|
|
|
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
|
2024-05-23 16:15:10 +00:00
|
|
|
NoNewPrivileges = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
PrivateTmp = true;
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
RestrictSUIDSGID = true;
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallFilter = "@system-service";
|
|
|
|
UMask = "0077";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = lib.mkIf cfg.openFirewall {
|
2024-08-25 15:02:35 +00:00
|
|
|
allowedTCPPorts = [ cfg.settings.PIXIVFE_PORT ];
|
2024-05-23 16:15:10 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|