1 { config, lib, pkgs, ... }:
3 cfg = config.services.gonic;
4 settingsFormat = pkgs.formats.keyValue {
5 mkKeyValue = lib.generators.mkKeyValueDefault { } " ";
6 listsAsDuplicateKeys = true;
13 enable = lib.mkEnableOption "Gonic music server";
15 settings = lib.mkOption rec {
16 type = settingsFormat.type;
17 apply = lib.recursiveUpdate default;
19 listen-addr = "127.0.0.1:4747";
20 cache-path = "/var/cache/gonic";
25 music-path = [ "/mnt/music" ];
26 podcast-path = "/mnt/podcasts";
29 Configuration for Gonic, see <https://github.com/sentriz/gonic#configuration-options> for supported values.
36 config = lib.mkIf cfg.enable {
37 systemd.services.gonic = {
38 description = "Gonic Media Server";
39 after = [ "network.target" ];
40 wantedBy = [ "multi-user.target" ];
44 # these values are null by default but should not appear in the final config
45 filteredSettings = lib.filterAttrs (n: v: !((n == "tls-cert" || n == "tls-key") && v == null)) cfg.settings;
47 "${pkgs.gonic}/bin/gonic -config-path ${settingsFormat.generate "gonic" filteredSettings}";
49 StateDirectory = "gonic";
50 CacheDirectory = "gonic";
51 WorkingDirectory = "/var/lib/gonic";
52 RuntimeDirectory = "gonic";
53 RootDirectory = "/run/gonic";
56 cfg.settings.playlists-path
59 # gonic can access scrobbling services
61 "-/etc/ssl/certs/ca-certificates.crt"
63 cfg.settings.podcast-path
64 ] ++ cfg.settings.music-path
65 ++ lib.optional (cfg.settings.tls-cert != null) cfg.settings.tls-cert
66 ++ lib.optional (cfg.settings.tls-key != null) cfg.settings.tls-key;
67 CapabilityBoundingSet = "";
68 RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
69 RestrictNamespaces = true;
70 PrivateDevices = true;
73 ProtectControlGroups = true;
75 ProtectKernelLogs = true;
76 ProtectKernelModules = true;
77 ProtectKernelTunables = true;
78 SystemCallArchitectures = "native";
79 SystemCallFilter = [ "@system-service" "~@privileged" ];
80 RestrictRealtime = true;
81 LockPersonality = true;
82 MemoryDenyWriteExecute = true;
84 ProtectHostname = true;
89 meta.maintainers = [ lib.maintainers.autrimpo ];