Skip to content

Commit

Permalink
feat: make proper rbw-atomic-unlock (#1006)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnae authored Nov 24, 2024
1 parent a015f16 commit 994d6e8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
stty sane
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.4/direnvrc" "sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4="

rbw unlocked || rbw unlock
rbw-atomic-unlock

watch_file devenv.nix
watch_file flake.nix
Expand Down
21 changes: 6 additions & 15 deletions flake/helper-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
rbw
rofi-wayland
skim
util-linux
wpa_supplicant
;

Expand Down Expand Up @@ -47,22 +48,12 @@

rbw-atomic-unlock = writeShellApplication {
name = "rbw-atomic-unlock";
runtimeInputs = [rbw];
runtimeInputs = [rbw util-linux];
text = ''
rbw_lock=/tmp/lock.rbw.lock
rbw_pid_lock="/tmp/lock.$$.tmp"
trap 'rm -f $rbw_lock $rbw_pid_lock' EXIT
if ! rbw unlocked 2>/dev/null; then
touch "$rbw_pid_lock"
if ln "$rbw_pid_lock" "$rbw_lock" 2>/dev/null; then
rbw unlock
rm -f "$rbw_lock"
else
while ! rbw unlocked 2>/dev/null; do
sleep 0.2
done
fi
fi
rbw_lock="/tmp/rbw-unlock.lock"
exec 200>"$rbw_lock"
flock -w 15 200
rbw unlocked || rbw unlock
'';
};

Expand Down

0 comments on commit 994d6e8

Please sign in to comment.