mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-26 07:34:11 +00:00
2e751c0772
the conversion procedure is simple: - find all things that look like options, ie calls to either `mkOption` or `lib.mkOption` that take an attrset. remember the attrset as the option - for all options, find a `description` attribute who's value is not a call to `mdDoc` or `lib.mdDoc` - textually convert the entire value of the attribute to MD with a few simple regexes (the set from mdize-module.sh) - if the change produced a change in the manual output, discard - if the change kept the manual unchanged, add some text to the description to make sure we've actually found an option. if the manual changes this time, keep the converted description this procedure converts 80% of nixos options to markdown. around 2000 options remain to be inspected, but most of those fail the "does not change the manual output check": currently the MD conversion process does not faithfully convert docbook tags like <code> and <package>, so any option using such tags will not be converted at all.
152 lines
4.2 KiB
Nix
152 lines
4.2 KiB
Nix
{ config
|
|
, pkgs
|
|
, lib
|
|
, ...}:
|
|
|
|
with lib;
|
|
let
|
|
cfg = config.services.polaris;
|
|
settingsFormat = pkgs.formats.toml {};
|
|
in
|
|
{
|
|
options = {
|
|
services.polaris = {
|
|
enable = mkEnableOption "Polaris Music Server";
|
|
|
|
package = mkPackageOption pkgs "polaris" { };
|
|
|
|
user = mkOption {
|
|
type = types.str;
|
|
default = "polaris";
|
|
description = lib.mdDoc "User account under which Polaris runs.";
|
|
};
|
|
|
|
group = mkOption {
|
|
type = types.str;
|
|
default = "polaris";
|
|
description = lib.mdDoc "Group under which Polaris is run.";
|
|
};
|
|
|
|
extraGroups = mkOption {
|
|
type = types.listOf types.str;
|
|
default = [];
|
|
description = lib.mdDoc "Polaris' auxiliary groups.";
|
|
example = literalExpression ''["media" "music"]'';
|
|
};
|
|
|
|
port = mkOption {
|
|
type = types.port;
|
|
default = 5050;
|
|
description = lib.mdDoc ''
|
|
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 = {};
|
|
description = lib.mdDoc ''
|
|
Contents for the TOML Polaris config, applied each start.
|
|
Although poorly documented, an example may be found here:
|
|
[test-config.toml](https://github.com/agersant/polaris/blob/374d0ca56fc0a466d797a4b252e2078607476797/test-data/config.toml)
|
|
'';
|
|
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;
|
|
description = lib.mdDoc ''
|
|
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 ];
|
|
}
|