2023-02-16 17:41:37 +00:00
|
|
|
{ lib, config, pkgs, utils, ... }:
|
|
|
|
|
|
|
|
let
|
2024-04-21 15:54:59 +00:00
|
|
|
inherit (lib) mkEnableOption mkIf mkOption types;
|
2023-02-16 17:41:37 +00:00
|
|
|
|
|
|
|
cfg = config.services.imaginary;
|
|
|
|
in {
|
|
|
|
options.services.imaginary = {
|
2024-04-21 15:54:59 +00:00
|
|
|
enable = mkEnableOption "imaginary image processing microservice";
|
2023-02-16 17:41:37 +00:00
|
|
|
|
|
|
|
address = mkOption {
|
|
|
|
type = types.str;
|
2023-03-04 12:14:45 +00:00
|
|
|
default = "localhost";
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-03-04 12:14:45 +00:00
|
|
|
Bind address. Corresponds to the `-a` flag.
|
|
|
|
Set to `""` to bind to all addresses.
|
|
|
|
'';
|
|
|
|
example = "[::1]";
|
2023-02-16 17:41:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 8088;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Bind port. Corresponds to the `-p` flag.";
|
2023-02-16 17:41:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
2024-04-21 15:54:59 +00:00
|
|
|
description = ''
|
2023-02-16 17:41:37 +00:00
|
|
|
Command line arguments passed to the imaginary executable, stripped of
|
|
|
|
the prefix `-`. See upstream's
|
|
|
|
[README](https://github.com/h2non/imaginary#command-line-usage) for all
|
|
|
|
options.
|
|
|
|
'';
|
|
|
|
type = types.submodule {
|
|
|
|
freeformType = with types; attrsOf (oneOf [
|
|
|
|
bool
|
|
|
|
int
|
|
|
|
(nonEmptyListOf str)
|
|
|
|
str
|
|
|
|
]);
|
|
|
|
|
|
|
|
options = {
|
|
|
|
return-size = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2024-04-21 15:54:59 +00:00
|
|
|
description = "Return the image size in the HTTP headers.";
|
2023-02-16 17:41:37 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
assertions = [ {
|
|
|
|
assertion = ! lib.hasAttr "a" cfg.settings;
|
|
|
|
message = "Use services.imaginary.address to specify the -a flag.";
|
|
|
|
} {
|
|
|
|
assertion = ! lib.hasAttr "p" cfg.settings;
|
|
|
|
message = "Use services.imaginary.port to specify the -p flag.";
|
|
|
|
} ];
|
|
|
|
|
|
|
|
systemd.services.imaginary = {
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
serviceConfig = rec {
|
|
|
|
ExecStart = let
|
|
|
|
args = lib.mapAttrsToList (key: val:
|
|
|
|
"-" + key + "=" + lib.concatStringsSep "," (map toString (lib.toList val))
|
|
|
|
) (cfg.settings // { a = cfg.address; p = cfg.port; });
|
|
|
|
in "${pkgs.imaginary}/bin/imaginary ${utils.escapeSystemdExecArgs args}";
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
BindReadOnlyPaths = lib.optional (cfg.settings ? mount) cfg.settings.mount;
|
|
|
|
CapabilityBoundingSet = if cfg.port < 1024 then
|
|
|
|
[ "CAP_NET_BIND_SERVICE" ]
|
|
|
|
else
|
|
|
|
[ "" ];
|
|
|
|
AmbientCapabilities = CapabilityBoundingSet;
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
DynamicUser = true;
|
|
|
|
ProtectSystem = "strict";
|
|
|
|
ProtectHome = true;
|
|
|
|
TemporaryFileSystem = [ "/:ro" ];
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = cfg.port >= 1024;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
RestrictAddressFamilies = [
|
|
|
|
"AF_INET"
|
|
|
|
"AF_INET6"
|
|
|
|
];
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
LockPersonality = true;
|
|
|
|
MemoryDenyWriteExecute = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
PrivateMounts = true;
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@privileged"
|
|
|
|
];
|
|
|
|
DevicePolicy = "closed";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
meta = {
|
|
|
|
maintainers = with lib.maintainers; [ dotlambda ];
|
|
|
|
};
|
|
|
|
}
|