Move Nix files into a nix directory

Move everything from `config` to the root level.
This commit is contained in:
Oliver Davies 2024-11-20 21:37:15 +00:00
parent 9f47df62b5
commit 69a397e624
124 changed files with 14 additions and 14 deletions

View file

@ -0,0 +1,13 @@
{
name = "_timer";
runtimeInputs = [ ];
text = ''
mins=$1
message=''${2:-Time out!}
sleep -- "$mins" * 60
notify-send -t 0 "''${message}" "Your timer of $mins min is over" -u normal
'';
}

View file

@ -0,0 +1,65 @@
{ pkgs }:
{
name = "create-zellij-session";
runtimeInputs = with pkgs; [
openssl
zellij
];
text = ''
function _execute_zellij_layout {
local session_name="$1"
local layout_file="$2"
DIGEST="$(openssl sha512 "$layout_file")"
# Prompt the first time we see a given layout file before running it.
if ! grep -q "$DIGEST" ~/..zellij.digests 2> /dev/null; then
cat "$layout_file"
read -r -n 1 -p "Trust (and run) this Zellij file? (t = trust, otherwise = skip) "
if [[ $REPLY =~ ^[Tt]$ ]]; then
echo "$DIGEST" >> ~/..zellij.digests
_attach_to_or_create_zellij_session --layout "$layout_file"
fi
else
_attach_to_or_create_zellij_session --layout "$layout_file"
fi
}
function _attach_to_or_create_zellij_session {
zellij attach "$session_name" 2>/dev/null || zellij --session "$session_name" "$@"
}
function main {
if [[ $# -eq 1 ]]; then
selected_path=$1
else
selected_path=$(find "$REPOS" "$REPOS/tfw" "$HOME/Documents" -maxdepth 1 -mindepth 1 -type d \
! -name "*-old" \
! -name "*.bak" \
! -name "*.old" \
! -name "_archive" \
| sort \
| fzf --reverse)
fi
session_name=$(basename "$selected_path")
cd "$selected_path"
if [[ -f ".ignored/dev.kdl" ]]; then
_execute_zellij_layout "$session_name" ".ignored/dev.kdl"
elif [[ -f "dev.kdl" ]]; then
_execute_zellij_layout "$session_name" "dev.kdl"
fi
_attach_to_or_create_zellij_session
}
main "$@"
'';
}

View file

@ -0,0 +1,25 @@
{ pkgs }:
{
name = "deliver";
runtimeInputs = with pkgs; [ docker ];
text = ''
set +o pipefail
# Based on https://github.com/jessarcher/dotfiles/blob/ef692c35d64db2c13674dfc850a23b6acf9e8f91/scripts/deliver.
docker_compose_service_name=$(docker compose ps --services 2>/dev/null | grep '^app\|php$' | head -n1)
if [[ "$docker_compose_service_name" != "" ]]; then
if [ -t 1 ]; then
"${pkgs.docker}/bin/docker" compose exec "$docker_compose_service_name" "$@"
else
# The command is not being run in a TTY
"${pkgs.docker}/bin/docker" compose exec -T "$docker_compose_service_name" "$@"
fi
else
"$@"
fi
'';
}

View file

@ -0,0 +1,33 @@
{ pkgs, username, ... }:
{
name = "export-video-list";
runtimeInputs = with pkgs; [
jq
tree
udisks
];
text = ''
device_name="/dev/sda2"
device_label="UNTITLED"
source_path="/run/media/${username}/$device_label"
# If the source path doesn't exist, try mounting the device.
if [[ ! -d "$source_path" ]]; then
${pkgs.udisks}/bin/udisksctl mount -b "$device_name"
fi
# Exit early if the source path still doesn't exist.
if [[ ! -d "$source_path" ]]; then
echo "Error: $source_path not found."
exit 1
fi
output_file="$HOME/Documents/videos.json"
${pkgs.tree}/bin/tree -J "$source_path/Videos" | ${pkgs.jq}/bin/jq . > "$output_file"
${pkgs.jq}/bin/jq . < "$output_file"
'';
}

View file

@ -0,0 +1,16 @@
{ pkgs }:
{
name = "run";
runtimeInputs = with pkgs; [ bashInteractive ];
text = ''
if [[ -e .ignored/run ]]; then
.ignored/run "$@"
exit $?
fi
./run "$@"
'';
}

View file

@ -0,0 +1,38 @@
{ pkgs }:
{
name = "t";
runtimeInputs = with pkgs; [
openssl
tmux
];
text = ''
# Based on similar scripts by ThePrimeagen and Jess Archer.
if [[ $# -eq 1 ]]; then
selected_path=$1
else
# Get the session name from fuzzy-finding list of directories and generating a
# tmux-safe version.
items=$(find "$REPOS" ~/Documents \
-maxdepth 1 -mindepth 1 -type d \
! -name "_archive" \
! -name "*-old" \
! -name "*.old"
)
selected_path=$(echo "''${items}" | sort | fzf --reverse)
fi
session_name=$(basename "$selected_path" | sed 's/\./_/g')
if tmux switch-client -t="$session_name" 2>/dev/null; then
exit 0
fi
( (tmux new-session -c "$selected_path" -d -s "$session_name" && tmux switch-client -t "$session_name") 2>/dev/null ) ||
tmux new-session -c "$selected_path" -A -s "$session_name"
'';
}

View file

@ -0,0 +1,20 @@
{
name = "timer";
runtimeInputs = [ ];
text = ''
if [[ "$1" == "" ]]; then
echo "Usage: ''${0##*/} <mins> [message]"
exit 1
fi
mins=$1
message=$2
nohup _timer "$mins" "$message" &> /dev/null &
echo "timer started for $mins min"
echo "timer started for $mins min, message: '$message'" | systemd-cat -t timer
'';
}