Compare commits

..

No commits in common. "6772fdbc2c7f51642579e21bee8cb6bc1c21dc0a" and "bd0f546401a1634964c76a9f9827c7aae6947d48" have entirely different histories.

5 changed files with 27 additions and 64 deletions

View file

@ -1,13 +1,10 @@
# Nix Background Upgrade # Nix Background Upgrade
Upgrade NixOS system (and/or home-manager) in the background, with Upgrade NixOS system (and/or home-manager) in the background, with notification support.
notification support.
**Early stages of development, subject to change and likely not **Early stages of development, subject to change and likely not working at the current stage.**
working at the current stage.**
## Install ## Install
Clone the repository and install with pip (or preferred Python Clone the repository and install with pip (or preferred Python packaging system):
packaging system):
```bash ```bash
git clone https://git.xenia.me.uk/pixelifytica/nix-background-upgrade.git git clone https://git.xenia.me.uk/pixelifytica/nix-background-upgrade.git
@ -15,12 +12,9 @@ python3 -m pip install ./nix-background-upgrade
``` ```
### For development ### For development
Project uses [Poetry](https://python-poetry.org/ "Poetry: Python Project uses [Poetry](https://python-poetry.org/ "Poetry: Python packaging and dependency management tool") to manage dependencies.
packaging and dependency management tool") to manage dependencies.
Install Poetry (see Install Poetry (see [documentation](https://python-poetry.org/docs/#installation) for more details), for example using `pipx`:
[documentation](https://python-poetry.org/docs/#installation) for more
details), for example using `pipx`:
```bash ```bash
pipx install poetry pipx install poetry
@ -32,23 +26,14 @@ Then install project using `poetry`:
poetry install poetry install
``` ```
Python code is formatted using [black](https://pypi.org/project/black/ Python code is formatted using [black](https://pypi.org/project/black/ "The uncompromising code formatter") and [isort](https://pypi.org/project/isort/ "A Python utility / library to sort Python imports").
"The uncompromising code formatter") and
[isort](https://pypi.org/project/isort/ "A Python utility / library to
sort Python imports").
#### `pre-commit` #### `pre-commit`
[pre-commit](https://pre-commit.com/ "A framework for managing and [pre-commit](https://pre-commit.com/ "A framework for managing and maintaining multi-language pre-commit hooks") is used to ensure formatting of new/changed files. Install pre-commit hooks with:
maintaining multi-language pre-commit hooks") is used to ensure
formatting of new/changed files. Install pre-commit hooks with:
```bash ```bash
pre-commit install --install-hooks pre-commit install --install-hooks
``` ```
### Nix Flake ### Nix Flake
Project provides a Nix `flake.nix` and `shell.nix` to get up and Project provides a Nix `flake.nix` to get up and running quickly.
running quickly.
Run `nix develop` (Flake) or `nix-shell` (non-Flake) to enter
development shell containing project dependencies.

View file

@ -29,10 +29,18 @@
}; };
}); });
devShells = forAllSystems (system: { devShells = forAllSystems (system: let
default = import ./shell.nix { inherit (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}) mkPoetryEnv;
pkgs = pkgs.${system}; in {
inherit (poetry2nix.lib.mkPoetry2Nix {pkgs = pkgs.${system};}) mkPoetryEnv; default = pkgs.${system}.mkShellNoCC {
packages = with pkgs.${system}; [
(mkPoetryEnv {
projectDir = self;
preferWheels = true;
extraPackages = ps: with ps; [python-lsp-server];
})
poetry
];
}; };
}); });
}; };

View file

@ -1,15 +0,0 @@
{
pkgs ? import <nixpkgs> {},
mkPoetryEnv ? ((builtins.getFlake "github:nix-community/poetry2nix").lib.mkPoetry2Nix {inherit pkgs;}).mkPoetryEnv,
}:
pkgs.mkShellNoCC {
packages = with pkgs; [
(mkPoetryEnv {
projectDir = ./.;
preferWheels = true;
editablePackageSources = {nix_background_upgrade = ./src;};
extraPackages = ps: with ps; [python-lsp-server];
})
poetry
];
}

View file

@ -3,23 +3,13 @@ Control upgrading NixOS configuration
""" """
import subprocess import subprocess
from os import getenv
from .notification import create_notification
NIXOS_CONFIGURATION: str = getenv("NIXOS_CONFIGURATION", "")
def nixos_switch() -> int: def nixos_switch() -> None:
""" """
Switch NixOS system to new version Switch NixOS system to new version
:returns: Error code of `sudo nixos-rebuild switch` call :returns: None
""" """
notification = create_notification(source="nixos_switch") subprocess.Popen("which -a nixos-rebuild".split())
try: return
subprocess.run("which -a nixos-rebuild".split()).check_returncode()
except subprocess.CalledProcessError as e:
notification.message = e
notification.send()
return 0

View file

@ -1,21 +1,16 @@
from pathlib import Path from pathlib import Path
from typing import Optional
from notifypy import Notify from notifypy import Notify
def create_notification(source: Optional[str] = None) -> Notify: def create_notification() -> Notify:
""" """
Create notification class Create notification class
:param source: Name of originating file or function, used in default notification
title
:returns: Notify class with custom defaults :returns: Notify class with custom defaults
""" """
if source is None:
source = "Nix process"
return Notify( return Notify(
default_notification_title="Message from {}".format(source), default_notification_title="Nix Background Update",
default_notification_message="Message from Nix process",
default_notification_icon=Path(__file__).parent / "./nix-snowflake.png", default_notification_icon=Path(__file__).parent / "./nix-snowflake.png",
) )