Loading pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py +7 −5 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ from typing import Final, assert_never from . import nix, tmpdir from .constants import EXECUTABLE, WITH_NIX_2_18, WITH_REEXEC, WITH_SHELL_FILES from .models import Action, BuildAttr, Flake, ImageVariants, NRError, Profile from .models import Action, BuildAttr, Flake, ImageVariants, NixOSRebuildError, Profile from .process import Remote, cleanup_ssh from .utils import Args, LogFormatter, tabulate Loading Loading @@ -332,7 +332,7 @@ def reexec( def validate_image_variant(image_variant: str, variants: ImageVariants) -> None: if image_variant not in variants: raise NRError( raise NixOSRebuildError( "please specify one of the following supported image variants via " "--image-variant:\n" + "\n".join(f"- {v}" for v in variants) ) Loading @@ -358,7 +358,7 @@ def validate_nixos_config(path_to_config: Path) -> None: Please open an issue if this is the case. """ ).strip() raise NRError(msg) raise NixOSRebuildError(msg) def execute(argv: list[str]) -> None: Loading Loading @@ -459,9 +459,11 @@ def execute(argv: list[str]) -> None: if maybe_path_to_config: # kinda silly but this makes mypy happy path_to_config = maybe_path_to_config else: raise NRError("could not find previous generation") raise NixOSRebuildError("could not find previous generation") case (_, True, _, _): raise NRError(f"--rollback is incompatible with '{action}'") raise NixOSRebuildError( f"--rollback is incompatible with '{action}'" ) case (_, False, Remote(_), Flake(_)): path_to_config = nix.build_remote_flake( attr, Loading pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ from .process import Remote, run_wrapper type ImageVariants = list[str] class NRError(Exception): class NixOSRebuildError(Exception): "nixos-rebuild general error." def __init__(self, message: str) -> None: Loading pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py +7 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ from .models import ( Generation, GenerationJson, ImageVariants, NRError, NixOSRebuildError, Profile, Remote, ) Loading Loading @@ -256,7 +256,7 @@ def edit(flake: Flake | None, flake_flags: Args | None = None) -> None: ) else: if flake_flags: raise NRError("'edit' does not support extra Nix flags") raise NixOSRebuildError("'edit' does not support extra Nix flags") nixos_config = Path( os.getenv("NIXOS_CONFIG") or find_file("nixos-config") or "/etc/nixos" ) Loading @@ -266,7 +266,7 @@ def edit(flake: Flake | None, flake_flags: Args | None = None) -> None: if nixos_config.exists(): run_wrapper([os.getenv("EDITOR", "nano"), nixos_config], check=False) else: raise NRError("cannot find NixOS config file") raise NixOSRebuildError("cannot find NixOS config file") def find_file(file: str, nix_flags: Args | None = None) -> Path | None: Loading Loading @@ -424,7 +424,7 @@ def get_generations(profile: Profile) -> list[Generation]: and if this is the current active profile or not. """ if not profile.path.exists(): raise NRError(f"no profile '{profile.name}' found") raise NixOSRebuildError(f"no profile '{profile.name}' found") def parse_path(path: Path, profile: Profile) -> Generation: entry_id = path.name.split("-")[1] Loading Loading @@ -456,7 +456,7 @@ def get_generations_from_nix_env( and if this is the current active profile or not. """ if not profile.path.exists(): raise NRError(f"no profile '{profile.name}' found") raise NixOSRebuildError(f"no profile '{profile.name}' found") # Using `nix-env --list-generations` needs root to lock the profile r = run_wrapper( Loading Loading @@ -635,13 +635,13 @@ def switch_to_configuration( """ if specialisation: if action not in (Action.SWITCH, Action.TEST): raise NRError( raise NixOSRebuildError( "'--specialisation' can only be used with 'switch' and 'test'" ) path_to_config = path_to_config / f"specialisation/{specialisation}" if not path_to_config.exists(): raise NRError(f"specialisation not found: {specialisation}") raise NixOSRebuildError(f"specialisation not found: {specialisation}") r = run_wrapper( ["test", "-d", "/run/systemd/system"], Loading pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py +1 −1 Original line number Diff line number Diff line Loading @@ -714,7 +714,7 @@ def test_switch_to_configuration_without_systemd_run( remote=None, ) with pytest.raises(m.NRError) as e: with pytest.raises(m.NixOSRebuildError) as e: n.switch_to_configuration( config_path, m.Action.BOOT, Loading Loading
pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/__init__.py +7 −5 Original line number Diff line number Diff line Loading @@ -10,7 +10,7 @@ from typing import Final, assert_never from . import nix, tmpdir from .constants import EXECUTABLE, WITH_NIX_2_18, WITH_REEXEC, WITH_SHELL_FILES from .models import Action, BuildAttr, Flake, ImageVariants, NRError, Profile from .models import Action, BuildAttr, Flake, ImageVariants, NixOSRebuildError, Profile from .process import Remote, cleanup_ssh from .utils import Args, LogFormatter, tabulate Loading Loading @@ -332,7 +332,7 @@ def reexec( def validate_image_variant(image_variant: str, variants: ImageVariants) -> None: if image_variant not in variants: raise NRError( raise NixOSRebuildError( "please specify one of the following supported image variants via " "--image-variant:\n" + "\n".join(f"- {v}" for v in variants) ) Loading @@ -358,7 +358,7 @@ def validate_nixos_config(path_to_config: Path) -> None: Please open an issue if this is the case. """ ).strip() raise NRError(msg) raise NixOSRebuildError(msg) def execute(argv: list[str]) -> None: Loading Loading @@ -459,9 +459,11 @@ def execute(argv: list[str]) -> None: if maybe_path_to_config: # kinda silly but this makes mypy happy path_to_config = maybe_path_to_config else: raise NRError("could not find previous generation") raise NixOSRebuildError("could not find previous generation") case (_, True, _, _): raise NRError(f"--rollback is incompatible with '{action}'") raise NixOSRebuildError( f"--rollback is incompatible with '{action}'" ) case (_, False, Remote(_), Flake(_)): path_to_config = nix.build_remote_flake( attr, Loading
pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/models.py +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ from .process import Remote, run_wrapper type ImageVariants = list[str] class NRError(Exception): class NixOSRebuildError(Exception): "nixos-rebuild general error." def __init__(self, message: str) -> None: Loading
pkgs/by-name/ni/nixos-rebuild-ng/src/nixos_rebuild/nix.py +7 −7 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ from .models import ( Generation, GenerationJson, ImageVariants, NRError, NixOSRebuildError, Profile, Remote, ) Loading Loading @@ -256,7 +256,7 @@ def edit(flake: Flake | None, flake_flags: Args | None = None) -> None: ) else: if flake_flags: raise NRError("'edit' does not support extra Nix flags") raise NixOSRebuildError("'edit' does not support extra Nix flags") nixos_config = Path( os.getenv("NIXOS_CONFIG") or find_file("nixos-config") or "/etc/nixos" ) Loading @@ -266,7 +266,7 @@ def edit(flake: Flake | None, flake_flags: Args | None = None) -> None: if nixos_config.exists(): run_wrapper([os.getenv("EDITOR", "nano"), nixos_config], check=False) else: raise NRError("cannot find NixOS config file") raise NixOSRebuildError("cannot find NixOS config file") def find_file(file: str, nix_flags: Args | None = None) -> Path | None: Loading Loading @@ -424,7 +424,7 @@ def get_generations(profile: Profile) -> list[Generation]: and if this is the current active profile or not. """ if not profile.path.exists(): raise NRError(f"no profile '{profile.name}' found") raise NixOSRebuildError(f"no profile '{profile.name}' found") def parse_path(path: Path, profile: Profile) -> Generation: entry_id = path.name.split("-")[1] Loading Loading @@ -456,7 +456,7 @@ def get_generations_from_nix_env( and if this is the current active profile or not. """ if not profile.path.exists(): raise NRError(f"no profile '{profile.name}' found") raise NixOSRebuildError(f"no profile '{profile.name}' found") # Using `nix-env --list-generations` needs root to lock the profile r = run_wrapper( Loading Loading @@ -635,13 +635,13 @@ def switch_to_configuration( """ if specialisation: if action not in (Action.SWITCH, Action.TEST): raise NRError( raise NixOSRebuildError( "'--specialisation' can only be used with 'switch' and 'test'" ) path_to_config = path_to_config / f"specialisation/{specialisation}" if not path_to_config.exists(): raise NRError(f"specialisation not found: {specialisation}") raise NixOSRebuildError(f"specialisation not found: {specialisation}") r = run_wrapper( ["test", "-d", "/run/systemd/system"], Loading
pkgs/by-name/ni/nixos-rebuild-ng/src/tests/test_nix.py +1 −1 Original line number Diff line number Diff line Loading @@ -714,7 +714,7 @@ def test_switch_to_configuration_without_systemd_run( remote=None, ) with pytest.raises(m.NRError) as e: with pytest.raises(m.NixOSRebuildError) as e: n.switch_to_configuration( config_path, m.Action.BOOT, Loading