diff --git a/flake.nix b/flake.nix index c8df7f0..82e2907 100644 --- a/flake.nix +++ b/flake.nix @@ -129,6 +129,7 @@ nix-index-auto-update-database = ./home/modules/programs/nix-index/auto-update-database.nix; direnv-auto-prune = ./home/modules/programs/direnv/auto-prune.nix; newsboat = ./home/modules/programs/newsboat; + mpd-auto-updater = ./home/modules/services/mpd.nix; }; homeConfigurations = { diff --git a/home/home.nix b/home/home.nix index e05cf1f..5455aeb 100644 --- a/home/home.nix +++ b/home/home.nix @@ -54,6 +54,7 @@ in { ./modules/programs/nix-index/auto-update-database.nix ./modules/programs/direnv/auto-prune.nix ./modules/programs/newsboat + ./modules/services/mpd.nix ] ++ (optionals graphics [ ./config/gtk.nix diff --git a/home/modules/services/mpd.nix b/home/modules/services/mpd.nix new file mode 100644 index 0000000..244940f --- /dev/null +++ b/home/modules/services/mpd.nix @@ -0,0 +1,54 @@ +{ config, pkgs, lib, ... }: +let + cfg = config.services.mpd; +in +{ + options.services.mpd.autoUpdateDatabase = lib.mkEnableOption "watchdog that updates the mpd database upon file changes"; + + config = lib.mkIf cfg.autoUpdateDatabase { + systemd.user.paths.mpd-update-database = { + Install.WantedBy = [ "paths.target" ]; + Unit = { + Description = "Watchdog that updates the mpd database upon file changes"; + Documentation = [ + "man:mpd(1)" + "man:mpd.conf(5)" + ]; + }; + Path = { + PathChanged = [ + cfg.musicDirectory + cfg.playlistDirectory + ]; + Unit = "mpd-update-database.service"; + TriggerLimitIntervalSec = "1s"; + TriggerLimitBurst = "1"; + }; + }; + + systemd.user.services.mpd-update-database = { + Unit = { + Description = "Watchdog that updates the mpd library whenever the files are modified"; + Documentation = [ + "man:mpd(1)" + "man:mpd.conf(5)" + ]; + }; + Service = { + Type = "oneshot"; + ExecStart = "${lib.getExe pkgs.mpc-cli} update --wait"; + + PrivateUsers = true; + ProtectSystem = true; + NoNewPrivileges = true; + ProtectKernelTunables = true; + ProtectControlGroups = true; + RestrictAddressFamilies = [ + "AF_INET" + "AF_UNIX" + ]; + RestrictNamespaces = true; + }; + }; + }; +} diff --git a/home/services/mpd.nix b/home/services/mpd.nix index f391529..aafef56 100644 --- a/home/services/mpd.nix +++ b/home/services/mpd.nix @@ -9,6 +9,8 @@ in playlistDirectory = "${cfg.musicDirectory}/playlists/MPD"; network.startWhenNeeded = true; + autoUpdateDatabase = true; + extraConfig = '' pid_file "/run/user/${toString config.home.uid}/mpd/pid" @@ -95,47 +97,5 @@ in RestrictNamespaces = true; }; }; - - systemd.user.paths.mpd-update-library = { - Unit = { - Description = "Watchdog that updates the mpd library whenever the files are modified"; - Documentation = [ - "man:mpd(1)" - "man:mpd.conf(5)" - ]; - WantedBy = [ "paths.target" ]; - }; - Path = { - PathChanged = cfg.musicDirectory; - Unit = "mpd-update-library.service"; - TriggerLimitIntervalSec = "1s"; - TriggerLimitBurst = "1"; - }; - }; - - systemd.user.services.mpd-update-library = { - Unit = { - Description = "Watchdog that updates the mpd library whenever the files are modified"; - Documentation = [ - "man:mpd(1)" - "man:mpd.conf(5)" - ]; - }; - Service = { - Type = "oneshot"; - ExecStart = "${lib.getExe pkgs.mpc-cli} update --wait"; - - PrivateUsers = true; - ProtectSystem = true; - NoNewPrivileges = true; - ProtectKernelTunables = true; - ProtectControlGroups = true; - RestrictAddressFamilies = [ - "AF_INET" - "AF_UNIX" - ]; - RestrictNamespaces = true; - }; - }; }