{ 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; wrapperdir = config.security.wrapperDir; mediadir = cfg.mediaDir; donotify = if cfg.notify.users != [] then "true" else "false"; showtitle = if cfg.notify.extractTitle then "true" else "false"; ffmpeg = if cfg.notify.users != [] 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"; }; mediaGroup = mkOption { type = types.str; default = "media"; }; }; }; imports = [ ./notify-users.nix ]; config = mkIf (cfg.remoteNodes != []) { services.uucp.commandPath = [ "${recv-media}/bin" ]; services.uucp.remoteNodes = genAttrs cfg.remoteNodes (name: { commands = ["recv-media"]; } ); assertions = map (user: { assertion = elem user config.services.notify-users; message = "Notification must be allowed for ${user}!"; }) (unique cfg.notify.users); users.groups."${cfg.mediaGroup}" = { members = [ "uucp" ]; }; system.activationScripts = '' mkdir -m 0755 -pv ${cfg.mediaDir} chown :${cfg.mediaGroup} ${cfg.mediaDir} chmod -c "g+rwx" ${cfg.mediaDir} ''; }; }