From 618e4580240c71a7ac866649e01439e75ef4d6a6 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 23 Aug 2024 23:36:43 +0200 Subject: ... --- accounts/gkleen@sif/hyprland.nix | 4 +++ accounts/gkleen@sif/systemd.nix | 55 +++++++++++++++++++++++++++++++- home-modules/lmu-hausschrift/default.nix | 37 ++++++++++++++------- 3 files changed, 83 insertions(+), 13 deletions(-) diff --git a/accounts/gkleen@sif/hyprland.nix b/accounts/gkleen@sif/hyprland.nix index 645a2f22..052f35b0 100644 --- a/accounts/gkleen@sif/hyprland.nix +++ b/accounts/gkleen@sif/hyprland.nix @@ -184,6 +184,10 @@ in { "CTRL, comma, exec, dunstctl history-pop" "$mainMod ALT, E, exec, emacsclient -c" + "$mainMod ALT, Y, exec, ${pkgs.writeShellScript "yt-dlp" '' + export PATH="${lib.makeBinPath (with pkgs; [ wl-clipboard-rs socat ])}:$PATH" + socat STDIO UNIX-CONNECT:"$XDG_RUNTIME_DIR"/yt-dlp.sock <<<$'{ "urls": ["'"$(wl-paste)"$'"] }' + ''}" ", XF86MonBrightnessUp, exec, lightctl -d -e4 -n1 up" ", XF86MonBrightnessDown, exec, lightctl -d -e4 -n1 down" diff --git a/accounts/gkleen@sif/systemd.nix b/accounts/gkleen@sif/systemd.nix index 09d058de..b7bf902e 100644 --- a/accounts/gkleen@sif/systemd.nix +++ b/accounts/gkleen@sif/systemd.nix @@ -278,6 +278,47 @@ in { ''}''; }; }; + "yt-dlp@" = { + Service = { + Type = "notify"; + RuntimeDirectory = "%N"; + StandardInput = "socket"; + StandardOutput = "journal"; + WatchdogSec = "10s"; + Environment = [ + "PATH=${lib.makeBinPath (with pkgs; [atomicparsley ffmpeg-headless rtmpdump])}" + ]; + ExecStart = pkgs.writers.writePython3 "yt-dlp" { + libraries = with pkgs.python3Packages; [ yt-dlp sdnotify ]; + } '' + import json + from yt_dlp import YoutubeDL, parse_options + from sys import stdin + from sdnotify import SystemdNotifier + from os import environ + from pathlib import Path + + + n = SystemdNotifier() + args = json.load(stdin) + ydl_opts = { + **parse_options().ydl_opts, + 'progress_hooks': [lambda _d: n.notify('WATCHDOG=1')], + 'postprocessor_hooks': [lambda _d: n.notify('WATCHDOG=1')], + 'progress_with_newline': True, + 'progress_delta': 5, + 'paths': { + 'home': str(Path.home() / 'media'), + 'temp': str(Path(environ['RUNTIME_DIRECTORY'])), + }, + **(args['params'] if 'params' in args else {}), + } + with YoutubeDL(ydl_opts) as ytdl: + n.notify('READY=1') + ytdl.download(args['urls']) + ''; + }; + }; } // listToAttrs (map ({host, port}: nameValuePair "proxy-to-autossh-socks@${toString port}" { Unit = { Requires = ["autossh-socks@${host}:${toString (port + 1)}.service" "proxy-to-autossh-socks@${toString port}.socket"]; @@ -294,7 +335,19 @@ in { Install = { WantedBy = ["default.target"]; }; - }) [8118 8120]); + }) [8118 8120]) // { + "yt-dlp" = { + Socket = { + SocketMode = "0600"; + Accept = true; + ListenStream = "%t/yt-dlp.sock"; + TriggerLimitIntervalSec = 0; + }; + Install = { + WantedBy = ["sockets.target"]; + }; + }; + }; timers = { sync-keepass = { Timer = { diff --git a/home-modules/lmu-hausschrift/default.nix b/home-modules/lmu-hausschrift/default.nix index c3344947..ceaf7252 100644 --- a/home-modules/lmu-hausschrift/default.nix +++ b/home-modules/lmu-hausschrift/default.nix @@ -24,24 +24,37 @@ with lib; ''; }; - systemd.user.services.sops-nix = { + systemd.user.services.unpack-lmu-hausschrift = { + Unit = { + ConditionPathExists = [ + "!%h/.local/share/lmu-hausschrift" + "!%t/lmu-hausschrift" + ]; + }; + Unit = { + After = ["sops-nix.service"]; + }; + Install = { + WantedBy = ["sops-nix.service"]; + }; Service = { - ExecStartPost = pkgs.writeShellScript "unpack-lmu-hausschrift.sh" '' + UMask = "07077"; + Environment = [ + "PATH=${lib.makeBinPath (with pkgs; [gnutar coreutils])}" + ]; + ExecStart = pkgs.writeShellScript "unpack-lmu-hausschrift.sh" '' set -xe out=''${XDG_RUNTIME_DIR:-/tmp}/lmu-hausschrift src="${config.sops.secrets."lmu-hausschrift.tar.zstd".path}" - src=''${src#"%r/"} - src=''${XDG_RUNTIME_DIR:-/tmp}/"''${src}" - - umask 07077 - - if [[ ! -d "''${out}" ]]; then - ${pkgs.coreutils}/bin/mkdir -p "''${out}" - ${pkgs.gnutar}/bin/tar -xaf "''${src}" -C "''${out}" - - ${pkgs.coreutils}/bin/ln -sfT "''${out}" "${config.home.homeDirectory}/.local/share/lmu-hausschrift" + if [[ "$src" =~ ^%r ]]; then + src=''${src#"%r/"} + src=''${XDG_RUNTIME_DIR:-/tmp}/"''${src}" fi + + mkdir -p "''${out}" + tar -xaf "''${src}" -C "''${out}" + ln -sfT "''${out}" "${config.home.homeDirectory}/.local/share/lmu-hausschrift" ''; }; }; -- cgit v1.2.3