1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-23 10:19:48 +01:00

mpd: systemd socket activation

This commit is contained in:
arcnmx 2020-10-02 13:50:48 -07:00 committed by Robert Helgesson
parent 99fbae0ec5
commit c8746fb588
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -50,7 +50,7 @@ in {
'';
};
musicDirectory = mkOption {
musicDirectory = mkOption {
type = with types; either path str;
default = "${config.home.homeDirectory}/music";
defaultText = "$HOME/music";
@ -96,7 +96,14 @@ in {
'';
};
network = {
network = {
startWhenNeeded = mkOption {
type = types.bool;
default = false;
description = ''
Enable systemd socket activation.
'';
};
listenAddress = mkOption {
type = types.str;
@ -143,7 +150,7 @@ in {
Description = "Music Player Daemon";
};
Install = {
Install = mkIf (!cfg.network.startWhenNeeded) {
WantedBy = [ "default.target" ];
};
@ -154,6 +161,23 @@ in {
ExecStartPre = ''${pkgs.bash}/bin/bash -c "${pkgs.coreutils}/bin/mkdir -p '${cfg.dataDir}' '${cfg.playlistDirectory}'"'';
};
};
systemd.user.sockets.mpd = mkIf cfg.network.startWhenNeeded {
Socket = {
ListenStream = let
listen =
if cfg.network.listenAddress == "any"
then toString cfg.network.port
else "${cfg.network.listenAddress}:${toString cfg.network.port}";
in [ listen "%t/mpd/socket" ];
Backlog = 5;
KeepAlive = true;
};
Install = {
WantedBy = [ "sockets.target" ];
};
};
};
}