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