From 8c4228dcba972d70be643ab44e9b26367221ffc3 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 11 May 2021 10:40:46 +0200 Subject: [PATCH] chore(nix): killall-uni2work --- shell.nix | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/shell.nix b/shell.nix index f4bf32107..dfe47c7a0 100644 --- a/shell.nix +++ b/shell.nix @@ -192,8 +192,42 @@ let echo "In develop" fi ''; + + killallUni2work = pkgs.writeScriptBin "killall-uni2work" '' + #!${pkgs.zsh}/bin/zsh + + set -o pipefail + + lockFile= + + if [[ ''${#@} -gt 0 ]]; then + lockFile=''${1} + shift + + if [[ -d ''${lockFile} && -f ''${lockFile}/.stack-work.lock ]]; then + lockFile=''${lockFile}/.stack-work.lock + fi + else + if [[ -f .stack-work.lock ]]; then + lockFile=.stack-work.lock + elif [[ -f ~/projects/uni2work/.stack-work.lock ]]; then + lockFile=~/projects/uni2work/.stack-work.lock + fi + fi + + if [[ -z "''${lockFile}" && !(-f ''${lockFile}) ]]; then + echo "Could not find lockfile" >&2 + exit 1 + fi + + printf "Killing users of %s...\n" ''${lockFile} + + while ${pkgs.psmisc}/bin/fuser ''${lockFile} 2>/dev/null | ${pkgs.coreutils}/bin/cut -d ':' -f 2- | ${pkgs.findutils}/bin/xargs -tr -- ${pkgs.util-linux}/bin/kill; do + sleep 1 + done + ''; in pkgs.mkShell { name = "uni2work"; - nativeBuildInputs = [develop inDevelop] ++ (with pkgs; [ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client gup ]) ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder profiteur ]); + nativeBuildInputs = [develop inDevelop killallUni2work] ++ (with pkgs; [ nodejs-14_x postgresql_12 openldap google-chrome exiftool memcached minio minio-client gup ]) ++ (with pkgs.haskellPackages; [ stack yesod-bin hlint cabal-install weeder profiteur ]); }