Check for nixos-rebuild command triggers notification if not found
Add source argument to default notification title
This commit is contained in:
parent
0396bdb66a
commit
6772fdbc2c
|
@ -3,13 +3,23 @@ Control upgrading NixOS configuration
|
|||
"""
|
||||
|
||||
import subprocess
|
||||
from os import getenv
|
||||
|
||||
from .notification import create_notification
|
||||
|
||||
NIXOS_CONFIGURATION: str = getenv("NIXOS_CONFIGURATION", "")
|
||||
|
||||
|
||||
def nixos_switch() -> None:
|
||||
def nixos_switch() -> int:
|
||||
"""
|
||||
Switch NixOS system to new version
|
||||
|
||||
:returns: None
|
||||
:returns: Error code of `sudo nixos-rebuild switch` call
|
||||
"""
|
||||
subprocess.Popen("which -a nixos-rebuild".split())
|
||||
return
|
||||
notification = create_notification(source="nixos_switch")
|
||||
try:
|
||||
subprocess.run("which -a nixos-rebuild".split()).check_returncode()
|
||||
except subprocess.CalledProcessError as e:
|
||||
notification.message = e
|
||||
notification.send()
|
||||
return 0
|
||||
|
|
|
@ -1,16 +1,21 @@
|
|||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
from notifypy import Notify
|
||||
|
||||
|
||||
def create_notification() -> Notify:
|
||||
def create_notification(source: Optional[str] = None) -> Notify:
|
||||
"""
|
||||
Create notification class
|
||||
|
||||
:param source: Name of originating file or function, used in default notification
|
||||
title
|
||||
|
||||
:returns: Notify class with custom defaults
|
||||
"""
|
||||
if source is None:
|
||||
source = "Nix process"
|
||||
return Notify(
|
||||
default_notification_title="Nix Background Update",
|
||||
default_notification_message="Message from Nix process",
|
||||
default_notification_title="Message from {}".format(source),
|
||||
default_notification_icon=Path(__file__).parent / "./nix-snowflake.png",
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue