massive rewrite using flake-parts

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2022-12-08 01:00:12 +05:30
parent dfd8c57b60
commit aaf19ee844
45 changed files with 245 additions and 531 deletions

View File

@@ -0,0 +1,12 @@
{lib, stdenvNoCC, fetchFromGitHub}:
stdenvNoCC.mkDerivation {
name = "customscripts";
src = ./src;
unpackPhase = ":";
installPhase = ''
mkdir -p $out/bin
cp -r $src/* $out/bin
chmod -R +x $out/bin/*
'';
}

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p rage
if [ $# -eq 0 ]; then echo "bruh"; exit 1; fi
FILE=$1
if [ $# -eq 2 ]; then
TARGET="$2.age"
elif [ $# -eq 1 ]; then
TARGET="$FILE.age"
else
echo "bruh"
exit 1
fi
keys=""
for x in ~/.ssh/*.pub
do
keys="$keys -r \"$(cat "$x")\""
done
echo rage -o $TARGET $keys $FILE

View File

@@ -0,0 +1,3 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg sox
mkdir spectrals; cd spectrals; for x in ../*$1;do sox "$x" -n spectrogram -o "$(echo $(ffprobe -loglevel error -show_entries format_tags=track -of default=noprint_wrappers=1:nokey=1 "$x") - $(ffprobe -loglevel error -show_entries format_tags=TITLE -of default=noprint_wrappers=1:nokey=1 "$x")).png"; done

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p sox ffmpeg curl jq
mkdir spectrals
cd spectrals
for x in ../*$1
do
spec="$(echo $(ffprobe -loglevel error -show_entries format_tags=track -of default=noprint_wrappers=1:nokey=1 "$x") - $(ffprobe -loglevel error -show_entries format_tags=TITLE -of default=noprint_wrappers=1:nokey=1 "$x"))"
sox "$x" -n spectrogram -o "$spec.png" -t "$spec"
resp=$(curl -F file-upload=@"$spec.png" -F "api_key=$PTPIMGAPI" https://ptpimg.me/upload.php 2>/dev/null)
echo "$spec"
echo [img]https://ptpimg.me/$(echo $resp | jq -r .[0].code).$(echo $resp | jq -r .[0].ext)[/img]
rm "$spec.png"
done
cd ..
rm -r spectrals

View File

@@ -0,0 +1,16 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg sox
IFS=$'\n'
for i in $(ls *$3)
do
if [ $1 = "320" ]; then
ffmpeg -i "$i" -codec:a libmp3lame -b:a 320k -map_metadata 0 -id3v2_version 3 "$2/${i%.$3}".mp3
elif [ $1 = "v0" ]; then
ffmpeg -i "$i" -codec:a libmp3lame -q:a 0 -map_metadata 0 -id3v2_version 3 "$2/${i%.$3}".mp3
elif [ $1 = "alactoflac" ]; then
ffmpeg -i "$i" -codec:a flac -map_metadata 0 -id3v2_version 3 "$2/${i%.$3}".flac
else
sox "$i" -G -b 16 "$2/${i%.$3}".flac rate -v -L 48000 dither
fi
echo $i
done

View File

@@ -0,0 +1,10 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p flac
if [ $1 == "flac" ]; then
for x in *.flac; do
flac "$x" --compression-level-8 -o "bruh.$x"
mv "bruh.$x" "$x"
done
else
echo "bruh"
fi

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg
target_video_size_KB="$2"
origin_duration_s=$(ffprobe -v error -show_streams -select_streams a "$1" | grep -Po "(?<=^duration\=)\d*\.\d*")
echo $origin_duration_s
origin_audio_bitrate_kbit_s=$(ffprobe -v error -pretty -show_streams -select_streams a "$1" | grep -Po "(?<=^bit_rate\=)\d*\.\d*")
target_audio_bitrate_kbit_s=$origin_audio_bitrate_kbit_s
target_video_bitrate_kbit_s=$(\
awk \
-v size="$target_video_size_KB" \
-v duration="$origin_duration_s" \
-v audio_rate="$target_audio_bitrate_kbit_s" \
'BEGIN { print ( ( size * 8.0 ) / ( 1.048576 * duration ) - audio_rate ) }')
ffmpeg \
-y \
-i "$1" \
-c:v libx264 \
-b:v "$target_video_bitrate_kbit_s"k \
-pass 1 \
-an \
-f mp4 \
/dev/null \
&& \
ffmpeg \
-i "$1" \
-c:v libx264 \
-b:v "$target_video_bitrate_kbit_s"k \
-pass 2 \
-c:a aac \
-b:a "$target_audio_bitrate_kbit_s"k \
"$3"

View File

@@ -0,0 +1,108 @@
#!/bin/sh
# title: dmenu_websearch <http://efe.kim/dmenu_websearch.html>
# license: CC0
# author: Sunur Efe Vural <efe@efe.kim>
# version: Mar 22, 2019
# dependencies: dmenu, xdotool, hexdump, xprop, setxkbmap, coreutils.
# A browser-independent address bar with bookmark support. When the
# cursor is on a web browser it acts as the address bar of that browser.
browser='firefox --new-window'
engine='https://duckduckgo.com/?q=%s'
bookmarks="$HOME/.bookmarks"
gotourl() {
if [ "$nbrowser" = surf ]
then
xprop -id "$winid" -f _SURF_GO 8s -set _SURF_GO "$choice"
elif [ -n "$winid" ] && [ -z "$nbrowser" ]
then
#change layout to us cuz xdotool spasms with non-latin layouts
layout=$(setxkbmap -query | awk '/^layout:/{ print $2 }')
setxkbmap -layout us
xdotool key --clearmodifiers "$shortcut"\
type --clearmodifiers --delay 2 "$choice"
xdotool key --clearmodifiers Return
setxkbmap -layout "$layout"
elif [ -n "$nbrowser" ]
then
$nbrowser "$choice"
else $browser "$choice"
fi
}
searchweb() {
#convert search query to percent encoding and insert it into url
choice=$(echo "$choice" | hexdump -v -e '/1 " %02x"')
choice=$(echo "$engine" | sed "s/%s/${choice% 0a}/;s/[[:space:]]/%/g")
gotourl
}
xprop -root | grep '^_NET_ACTIVE_WINDOW' && {
winid=$(xprop -root _NET_ACTIVE_WINDOW | sed 's/.*[[:space:]]//')
class=$(xprop -id "$winid" WM_CLASS | awk -F'\"' '{ print $(NF - 1) }')
case "$class" in
Firefox) nbrowser='firefox' ;;
#Firefox) shortcut='ctrl+l' ;; # alternative method, uses xdotool
IceCat) nbrowser='icecat' ;;
Chromium) nbrowser='chromium' ;;
Chrome) nbrowser='chrome' ;;
Opera) nbrowser='opera' ;;
Vivaldi) nbrowser='vivaldi' ;; # not tested
Brave) nbrowser='brave' ;; # not tested
Conkeror) nbrowser='conkeror' ;; # not tested
Palemoon) nbrowser='palemoon' ;; # not tested
Iceweasel) nbrowser='iceweasel' ;; # not tested
qutebrowser) nbrowser='qutebrowser' ;;
Midori) nbrowser='midori' ;; # not that good
Luakit) nbrowser='luakit' ;; # uses the last window instance
Uzbl|Vimb) shortcut='o' ;;
Links) shortcut='g' ;;
Netsurf*|Epiphany|Dillo|Konqueror|Arora) shortcut='ctrl+l' ;;
Surf) nbrowser='surf' ; uricur=$(xprop -id "$winid" _SURF_URI |\
awk -F'\"' '{ print $( NF - 1 ) }') ;;
*) pid=$(xprop -id "$winid" _NET_WM_PID | awk '{ print $3 }')
while pgrep -oP "$pid" >/dev/null
do
pid=$(pgrep -oP "$pid")
done
pname=$(awk '/^Name\:/{ print $NF }' /proc/"$pid"/status) ||
winid="" ;;
esac
[ -n "$pname" ] && case "$pname" in
w3m) shortcut="U" ;;
lynx|elinks|links) shortcut="g" ;;
*) winid="" ;;
esac
}
tmpfile=$(mktemp /tmp/dmenu_websearch.XXXXXX)
trap 'rm "$tmpfile"' 0 1 15
printf '%s\n%s\n' "$uricur" "$1" > "$tmpfile"
cat "$bookmarks" >> "$tmpfile"
sed -i -E '/^(#|$)/d' "$tmpfile"
choice=$(dmenu -i -p "Go:" -w "$winid" < "$tmpfile") || exit 1
# Detect links without protocol (This is WIP)
protocol='^(https?|ftps?|mailto|about|file):///?'
checkurl() {
grep -Fx "$choice" "$tmpfile" &&
choice=$(echo "$choice" | awk '{ print $1 }') && return 0
[ ${#choice} -lt 4 ] && return 1
echo "$choice" | grep -Z ' ' && return 1
echo "$choice" | grep -EiZ "$protocol" && return 0
echo "$choice" | grep -FZ '..' && return 1
prepath=$(echo "$choice" | sed 's/(\/|#|\?).*//')
echo "$prepath" | grep -FvZ '.' && return 1
echo "$prepath" | grep -EZ '^([[:alnum:]~_:-]+\.?){1,3}' && return 0
}
if checkurl
then
echo "$choice" | grep -EivZ "$protocol" &&
choice="http://$choice"
gotourl
else searchweb
fi

View File

@@ -0,0 +1,4 @@
#!/usr/bin/env bash
su $USERNAME -l -c "google-drive-ocamlfuse -label $1 $*"
exit 0

View File

@@ -0,0 +1,4 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg
for x in *$1;do echo $(ffprobe -loglevel error -show_entries format_tags=track -of default=noprint_wrappers=1:nokey=1 "$x") - $(ffprobe -loglevel error -show_entries format_tags=TITLE -of default=noprint_wrappers=1:nokey=1 "$x"); done

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env sh
#credits: https://github.com/alnj/ncmpcpp-ueberzug
export FIFO_UEBERZUG="/tmp/mpd-ueberzug-${PPID}"
cleanup() {
rm "$FIFO_UEBERZUG" 2>/dev/null
rm /tmp/mpd_cover.jpg 2>/dev/null
pkill -P $$ 2>/dev/null
pkill ncmpcpp_cover_art.sh
}
pkill -P $$ 2>/dev/null
rm "$FIFO_UEBERZUG" 2>/dev/null
mkfifo "$FIFO_UEBERZUG" >/dev/null
trap cleanup EXIT 2>/dev/null
tail --follow "$FIFO_UEBERZUG" | ueberzug layer --silent --parser simple >/dev/null 2>&1 &
ncmpcpp
cleanup

View File

@@ -0,0 +1,11 @@
#!/usr/bin/env bash
if [ $# != 2 ]; then
echo "Two args required"
exit 1
fi
if [ $1 == "on" ]; then
xinput --set-prop $2 'libinput Accel Profile Enabled' 0, 1
else
xinput --set-prop $2 'libinput Accel Profile Enabled' 1, 0
fi

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env bash
for x in "$@"; do
curl -F "file=@\"$x\"" -F "key=$FILEHOST_KEY" $FILEHOST_URL
printf "\n"
done

View File

@@ -0,0 +1,6 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p curl
for x in "$@"; do
curl -F "file=@\"$x\"" https://x0.at/
echo " "
done

View File

@@ -0,0 +1,9 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash -p ffmpeg yt-dlp
yt-dlp -f bestaudio -o "ytmp3.%(title)s.%(ext)s" "$1"
file=$(echo ytmp3.*.*)
newfile=$(echo $file | cut -c 7-)
mv "$file" "$newfile"
ffmpeg -i "$newfile" -c:a mp3 "${newfile%.*}.mp3"
rm "$newfile"
#trust me ive a reason for lossy->lossy transcoding

14
pkgs/default.nix Normal file
View File

@@ -0,0 +1,14 @@
{ self, ... }: {
systems = [ "x86_64-linux" ];
flake = {
overlays = rec {
packages = import ./packages.nix;
default = packages;
};
};
perSystem = { pkgs, ... }: {
packages = self.overlays.default null pkgs;
};
}

8
pkgs/packages.nix Normal file
View File

@@ -0,0 +1,8 @@
final: prev:
let
call = prev.callPackage; in
{
customscripts = call ./customscripts { };
tlauncher = call ./tlauncher { };
simp1e-cursors = call ./simp1e { };
}

39
pkgs/simp1e/default.nix Normal file
View File

@@ -0,0 +1,39 @@
{ lib, stdenvNoCC, fetchFromGitLab, python3, librsvg, xcursorgen }:
stdenvNoCC.mkDerivation rec {
pname = "simp1e-cursors";
version = "20221103.2";
src = fetchFromGitLab {
owner = "cursors";
repo = "simp1e";
rev = version;
sha256 = "sha256-3DCF6TwxWwYK5pF2Ykr3OwF76H7J03vLNZch/XoZZZk=";
fetchSubmodules = true;
};
nativeBuildInputs = [
(python3.withPackages (ps: with ps; [ pillow ]))
librsvg
xcursorgen
];
buildPhase = ''
patchShebangs .
HOME=$TMP ./build.sh
'';
installPhase = ''
install -dm 755 $out/share/icons
cp -dr --no-preserve='ownership' built_themes/* $out/share/icons/
'';
meta = with lib; {
description = "An aesthetic cursor theme for Linux desktops";
homepage = "https://gitlab.com/cursors/simp1e";
license = licenses.gpl3;
platforms = platforms.all;
maintainers = with maintainers; [ natto1784 ];
};
}

View File

@@ -0,0 +1,72 @@
{ stdenv
, openjdk8
, buildFHSUserEnv
, fetchzip
}:
let
version = "2.86";
jar = stdenv.mkDerivation {
pname = "tlauncher-jar";
inherit version;
src = fetchzip {
name = "tlauncher.zip";
url = "https://dl2.tlauncher.org/f.php?f=files%2FTLauncher-${version}.zip";
sha256 = "sha256-Tpia/GtPfeO8/Tca0fE7z387FRpkXfS1CtvX/oNJDag=";
stripRoot = false;
};
installPhase = ''
cp $src/*.jar $out
'';
};
fhs = buildFHSUserEnv {
name = "tlauncher";
runScript = ''
${openjdk8}/bin/java -jar "${jar}" "$@"
'';
targetPkgs = pkgs: with pkgs; [
zip
zlib
alsa-lib
cpio
cups
file
fontconfig
freetype
giflib
glib
gnome2.GConf
gnome2.gnome_vfs
gtk2
libjpeg
libGL
openjdk8-bootstrap
perl
which
] ++
(with xorg; [
libICE
libX11
libXcursor
libXext
libXi
libXinerama
libXrandr
xrandr
libXrender
libXt
libXtst
libXtst
libXxf86vm
]);
};
in
stdenv.mkDerivation rec {
pname = "tlauncher";
inherit version;
dontUnpack = true;
installPhase = ''
mkdir $out/{bin,share/applications} -p
install ${fhs}/bin/tlauncher $out/bin
'';
}