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