From ef297345e1d3f147911fdcdd9fb9232dde8e8945 Mon Sep 17 00:00:00 2001 From: cswimr Date: Mon, 25 Nov 2024 14:21:02 -0500 Subject: [PATCH] use `script-dependencies.nix` as a nix shell environment instead of specifying dependencies in shebangs of each individual script file --- nixos/script-dependencies.nix | 15 +++++++++++++++ scripts/common/common.py | 6 +++--- scripts/spectacle-screenshot.py | 4 ++-- scripts/zipline.py | 4 ++-- 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 nixos/script-dependencies.nix diff --git a/nixos/script-dependencies.nix b/nixos/script-dependencies.nix new file mode 100644 index 0000000..75a54cd --- /dev/null +++ b/nixos/script-dependencies.nix @@ -0,0 +1,15 @@ +let + nixpkgs = fetchTarball + "https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"; + pkgs = import nixpkgs { + config = { }; + overlays = [ ]; + }; +in pkgs.mkShellNoCC { + packages = with pkgs; [ + libnotify + python312 + python312Packages.requests + python312Packages.pyperclip + ]; +} diff --git a/scripts/common/common.py b/scripts/common/common.py index 8dfc1be..84906d7 100644 --- a/scripts/common/common.py +++ b/scripts/common/common.py @@ -30,10 +30,10 @@ def notify( def read_secret_file(secret: str) -> str: - path = f"/run/secrets/{secret}" + path = f"/var/secrets/{secret}" if not os.path.exists(path): - raise FileNotFoundError(f"Secret file {path} does not exist.") - with open(f"/run/secrets/{secret}", "r") as f: + raise FileNotFoundError(f"Secret file {path} does not exist or cannot be read.") + with open(f"/var/secrets/{secret}", "r") as f: secret = f.read().strip() if not secret: raise ValueError(f"Secret file {path} is empty.") diff --git a/scripts/spectacle-screenshot.py b/scripts/spectacle-screenshot.py index 9eacd5f..2a08cad 100755 --- a/scripts/spectacle-screenshot.py +++ b/scripts/spectacle-screenshot.py @@ -1,5 +1,5 @@ #! /usr/bin/env nix-shell -#! nix-shell -i python -p python312 libnotify +#! nix-shell /etc/nixos/nixos/script-dependencies.nix -i python import argparse import os @@ -73,7 +73,7 @@ def spectacle_screenshot( finally: if Path(file_path).exists() and use_temp_file: os.remove(file_path) - except Exception as e: + except BaseException as e: notify( application_name="Spectacle", title="An error occurred", diff --git a/scripts/zipline.py b/scripts/zipline.py index 92ffece..8d1e214 100755 --- a/scripts/zipline.py +++ b/scripts/zipline.py @@ -1,5 +1,5 @@ #! /usr/bin/env nix-shell -#! nix-shell -i python -p python312 python312Packages.pyperclip python312Packages.requests libnotify +#! nix-shell /etc/nixos/nixos/script-dependencies.nix -i python import argparse import mimetypes @@ -66,7 +66,7 @@ def zipline( error_message = response.text raise Exception(error_message) - except Exception as e: + except BaseException as e: if use_notify_send: notify( application_name=application_name,