nix-config/modules/home-manager/cli/scripts/mounter.nix
Oliver Davies dfebe131a6 Move scripts to Nix files
Move the scripts I commonly use into Nix files managed by Home Manager.

Some, like `mounter` and `unmounter` are desktop-only, but this can be
addressed in a future commit to create per-host scripts or
desktop/non-desktop scripts.

This commit also removes a number of unused scripts that are either
included in packages like `git-extras` or aren't used.
2025-07-10 16:33:43 +01:00

45 lines
1.2 KiB
Nix
Executable file

{ pkgs }:
pkgs.writeShellApplication {
name = "mounter";
runtimeInputs = with pkgs; [
cryptsetup
dmenu
gawk
libnotify
util-linux
];
text = ''
lsblk_output="$(lsblk -rpo "uuid,name,type,size,label,mountpoint,mountpoints,fstype" | grep "part" | grep -Ev "/(boot|nix/store)")"
partition_names="$(echo "$lsblk_output" | awk '{ printf "%s (%s)\n", $2, $4 }' )";
selected=$(echo "$partition_names" | dmenu -p "Select drive:" | awk '{ print $1 }')
test -n "$selected"
mount_device="$selected"
if sudo cryptsetup isLuks "$selected"; then
luks_name="usb"
${"TERMINAL:-st"} -n floatterm -g 60x1 -e sudo cryptsetup open "$selected" "$luks_name"
mount_device="/dev/mapper/$luks_name"
test -b "/dev/mapper/$luks_name"
fi
mount_point=$(echo -e "/mnt\n/media\n/run/media/$USER" | dmenu -p "Select mount point:")
test -n "$mount_point"
sudo mkdir -p "$mount_point"
if sudo mount "$mount_device" "$mount_point"; then
notify-send "Device mounted" "Mounted $selected at $mount_point."
else
notify-send "Mount failed" "Failed to mount $selected."
exit 1
fi
'';
}