Split ncli across multiple files in its own directory
This commit is contained in:
133
modules/ncli/builder.nix
Normal file
133
modules/ncli/builder.nix
Normal file
@ -0,0 +1,133 @@
|
||||
# ncli/builder.nix — Assembles all modules into the final script
|
||||
{
|
||||
pkgs,
|
||||
host,
|
||||
backupFiles ? [".config/mimeapps.list.backup"],
|
||||
project,
|
||||
...
|
||||
}: let
|
||||
# --- Shared library ---
|
||||
lib = import ./lib.nix {inherit pkgs host project backupFiles;};
|
||||
|
||||
# --- Command modules ---
|
||||
rebuild = import ./commands/rebuild.nix lib;
|
||||
maintenance = import ./commands/maintenance.nix lib;
|
||||
git = import ./commands/git.nix lib;
|
||||
switch = import ./commands/switch.nix lib;
|
||||
dev = import ./commands/dev.nix lib;
|
||||
|
||||
# --- Help text ---
|
||||
print_help = ''
|
||||
echo "NixOS CLI Utility -- version 2.1.3"
|
||||
echo ""
|
||||
echo "Usage: ncli [command]"
|
||||
echo ""
|
||||
echo "System Commands:"
|
||||
echo " rebuild - Rebuild the NixOS system configuration."
|
||||
echo " update - Update the flake and rebuild the system."
|
||||
echo ""
|
||||
echo "Maintenance Commands:"
|
||||
echo " cleanup - Clean up old system generations. Can specify a number to keep."
|
||||
echo " diag - Create a system diagnostic report (saves to ~/diag.txt)."
|
||||
echo " list-gens - List user and system generations."
|
||||
echo " trim - Trim filesystems to improve SSD performance."
|
||||
echo ""
|
||||
echo "Git Commands:"
|
||||
echo " commit [msg] - Add all changes and commit with message."
|
||||
echo " push - Push changes to origin."
|
||||
echo " pull - Pull latest changes from origin."
|
||||
echo " status - Show git status."
|
||||
echo ""
|
||||
echo "Development Commands:"
|
||||
echo " dev - Initialize a Nix development environment (flake.nix + direnv)."
|
||||
echo " dev track - Remove assume-unchanged flag from flake files."
|
||||
echo " dev untrack - Mark flake files as assume-unchanged in a directory."
|
||||
echo ""
|
||||
echo " help - Show this help message."
|
||||
echo ""
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "ncli" ''
|
||||
#!${pkgs.bash}/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# --- Configuration ---
|
||||
PROJECT="${project}"
|
||||
HOST="${host}"
|
||||
BACKUP_FILES_STR="${lib.backupFilesString}"
|
||||
VERSION="2.2.0"
|
||||
FLAKE_NIX_PATH="$HOME/$PROJECT/flake.nix"
|
||||
|
||||
read -r -a BACKUP_FILES <<< "$BACKUP_FILES_STR"
|
||||
|
||||
# --- Read Colors file ---
|
||||
source ${lib.colorsSource}
|
||||
|
||||
# --- Helper Functions ---
|
||||
${lib.handle_backups}
|
||||
${lib.handle_build_error}
|
||||
${lib.print_header}
|
||||
${lib.print_success}
|
||||
${lib.print_error}
|
||||
${lib.print_info}
|
||||
|
||||
# --- Main Logic ---
|
||||
if [ "$#" -eq 0 ]; then
|
||||
echo "Error: No command provided." >&2
|
||||
print_help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
rebuild)
|
||||
${rebuild.rebuild_case}
|
||||
;;
|
||||
update)
|
||||
${rebuild.update_case}
|
||||
;;
|
||||
cleanup)
|
||||
${maintenance.cleanup_case}
|
||||
;;
|
||||
diag)
|
||||
${maintenance.diag_case}
|
||||
;;
|
||||
list-gens)
|
||||
${maintenance.list_gens_case}
|
||||
;;
|
||||
trim)
|
||||
${maintenance.trim_case}
|
||||
;;
|
||||
home-backups)
|
||||
${maintenance.home_backups_case}
|
||||
;;
|
||||
commit)
|
||||
${git.commit_case}
|
||||
;;
|
||||
push)
|
||||
${git.push_case}
|
||||
;;
|
||||
pull)
|
||||
${git.pull_case}
|
||||
;;
|
||||
status)
|
||||
${git.status_case}
|
||||
;;
|
||||
format)
|
||||
${git.format_case}
|
||||
;;
|
||||
switch)
|
||||
${switch.switch_case}
|
||||
;;
|
||||
dev)
|
||||
${dev.dev_case}
|
||||
;;
|
||||
help)
|
||||
${print_help}
|
||||
;;
|
||||
*)
|
||||
echo "Error: Invalid command '$1'" >&2
|
||||
print_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
''
|
||||
Reference in New Issue
Block a user