From 0d168edb2876014627a56b787e3c75a7ec60ef7c Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Mon, 17 Nov 2025 22:08:29 +0200 Subject: [PATCH] nixos/mpd: use pkgs.writeTextFile, with a checkPhase --- nixos/modules/services/audio/mpd.nix | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/audio/mpd.nix b/nixos/modules/services/audio/mpd.nix index 835009f6b081..2f5e8c1a2bcd 100644 --- a/nixos/modules/services/audio/mpd.nix +++ b/nixos/modules/services/audio/mpd.nix @@ -24,7 +24,9 @@ let lib.concatStringsSep "\n" placeholders ); - mpdConf = pkgs.writeText "mpd.conf" '' + mpdConf = pkgs.writeTextFile { + name = "mpd.conf"; + text = '' # This file was automatically generated by NixOS. Edit mpd's configuration # via NixOS' configuration.nix, as this file will be rewritten upon mpd's # restart. @@ -48,6 +50,27 @@ let ${cfg.extraConfig} ''; + derivationArgs = { + expectScript = '' + spawn ${lib.getExe pkgs.buildPackages.mpd} --no-daemon "$env(out)" + expect { + "exception: Error in \"$env(out)\"" { + puts "Config file invalid\n" + exit 1 + } + "exception:" { + exit 0 + } + } + ''; + passAsFile = [ + "expectScript" + ]; + }; + checkPhase = '' + ${lib.getExe pkgs.buildPackages.expect} -f "$expectScriptPath" + ''; + }; in {