python312Packages.publicsuffixlist: 1.0.2.20241207 -> 1.0.2.20241213 (#365192)
[NixPkgs.git] / nixos / modules / services / audio / gonic.nix
blob5f55f776bf8b69b90f5ababbfde1ed09652f9c1c
1 { config, lib, pkgs, ... }:
2 let
3   cfg = config.services.gonic;
4   settingsFormat = pkgs.formats.keyValue {
5     mkKeyValue = lib.generators.mkKeyValueDefault { } " ";
6     listsAsDuplicateKeys = true;
7   };
8 in
10   options = {
11     services.gonic = {
13       enable = lib.mkEnableOption "Gonic music server";
15       settings = lib.mkOption rec {
16         type = settingsFormat.type;
17         apply = lib.recursiveUpdate default;
18         default = {
19           listen-addr = "127.0.0.1:4747";
20           cache-path = "/var/cache/gonic";
21           tls-cert = null;
22           tls-key = null;
23         };
24         example = {
25           music-path = [ "/mnt/music" ];
26           podcast-path = "/mnt/podcasts";
27         };
28         description = ''
29           Configuration for Gonic, see <https://github.com/sentriz/gonic#configuration-options> for supported values.
30         '';
31       };
33     };
34   };
36   config = lib.mkIf cfg.enable {
37     systemd.services.gonic = {
38       description = "Gonic Media Server";
39       after = [ "network.target" ];
40       wantedBy = [ "multi-user.target" ];
41       serviceConfig = {
42         ExecStart =
43           let
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;
46           in
47           "${pkgs.gonic}/bin/gonic -config-path ${settingsFormat.generate "gonic" filteredSettings}";
48         DynamicUser = true;
49         StateDirectory = "gonic";
50         CacheDirectory = "gonic";
51         WorkingDirectory = "/var/lib/gonic";
52         RuntimeDirectory = "gonic";
53         RootDirectory = "/run/gonic";
54         ReadWritePaths = "";
55         BindPaths = [
56           cfg.settings.playlists-path
57         ];
58         BindReadOnlyPaths = [
59           # gonic can access scrobbling services
60           "-/etc/resolv.conf"
61           "-/etc/ssl/certs/ca-certificates.crt"
62           builtins.storeDir
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;
71         PrivateUsers = true;
72         ProtectClock = true;
73         ProtectControlGroups = true;
74         ProtectHome = 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;
83         UMask = "0066";
84         ProtectHostname = true;
85       };
86     };
87   };
89   meta.maintainers = [ lib.maintainers.autrimpo ];