Something went wrong. Try again.
nixos config
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204{ pkgs, lib }:let
screenshotScript = pkgs.writeShellScriptBin "screenshot" '' MODE="$1" BASE_DIR="$HOME/Pictures/screenshots" DATE_DIR="$(date +'%Y-%m-%d')" DIR="$BASE_DIR/$DATE_DIR" mkdir -p "$DIR" TMPDIR=$(mktemp -d) FILE="$DIR/$(date +'%Y-%m-%d_%H-%M-%S').png"
if [ "$MODE" = "select" ]; then ${lib.getExe pkgs.scrot} -s "$FILE" || exit 1 else ${lib.getExe pkgs.scrot} "$FILE" || exit 1 fi
[ ! -f "$FILE" ] && exit 1 ${pkgs.xclip}/bin/xclip -selection clipboard -t image/png -i "$FILE"
CROPPED_FILE="$TMPDIR/cropped.png" ${pkgs.imagemagick}/bin/magick "$FILE" \ -gravity center \ -crop '%[fx:min(w,h)]x%[fx:min(w,h)]+0+0' \ -resize 128x128 +repage "$CROPPED_FILE" 2>/dev/null \ || CROPPED_FILE="$FILE"
ACTION=$(${pkgs.libnotify}/bin/dunstify "Screenshot saved" \ -i "$CROPPED_FILE" -t 4000 \ -A view,"View Image" \ -A open,"Open Folder") [ "$ACTION" = "view" ] && xdg-open "$FILE" & [ "$ACTION" = "open" ] && xdg-open "$(dirname "$FILE")" & (sleep 3 && rm -rf "$TMPDIR") & ''; screenrecordScript = pkgs.writeShellScriptBin "screenrecord" '' FPS=60 VIDEO_CODEC="hevc" AUDIO_CODEC="opus" QUALITY="high" MODE="$1" BASE_DIR="$HOME/Videos/recordings" DIR="$BASE_DIR/$(date +'%Y-%m-%d')" mkdir -p "$DIR" PIDFILE="/tmp/gpu-screen-recorder.pid"
if [ -f "$PIDFILE" ]; then PID=$(head -1 "$PIDFILE") FILE=$(tail -1 "$PIDFILE")
if kill -0 "$PID" 2>/dev/null; then kill -INT "$PID" wait "$PID" 2>/dev/null rm -f "$PIDFILE"
TMPDIR=$(mktemp -d) THUMB="$TMPDIR/thumb.png"
${lib.getExe pkgs.ffmpeg} \ -i "$FILE" \ -vframes 1 \ -vf "scale=128:128:force_original_aspect_ratio=increase,crop=128:128" \ -y "$THUMB" \ 2>/dev/null
printf 'file://%s' "$FILE" | ${pkgs.xclip}/bin/xclip -selection clipboard
ICON_ARG="" [ -f "$THUMB" ] && ICON_ARG="-i $THUMB"
ACTION=$(${pkgs.libnotify}/bin/dunstify \ "Recording saved" \ $ICON_ARG \ -t 4000 \ -A view,"View Recording" \ -A open,"Open Folder")
[ "$ACTION" = "view" ] && xdg-open "$FILE" [ "$ACTION" = "open" ] && xdg-open "$(dirname "$FILE")"
(sleep 3 && rm -rf "$TMPDIR") & exit 0 else rm -f "$PIDFILE" fi fi
FILE="$DIR/$(date +'%Y-%m-%d_%H-%M-%S').mp4"
MONITOR=$(${pkgs.xrandr}/bin/xrandr --current \ | awk '/ connected/ {print $1; exit}')
if [ "$MODE" = "select" ]; then GEOMETRY=$(${lib.getExe pkgs.slop} -f "%wx%h+%x+%y") || exit 1
${pkgs.gpu-screen-recorder}/bin/gpu-screen-recorder \ -w region \ -region "$GEOMETRY" \ -c mp4 \ -f "$FPS" \ -a default_output \ -ac "$AUDIO_CODEC" \ -k "$VIDEO_CODEC" \ -q "$QUALITY" \ -o "$FILE" & else ${pkgs.gpu-screen-recorder}/bin/gpu-screen-recorder \ -w "$MONITOR" \ -c mp4 \ -f "$FPS" \ -a default_output \ -ac "$AUDIO_CODEC" \ -k "$VIDEO_CODEC" \ -q "$QUALITY" \ -o "$FILE" & fi
PID=$! printf '%s\n%s\n' "$PID" "$FILE" > "$PIDFILE" ''; cavaScript = pkgs.writeShellScriptBin "waybar-cava" '' set -u bars=(▁ ▂ ▃ ▄ ▅ ▆ ▇ █) config_file="/tmp/waybar_cava_config" cat > "$config_file" <<CAVAEOF [general] bars = 16 framerate = 60 autosens = 1
[output] method = raw raw_target = /dev/stdout data_format = ascii ascii_max_range = 7 CAVAEOF
trap 'kill 0 2>/dev/null || true' EXIT pause_start=0
convert_to_bars() { local line="$1" IFS=';' local -a nums out="" read -ra nums <<< "$line" for n in "''${nums[@]}"; do (( n < 0 || n > 7 )) && n=0 out+="''${bars[n]}" done printf '%s\n' "$out" }
is_silence() { local l="''${1//;/}" [[ -z "''${l//0/}" ]] }
${pkgs.cava}/bin/cava -p "$config_file" 2>/dev/null | while IFS= read -r line || [[ -n "$line" ]]; do if is_silence "$line"; then (( pause_start == 0 )) && pause_start=$SECONDS if (( SECONDS - pause_start >= 2 )); then echo "" else convert_to_bars "$line" fi continue fi pause_start=0 convert_to_bars "$line" done '';
trayIndicator = pkgs.writeShellScriptBin "waybar-tray-indicator" '' count=$(busctl --user get-property org.kde.StatusNotifierWatcher \ /StatusNotifierWatcher \ org.kde.StatusNotifierWatcher \ RegisteredStatusNotifierItems \ | sed -n 's/^as \([0-9]\+\).*/\1/p') if [ "${"count:-0"}" -gt 0 ]; then echo '{"text":"|","class":"show"}' else echo '{"text":"","class":"hide"}' fi '';
updatesCheck = pkgs.writeShellScriptBin "waybar-updates" '' n=$(nix store gc --dry-run 2>/dev/null | grep -c "would") if [ "$n" -gt 0 ]; then echo "{\"text\":\" $n\",\"tooltip\":\"$n items\"}" else echo '{"text":""}' fi '';
in{ home.packages = [ screenshotScript screenrecordScript cavaScript ]; inherit cavaScript trayIndicator updatesCheck;}