{ config, lib, pkgs, ... }: with lib; let cfg = config.services.uucp.media-client; recv-media = with pkgs; stdenv.mkDerivation rec { name = "recv-media"; src = ./recv-media.sh; phases = [ "unpackPhase" "buildPhase" "installPhase" ]; unpackPhase = '' cp $src recv-media ''; inherit zsh coreutils utillinux; inherit (config.security) wrapperDir; inherit (cfg) mediaDir; doNotify = cfg.notify.users != []; ffmpeg = if doNotify then ffmpeg-full else "/no-such-path"; notify = writeScript "notify.sh" '' #!${zsh}/bin/zsh input=$(cat) ${concatMapStringsSep "\n" (name: ''${wrapperDir}/notify-${name} $@ <<<''${input}'') cfg.notify.users} ''; buildPhase = '' substituteAllInPlace recv-media ''; installPhase = '' mkdir -p $out/bin install -m 755 -t $out/bin \ recv-media ''; }; in { options = { services.uucp.media-client = { remoteNodes = mkOption { type = with types; listOf str; default = []; description = '' Servers to receive media from ''; }; notify = { users = mkOption { type = with types; listOf str; default = []; description = '' Users to notify ''; }; extractTitle = mkOption { type = types.bool; default = true; description = '' Use ffmpeg to include the media title in notifications ''; }; }; mediaDir = mkOption { type = types.path; default = "/var/media"; description = "Media directory"; }; }; }; imports = [ ./notify-users.nix ]; config = mkIf (cfg.remoteNodes != []) { services.uucp.commandPath = [ "${recv-media}/bin" ]; services.uucp.remoteNodes = genAttrs cfg.remoteNodes (name: { commands = ["recv-media"]; } ); services.notify-users = mkIf (cfg.notify.users != []) cfg.notify.users; }; }