9 cfg = config.services.mympd;
16 enable = lib.mkEnableOption "MyMPD server";
18 package = lib.mkPackageOption pkgs "mympd" { };
20 openFirewall = lib.mkOption {
21 type = lib.types.bool;
24 Open ports needed for the functionality of the program.
28 extraGroups = lib.mkOption {
29 type = lib.types.listOf lib.types.str;
31 example = [ "music" ];
33 Additional groups for the systemd service.
37 settings = lib.mkOption {
38 type = lib.types.submodule {
49 http_port = lib.mkOption {
50 type = lib.types.port;
52 The HTTP port where mympd's web interface will be available.
54 The HTTPS/SSL port can be configured via {option}`config`.
60 type = lib.types.bool;
62 Whether to enable listening on the SSL port.
64 Refer to <https://jcorporation.github.io/myMPD/configuration/configuration-files#ssl-options>
72 Manages the configuration files declaratively. For all the configuration
73 options, see <https://jcorporation.github.io/myMPD/configuration/configuration-files>.
75 Each key represents the "File" column from the upstream configuration table, and the
76 value is the content of that file.
83 config = lib.mkIf cfg.enable {
84 systemd.services.mympd = {
85 # upstream service config: https://github.com/jcorporation/myMPD/blob/master/contrib/initscripts/mympd.service.in
86 after = [ "mpd.service" ];
87 wantedBy = [ "multi-user.target" ];
88 preStart = with lib; ''
89 config_dir="/var/lib/mympd/config"
90 mkdir -p "$config_dir"
95 echo -n "${if isBool value then boolToString value else toString value}" > "$config_dir/${name}"
98 (concatStringsSep "\n")
102 Description = "myMPD server daemon";
103 Documentation = "man:mympd(1)";
106 AmbientCapabilities = "CAP_NET_BIND_SERVICE";
107 CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
109 ExecStart = lib.getExe cfg.package;
110 LockPersonality = true;
111 MemoryDenyWriteExecute = true;
112 PrivateDevices = true;
114 ProtectControlGroups = true;
116 ProtectHostname = true;
117 ProtectKernelLogs = true;
118 ProtectKernelModules = true;
119 ProtectKernelTunables = true;
120 ProtectProc = "invisible";
121 RestrictRealtime = true;
122 StateDirectory = "mympd";
123 CacheDirectory = "mympd";
124 RestrictAddressFamilies = "AF_INET AF_INET6 AF_NETLINK AF_UNIX";
125 RestrictNamespaces = true;
126 SystemCallArchitectures = "native";
127 SystemCallFilter = "@system-service";
128 SupplementaryGroups = cfg.extraGroups;
132 networking.firewall = lib.mkMerge [
133 (lib.mkIf cfg.openFirewall {
134 allowedTCPPorts = [ cfg.settings.http_port ];
136 (lib.mkIf (cfg.openFirewall && cfg.settings.ssl && cfg.settings.ssl_port != null) {
137 allowedTCPPorts = [ cfg.settings.ssl_port ];
143 meta.maintainers = [ lib.maintainers.eliandoran ];