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:
|
def read_secret_file(secret: str) -> str:
|
||||||
path = f"/run/secrets/{secret}"
|
path = f"/var/secrets/{secret}"
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise FileNotFoundError(f"Secret file {path} does not exist.")
|
raise FileNotFoundError(f"Secret file {path} does not exist or cannot be read.")
|
||||||
with open(f"/run/secrets/{secret}", "r") as f:
|
with open(f"/var/secrets/{secret}", "r") as f:
|
||||||
secret = f.read().strip()
|
secret = f.read().strip()
|
||||||
if not secret:
|
if not secret:
|
||||||
raise ValueError(f"Secret file {path} is empty.")
|
raise ValueError(f"Secret file {path} is empty.")
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#! /usr/bin/env nix-shell
|
#! /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 argparse
|
||||||
import os
|
import os
|
||||||
|
@ -73,7 +73,7 @@ def spectacle_screenshot(
|
||||||
finally:
|
finally:
|
||||||
if Path(file_path).exists() and use_temp_file:
|
if Path(file_path).exists() and use_temp_file:
|
||||||
os.remove(file_path)
|
os.remove(file_path)
|
||||||
except Exception as e:
|
except BaseException as e:
|
||||||
notify(
|
notify(
|
||||||
application_name="Spectacle",
|
application_name="Spectacle",
|
||||||
title="An error occurred",
|
title="An error occurred",
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#! /usr/bin/env nix-shell
|
#! /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 argparse
|
||||||
import mimetypes
|
import mimetypes
|
||||||
|
@ -66,7 +66,7 @@ def zipline(
|
||||||
error_message = response.text
|
error_message = response.text
|
||||||
raise Exception(error_message)
|
raise Exception(error_message)
|
||||||
|
|
||||||
except Exception as e:
|
except BaseException as e:
|
||||||
if use_notify_send:
|
if use_notify_send:
|
||||||
notify(
|
notify(
|
||||||
application_name=application_name,
|
application_name=application_name,
|
||||||
|
|
Loading…
Reference in a new issue