{ 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; inherit (config.security) wrapperDir; inherit (cfg) mediaDir; utillinux = util-linux; doNotify = cfg.notify.users != []; ffmpeg = if doNotify then ffmpeg-full else "/no-such-path"; notify = writeScript "notify.sh" '' #!${zsh}/bin/zsh ${concatMapStringsSep "\n" ({ name, ... }: "${notify-user name}/bin/notify-${name} $@") 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 = mkIf (cfg.notify.users != []) [ ./custom/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 != []) notify.users; }; }