2022-07-14 12:49:19 +00:00
|
|
|
{ config
|
|
|
|
, pkgs
|
|
|
|
, lib
|
|
|
|
, ...}:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
let
|
|
|
|
cfg = config.services.polaris;
|
|
|
|
settingsFormat = pkgs.formats.toml {};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.polaris = {
|
2022-09-09 14:08:57 +00:00
|
|
|
enable = mkEnableOption (lib.mdDoc "Polaris Music Server");
|
2022-07-14 12:49:19 +00:00
|
|
|
|
2024-01-02 11:29:13 +00:00
|
|
|
package = mkPackageOption pkgs "polaris" { };
|
2022-07-14 12:49:19 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "polaris";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "User account under which Polaris runs.";
|
2022-07-14 12:49:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "polaris";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Group under which Polaris is run.";
|
2022-07-14 12:49:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraGroups = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Polaris' auxiliary groups.";
|
2022-07-14 12:49:19 +00:00
|
|
|
example = literalExpression ''["media" "music"]'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
|
|
|
type = types.port;
|
|
|
|
default = 5050;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-14 12:49:19 +00:00
|
|
|
The port which the Polaris REST api and web UI should listen to.
|
|
|
|
Note: polaris is hardcoded to listen to the hostname "0.0.0.0".
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = settingsFormat.type;
|
|
|
|
default = {};
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-14 12:49:19 +00:00
|
|
|
Contents for the TOML Polaris config, applied each start.
|
|
|
|
Although poorly documented, an example may be found here:
|
2022-08-12 12:06:08 +00:00
|
|
|
[test-config.toml](https://github.com/agersant/polaris/blob/374d0ca56fc0a466d797a4b252e2078607476797/test-data/config.toml)
|
2022-07-14 12:49:19 +00:00
|
|
|
'';
|
|
|
|
example = literalExpression ''
|
|
|
|
{
|
|
|
|
settings.reindex_every_n_seconds = 7*24*60*60; # weekly, default is 1800
|
|
|
|
settings.album_art_pattern =
|
|
|
|
"(cover|front|folder)\.(jpeg|jpg|png|bmp|gif)";
|
|
|
|
mount_dirs = [
|
|
|
|
{
|
|
|
|
name = "NAS";
|
|
|
|
source = "/mnt/nas/music";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "Local";
|
|
|
|
source = "/home/my_user/Music";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
openFirewall = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc ''
|
2022-07-14 12:49:19 +00:00
|
|
|
Open the configured port in the firewall.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
systemd.services.polaris = {
|
|
|
|
description = "Polaris Music Server";
|
|
|
|
after = [ "network.target" ];
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = rec {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
DynamicUser = true;
|
|
|
|
SupplementaryGroups = cfg.extraGroups;
|
|
|
|
StateDirectory = "polaris";
|
|
|
|
CacheDirectory = "polaris";
|
|
|
|
ExecStart = escapeShellArgs ([
|
|
|
|
"${cfg.package}/bin/polaris"
|
|
|
|
"--foreground"
|
|
|
|
"--port" cfg.port
|
|
|
|
"--database" "/var/lib/${StateDirectory}/db.sqlite"
|
|
|
|
"--cache" "/var/cache/${CacheDirectory}"
|
|
|
|
] ++ optionals (cfg.settings != {}) [
|
|
|
|
"--config" (settingsFormat.generate "polaris-config.toml" cfg.settings)
|
|
|
|
]);
|
|
|
|
Restart = "on-failure";
|
|
|
|
|
|
|
|
# Security options:
|
|
|
|
|
|
|
|
#NoNewPrivileges = true; # implied by DynamicUser
|
|
|
|
#RemoveIPC = true; # implied by DynamicUser
|
|
|
|
|
|
|
|
AmbientCapabilities = "";
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
|
|
|
|
DeviceAllow = "";
|
|
|
|
|
|
|
|
LockPersonality = true;
|
|
|
|
|
|
|
|
#PrivateTmp = true; # implied by DynamicUser
|
|
|
|
PrivateDevices = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
|
|
|
|
ProtectClock = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" "AF_UNIX" ];
|
|
|
|
RestrictRealtime = true;
|
|
|
|
#RestrictSUIDSGID = true; # implied by DynamicUser
|
|
|
|
|
|
|
|
SystemCallArchitectures = "native";
|
|
|
|
SystemCallErrorNumber = "EPERM";
|
|
|
|
SystemCallFilter = [
|
|
|
|
"@system-service"
|
|
|
|
"~@cpu-emulation" "~@debug" "~@keyring" "~@memlock" "~@obsolete" "~@privileged" "~@setuid"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
networking.firewall = mkIf cfg.openFirewall {
|
|
|
|
allowedTCPPorts = [ cfg.port ];
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
meta.maintainers = with maintainers; [ pbsds ];
|
|
|
|
}
|