Skip to content

Commit

Permalink
fixed ssh-agent on servers, added yt-dlp script
Browse files Browse the repository at this point in the history
  • Loading branch information
heywoodlh committed Jan 24, 2025
1 parent d0b6c52 commit 88fa6bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
24 changes: 24 additions & 0 deletions nixos/roles/media/youtube.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,35 @@ let
nameserver 1.1.1.1
nameserver 1.0.0.1
'';
yt-dlp-wrapper = pkgs.writeShellScriptBin "yt-dlp-wrapper" ''
sudo -u media mkdir -p /tmp/yt-dlp
sudo -u media HOME=/tmp/yt-dlp ${pkgs.nix}/bin/nix --extra-experimental-features "nix-command flakes" run "github:nixos/nixpkgs/master#yt-dlp" -- --user-agent "Mozilla/5.0 (X11; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0" --cookies "/media/services/yt-dlp/cookies.txt" --cache-dir /tmp/yt-dlp -P "/media/home-media/disk2/videos/" $1
'';
youtube-dl = pkgs.writeShellScriptBin "youtube-dl" ''
ntfy_uri="http://ntfy/plex-notifications"
date="$(date +%Y%m%d-%H:%M:%S)"
outfile="/tmp/youtube-dl-$date.log"
${yt-dlp-wrapper}/bin/yt-dlp-wrapper "$1" &> $outfile
status=$?
if [ $status -eq 0 ]; then
message="Downloaded $1"
echo "$message"
else
message="Failed to download $1. Logfile at $outfile"
echo "$message"
fi
curl -d "$message" $ntfy_uri
'';
in {
networking.firewall.allowedTCPPorts = [
6081
];

environment.systemPackages = [
youtube-dl
];

virtualisation.oci-containers = {
backend = "docker";
containers = {
Expand Down
5 changes: 5 additions & 0 deletions nixos/server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ in {
programs.fish = {
enable = true;
interactiveShellInit = ''
if not ${pkgs.ps}/bin/ps -fjH -u $USER | ${pkgs.gnugrep}/bin/grep ssh-agent | ${pkgs.gnugrep}/bin/grep -q "$HOME/.ssh/agent.sock" &> /dev/null
mkdir -p $HOME/.ssh
rm -f $HOME/.ssh/agent.sock &> /dev/null
eval (${pkgs.openssh}/bin/ssh-agent -t 4h -c -a "$HOME/.ssh/agent.sock") &> /dev/null || true
end
'';
};

Expand Down

0 comments on commit 88fa6bb

Please sign in to comment.