nixos-rebuild-ng: move list_generations to services.py

This commit is contained in:
Thiago Kenji Okada
2025-06-28 20:42:49 +01:00
parent 7fdb86a635
commit b633b75cc9
2 changed files with 25 additions and 18 deletions
@@ -1,5 +1,4 @@
import argparse
import json
import logging
import os
import sys
@@ -10,8 +9,8 @@ from . import nix
from .constants import EXECUTABLE, WITH_NIX_2_18, WITH_REEXEC, WITH_SHELL_FILES
from .models import Action, BuildAttr, Flake, Profile
from .process import Remote
from .services import build_and_activate_system, reexec
from .utils import LogFormatter, tabulate
from .services import build_and_activate_system, list_generations, reexec
from .utils import LogFormatter
logger: Final = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
@@ -349,20 +348,7 @@ def execute(argv: list[str]) -> None:
raise AssertionError("DRY_RUN should be a DRY_BUILD alias")
case Action.LIST_GENERATIONS:
generations = nix.list_generations(profile)
if args.json:
print(json.dumps(generations, indent=2))
else:
headers = {
"generation": "Generation",
"date": "Build-date",
"nixosVersion": "NixOS version",
"kernelVersion": "Kernel",
"configurationRevision": "Configuration Revision",
"specialisations": "Specialisation",
"current": "Current",
}
print(tabulate(generations, headers=headers))
list_generations(args, profile)
case Action.REPL:
if flake:
@@ -1,4 +1,5 @@
import argparse
import json
import logging
import os
import sys
@@ -10,7 +11,7 @@ from . import nix, tmpdir
from .constants import EXECUTABLE
from .models import Action, BuildAttr, Flake, ImageVariants, NixOSRebuildError, Profile
from .process import Remote, cleanup_ssh
from .utils import Args
from .utils import Args, tabulate
NIXOS_REBUILD_ATTR: Final = "config.system.build.nixos-rebuild"
@@ -315,3 +316,23 @@ def build_and_activate_system(
common_flags=common_flags,
flake_common_flags=flake_common_flags,
)
def list_generations(
args: argparse.Namespace,
profile: Profile,
) -> None:
generations = nix.list_generations(profile)
if args.json:
print(json.dumps(generations, indent=2))
else:
headers = {
"generation": "Generation",
"date": "Build-date",
"nixosVersion": "NixOS version",
"kernelVersion": "Kernel",
"configurationRevision": "Configuration Revision",
"specialisations": "Specialisation",
"current": "Current",
}
print(tabulate(generations, headers=headers))