use script-dependencies.nix
as a nix shell environment instead of specifying dependencies in shebangs of each individual script file
This commit is contained in:
parent
d82fe7048a
commit
ef297345e1
4 changed files with 22 additions and 7 deletions
15
nixos/script-dependencies.nix
Normal file
15
nixos/script-dependencies.nix
Normal file
|
@ -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
|
||||
];
|
||||
}
|
|
@ -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.")
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue