From 2f9ff34ad4cace211b2e0409d4f6638051e64bd1 Mon Sep 17 00:00:00 2001 From: Peritia Date: Wed, 6 Aug 2025 09:34:26 +0200 Subject: [PATCH 1/2] Adding Importing functionality --- README.md | 226 ++++++++------- flake.nix | 11 + nyx-cleanup.nix | 56 ---- nyx-rebuild.nix | 87 ------ nyx-tool.nix | 28 -- nyx.nix => nyx/default.nix | 5 - nyx/nyx-cleanup.nix | 176 ++++++++++++ nyx/nyx-rebuild.nix | 295 ++++++++++++++++++++ nyx/nyx-tool.nix | 79 ++++++ other/bash/nyx-rebuild.sh | 304 +++++++++++++++++++++ other/bash/nyx-tool.sh | 101 +++++++ other/example/configuration.nix | 37 +++ other/example/flake.nix | 30 ++ EXAMPLE_home.nix => other/example/home.nix | 43 ++- {zsh => other/zsh}/nyx-cleanup.zsh | 11 +- {zsh => other/zsh}/nyx-rebuild.zsh | 2 +- {zsh => other/zsh}/nyx-tool.zsh | 4 +- 17 files changed, 1188 insertions(+), 307 deletions(-) create mode 100644 flake.nix delete mode 100644 nyx-cleanup.nix delete mode 100644 nyx-rebuild.nix delete mode 100644 nyx-tool.nix rename nyx.nix => nyx/default.nix (80%) create mode 100644 nyx/nyx-cleanup.nix create mode 100644 nyx/nyx-rebuild.nix create mode 100644 nyx/nyx-tool.nix create mode 100644 other/bash/nyx-rebuild.sh create mode 100644 other/bash/nyx-tool.sh create mode 100644 other/example/configuration.nix create mode 100644 other/example/flake.nix rename EXAMPLE_home.nix => other/example/home.nix (51%) rename {zsh => other/zsh}/nyx-cleanup.zsh (89%) rename {zsh => other/zsh}/nyx-rebuild.zsh (99%) rename {zsh => other/zsh}/nyx-tool.zsh (97%) diff --git a/README.md b/README.md index 941ac12..442a15d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # โš™๏ธ Nyx: NixOS System Management Toolkit -**Nyx** is a modular toolkit for managing NixOS systems. It streamlines NixOS rebuilds, system cleanups, and developer workflow enhancements through a unified and extensible interface. Simply import one file to enable all features. +**Nyx** is a modular toolkit that simplifies and automates various NixOS system management tasks, from enhanced rebuilds to cleanup and shell customization. --- @@ -8,152 +8,168 @@ * ๐Ÿ” **Enhanced NixOS Rebuilds** โ€” via `nyx-rebuild.nix` * ๐Ÿงน **Automated System Cleanup** โ€” via `nyx-cleanup.nix` -* ๐Ÿ› ๏ธ **Custom Shell Tools & Visuals** โ€” like banners via `nyx-tool.nix` -* ๐Ÿงฉ **One-File Integration** โ€” import just `nyx.nix` to activate everything +* ๐Ÿ› ๏ธ **Shell Customization & Tooling** โ€” banners and helpers via `nyx-tool.nix` +* ๐Ÿงฉ **All-in-One Integration** โ€” enable everything with a single import: `nyx.nix` --- ## ๐Ÿ“ฆ Dependencies -* โœ… NixOS or compatible Nix environment -* โœ… `sudo` access (for system operations) -* โœ… [Home Manager](https://github.com/nix-community/home-manager) -* โœ… Git โ€” required if you use `autoPush` features (must be a Git repo) -* โœ… Zsh (included via Nyx modules) -* โœ… [`nix-output-monitor`](https://github.com/maralorn/nix-output-monitor) (included via Nyx) - -> โ„น๏ธ No need to preinstall Zsh or `nix-output-monitor`; Nyx provides them internally. +| Tool / Service | Required | Notes | +| -------------------- | -------- | -------------------------------------------------------- | +| NixOS / Nix | โœ… | Nyx is designed for NixOS or compatible Nix environments | +| `sudo` access | โœ… | Needed for system-level operations | +| Home Manager | โœ… | Integrates via `home.nix` | +| Git | โœ… | Required for `autoPush*` features (must be a Git repo) | +| `nix-output-monitor` | โœ… | Automatically provided by Nyx | --- ## ๐Ÿ“ Project Structure -```bash +``` Nyx-Tools -โ”œโ”€โ”€ nyx.nix # Master module -โ”œโ”€โ”€ nyx-tool.nix # Shell customizations (e.g., banners) +โ”œโ”€โ”€ default.nix # Top-level module +โ”œโ”€โ”€ nyx-tool.nix # Shell enhancements and banners โ”œโ”€โ”€ nyx-rebuild.nix # Enhanced nixos-rebuild logic -โ”œโ”€โ”€ nyx-cleanup.nix # System cleanup logic -โ””โ”€โ”€ zsh/ - โ”œโ”€โ”€ nyx-cleanup.zsh - โ”œโ”€โ”€ nyx-rebuild.zsh - โ””โ”€โ”€ nyx-tool.zsh -```` +โ”œโ”€โ”€ nyx-cleanup.nix # System cleanup automation +โ””โ”€โ”€ other/ # Legacy scripts (to be removed soon) +``` --- ## โš™๏ธ How It Works -* `nyx.nix`: Central module that imports all others. -* `nyx-tool.nix`: Adds startup banners and sources Zsh helpers. -* `nyx-rebuild.nix`: Extends `nixos-rebuild` with logs, Git push, and optional formatting. -* `nyx-cleanup.nix`: Automates system cleanup and logs output. -* `zsh/*.zsh`: Shell scripts sourced into Zsh to handle CLI tooling. +* **`nyx-tool.nix`** + Sets up shell visuals (e.g. banners) and Zsh helpers. + +* **`nyx-rebuild.nix`** + Enhances `nixos-rebuild` with: + + * Git auto-push support + * Optional code formatting before builds + * Rebuild logging + +* **`nyx-cleanup.nix`** + Automates system cleanup and tracks logs (optionally pushes to GitHub). --- ## ๐Ÿš€ Quick Start -### 1. Import into `home.nix` +### 1. Add Nyx to your Flake ```nix -imports = [ - ./path/to/Nyx-Tools/nyx.nix -]; +# flake.nix +{ + inputs.nyx.url = "github:Peritia-System/Nyx-Tools"; + + outputs = inputs @ { nixpkgs, nyx, ... }: + { + nixosConfigurations.HOSTNAME = nixpkgs.lib.nixosSystem { + modules = [ ./configuration.nix ]; + }; + }; +} ``` -### 2. Enable desired modules +### 2. Import Nyx into Home Manager ```nix -modules.nyx-rebuild = { - enable = true; - inherit username nixDirectory; -}; - -modules.nyx-cleanup = { - enable = true; - inherit username nixDirectory; -}; - -modules.nix-tool = { - enable = true; - inherit nixDirectory; -}; +# home.nix +{ + imports = [ + inputs.nyx.homeManagerModules.default + ]; +} ``` -> โš ๏ธ **Note:** You must define `nixDirectory` in your configuration or import it. -> It must be a **full path** to your flake directory (e.g., `/home/${username}/NixOS/Nyx-Tools`). - -๐Ÿ‘‰ See the [example config](./EXAMPLE_home.nix) for a working setup. - ---- - -## ๐Ÿ› ๏ธ Module Options - -### `nyx-rebuild` - -| Option | Description | Default | -| ------------------ | ----------------------------------- | ------- | -| `enable` | Enable this module | `false` | -| `startEditor` | Launch an editor before rebuild | `false` | -| `editor` | Which editor to use (`nvim`, `vim`) | โ€” | -| `enableFormatting` | Format Nix files before rebuild | `false` | -| `formatter` | Formatter to use (`alejandra`) | โ€” | -| `enableAlias` | Add shell alias for rebuild | `false` | -| `autoPush` | Push rebuild logs or dir to GitHub | `false` | - ---- - -### `nyx-cleanup` - -| Option | Description | Default | -| ----------------- | ------------------------------------ | ------- | -| `enable` | Enable this module | `false` | -| `autoPush` | Push logs to GitHub after cleanup | `false` | -| `keepGenerations` | Number of system generations to keep | `5` | -| `enableAlias` | Add shell alias for cleanup | `false` | - ---- - -### `nix-tool` - -| Option | Description | Default | -| -------- | ------------------ | ------- | -| `enable` | Enable this module | `false` | - ---- - -## ๐ŸŽจ Customization - -Nyx is fully modular and extensible. You can: - -* Modify existing `.nix` or `.zsh` files -* Add new modules and source them in `nyx.nix` - -### Example: Adding a Custom Tool +### 3. Enable Desired Modules ```nix -# Add to nyx.nix or your home.nix -imports = [ - ./nyx-rebuild.nix - ./my-custom-tool.nix -]; +{ + nyx.nyx-rebuild = { + enable = true; + inherit username nixDirectory; + }; + + nyx.nyx-cleanup = { + enable = true; + inherit username nixDirectory; + }; + + nyx.nyx-tool = { + enable = true; + inherit nixDirectory; + }; +} ``` -Create `my-custom-tool.nix` and optionally pair it with a `.zsh` helper script in the `zsh/` folder. +> โš ๏ธ **Note**: `nixDirectory` must be a **full path** to your flake repo (e.g., `/home/${username}/NixOS/Nyx-Tools`). + +See `./other/example/home.nix` for a working example. + +--- + +## ๐Ÿ”ง Module Options + +### `modules.nyx-rebuild` + +| Option | Description | Default | +| ------------------ | -------------------------------------- | ------------------------- | +| `enable` | Enable the module | `false` | +| `startEditor` | Launch editor before rebuilding | `false` | +| `editor` | Editor to use (`vim`, `nvim`, etc.) | โ€” | +| `enableFormatting` | Auto-format Nix files before rebuild | `false` | +| `formatter` | Formatter to use (e.g., `alejandra`) | โ€” | +| `enableAlias` | Add CLI alias for rebuild | `false` | +| `autoPushLog` | Push rebuild logs to GitHub | `false` | +| `autoPushNixDir` | Push flake dir to GitHub after rebuild | `false` | +| `username` | Username the module applies to | Required | +| `nixDirectory` | Full path to the Nix flake directory | Required | +| `logDir` | Where to store logs | `~/.nyx/nyx-rebuild/logs` | + +--- + +### `modules.nyx-cleanup` + +| Option | Description | Default | +| ----------------- | ----------------------------- | ------------------------- | +| `enable` | Enable the module | `false` | +| `autoPush` | Push logs to GitHub | `false` | +| `keepGenerations` | Number of generations to keep | `5` | +| `enableAlias` | Add CLI alias for cleanup | `false` | +| `username` | User this applies to | Required | +| `nixDirectory` | Full path to flake dir | Required | +| `logDir` | Path to store logs | `~/.nyx/nyx-cleanup/logs` | + +--- + +### `modules.nyx-tool` + +| Option | Description | Default | +| -------- | ------------------------------- | ------- | +| `enable` | Enables banners and shell tools | `false` | + +> ๐Ÿ’ก `nyx-tool` must be enabled for other modules to function properly. --- ## ๐Ÿค Contributing -Contributions are welcome! Feel free to open an issue or submit a pull request to: +You're welcome to contribute: -* Add new functionality -* Improve existing tools -* Fix bugs or typos +* New features & modules +* Tooling improvements +* Bug fixes or typos + +Open an issue or pull request at: + +๐Ÿ‘‰ [https://github.com/Peritia-System/Nyx-Tools](https://github.com/Peritia-System/Nyx-Tools) --- ## ๐Ÿ“„ License -Licensed under the [MIT License](./LICENSE). +Licensed under the [MIT License](./LICENSE) + diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..8731513 --- /dev/null +++ b/flake.nix @@ -0,0 +1,11 @@ +{ + description = "Nyx: Home Manager Tools"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs, ... }: { + homeManagerModules.default = import ./nyx; + }; +} diff --git a/nyx-cleanup.nix b/nyx-cleanup.nix deleted file mode 100644 index 51de1cc..0000000 --- a/nyx-cleanup.nix +++ /dev/null @@ -1,56 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.modules.nyx-cleanup; - scriptTargetPath = "${cfg.nixDirectory}/Misc/Nyx-Tools/zsh/nyx-cleanup.zsh"; -in -{ - options.modules.nyx-cleanup = { - enable = lib.mkEnableOption "Enable nyx-cleanup Zsh function and Zsh shell"; - - username = lib.mkOption { - type = lib.types.str; - description = "The name of the user this module applies to."; - }; - - nixDirectory = lib.mkOption { - type = lib.types.path; - description = "Path to the NixOS configuration directory."; - }; - - keepGenerations = lib.mkOption { - type = lib.types.int; - default = 5; - description = "Number of NixOS generations to keep during cleanup."; - }; - - autoPush = lib.mkOption { - type = lib.types.bool; - default = false; - description = "If true, push commits to Git remote after cleanup."; - }; - - enableAlias = lib.mkOption { - type = lib.types.bool; - default = true; - description = "If true, add `nc` alias for `nyx-cleanup`."; - }; - }; - - config = lib.mkIf cfg.enable { - programs.zsh.enable = lib.mkDefault true; - - home.shellAliases = lib.mkIf cfg.enableAlias { - nc = "nyx-cleanup"; - }; - - programs.zsh.initContent = '' - - # Nyx Cleanup - nix_dir="${cfg.nixDirectory}" - auto_push="${toString cfg.autoPush}" - keep_generations="${toString cfg.keepGenerations}" - source "${scriptTargetPath}" - ''; - }; -} diff --git a/nyx-rebuild.nix b/nyx-rebuild.nix deleted file mode 100644 index 7eb2364..0000000 --- a/nyx-rebuild.nix +++ /dev/null @@ -1,87 +0,0 @@ -{ config, lib, pkgs, ... }: - -let - cfg = config.modules.nyx-rebuild; - scriptTargetPath = "${cfg.nixDirectory}/Misc/Nyx-Tools/zsh/nyx-rebuild.zsh"; -in -{ - options.modules.nyx-rebuild = { - enable = lib.mkEnableOption "Enable nyx-rebuild Zsh function and Zsh shell"; - - username = lib.mkOption { - type = lib.types.str; - description = "The name of the user this module applies to."; - }; - - nixDirectory = lib.mkOption { - type = lib.types.path; - description = "Path to the NixOS configuration directory."; - }; - - editor = lib.mkOption { - type = lib.types.str; - default = "nvim"; - description = "Editor used in nyx-rebuild."; - }; - - formatter = lib.mkOption { - type = lib.types.str; - default = "alejandra"; - description = "Formatter used for Nix files."; - }; - - startEditor = lib.mkOption { - type = lib.types.bool; - default = false; - description = "If true, starts editor while then rebuilds."; - }; - - enableFormatting = lib.mkOption { - type = lib.types.bool; - default = false; - description = "If true, uses set Formatter"; - }; - - autoPush = lib.mkOption { - type = lib.types.bool; - default = false; - description = "If true, push commits to Git remote after rebuild."; - }; - - enableAlias = lib.mkOption { - type = lib.types.bool; - default = true; - description = "If true, add `nr` alias for `nyx-rebuild`."; - }; - - }; - - config = lib.mkIf cfg.enable { - programs.zsh.enable = lib.mkDefault true; - - - # Enable known formatters - ## no enable function - home.packages = lib.mkIf (cfg.enableFormatting && cfg.formatter == "alejandra") [ - pkgs.alejandra - ]; - - # Add optional alias - home.shellAliases = lib.mkIf cfg.enableAlias { - nr = "nyx-rebuild"; - }; - -# Add to .zshrc - programs.zsh.initContent = '' - - # Extract cfg values into local variables - nix_dir="${cfg.nixDirectory}" - start_editor="${toString cfg.startEditor}" - enable_formatting="${toString cfg.enableFormatting}" - editor_cmd="${cfg.editor}" - formatter_cmd="${cfg.formatter}" - auto_push="${toString cfg.autoPush}" - source "${scriptTargetPath}" - ''; - }; -} diff --git a/nyx-tool.nix b/nyx-tool.nix deleted file mode 100644 index 7969f5c..0000000 --- a/nyx-tool.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ config, lib, pkgs,... }: - -let - cfg = config.modules.nix-tool; - scriptTargetPath = "${cfg.nixDirectory}/Misc/Nyx-Tools/zsh/nyx-tool.zsh"; -in -{ - options.modules.nix-tool = { - enable = lib.mkEnableOption "Enable nix-tool Zsh function for Banner display."; - - nixDirectory = lib.mkOption { - type = lib.types.str; - description = "Path to the main Nix directory used for scripts."; - }; - }; - - config = lib.mkIf cfg.enable { - home.packages = [ - pkgs.figlet - ]; - - programs.zsh.enable = lib.mkDefault true; - - programs.zsh.initContent = '' - source "${scriptTargetPath}" - ''; - }; -} diff --git a/nyx.nix b/nyx/default.nix similarity index 80% rename from nyx.nix rename to nyx/default.nix index d28b01e..75328dc 100644 --- a/nyx.nix +++ b/nyx/default.nix @@ -14,9 +14,4 @@ ./nyx-cleanup.nix ]; - home.packages = with pkgs; [ - nix-output-monitor - ]; - - } diff --git a/nyx/nyx-cleanup.nix b/nyx/nyx-cleanup.nix new file mode 100644 index 0000000..841e86d --- /dev/null +++ b/nyx/nyx-cleanup.nix @@ -0,0 +1,176 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.nyx.nyx-cleanup; + logDirDefault = "/home/${toString cfg.username}/.nyx/nyx-cleanup/logs"; +in + +{ + options.nyx.nyx-cleanup = { + enable = lib.mkEnableOption "Enable nyx-cleanup script"; + + username = lib.mkOption { + type = lib.types.str; + description = "The user this module applies to."; + }; + + nixDirectory = lib.mkOption { + type = lib.types.path; + description = "Path to NixOS flake configuration."; + }; + + logDir = lib.mkOption { + type = lib.types.str; + default = logDirDefault; + description = "Directory for storing cleanup logs."; + }; + + keepGenerations = lib.mkOption { + type = lib.types.int; + default = 5; + description = "Number of NixOS generations to keep."; + }; + + autoPush = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Whether to auto-push git commits after cleanup."; + }; + + enableAlias = lib.mkOption { + type = lib.types.bool; + default = true; + description = "If true, add alias 'nc' for 'nyx-cleanup'."; + }; + }; + + config = lib.mkIf cfg.enable { + home.packages = [ + (pkgs.writeShellScriptBin "nyx-cleanup" '' + + #!/usr/bin/env bash + nyx-cleanup(){ + set -euo pipefail + + # === CONFIGURATION === + log_dir="${toString cfg.logDir}" + keep_generations=${toString cfg.keepGenerations} + auto_push=${if cfg.autoPush then "true" else "false"} + git_bin="${pkgs.git}/bin/git" + + # Derived repo dir (assumes: ~/.nyx/nyx-cleanup/logs โ†’ ~/.nyx) + repo_dir="$(dirname "$(dirname "$log_dir")")" + + # === INITIAL SETUP === + version="1.0.0" + start_time=$(date +%s) + start_human=$(date '+%Y-%m-%d %H:%M:%S') + cleanup_success=false + exit_code=1 + + # === COLORS === + if [[ -t 1 ]]; then + RED=$'\e[31m'; GREEN=$'\e[32m'; YELLOW=$'\e[33m' + BLUE=$'\e[34m'; MAGENTA=$'\e[35m'; CYAN=$'\e[36m' + BOLD=$'\e[1m'; RESET=$'\e[0m' + else + RED=""; GREEN=""; YELLOW="" + BLUE=""; MAGENTA=""; CYAN="" + BOLD=""; RESET="" + fi + + # === LOGGING === + mkdir -p "$log_dir" + timestamp=$(date '+%Y-%m-%d_%H-%M-%S') + cleanup_log="$log_dir/cleanup-''${timestamp}.log" + + console-log() { + echo -e "$@" | tee -a "$cleanup_log" + } + + print_line() { + console-log "" + console-log "''${BOLD}==================================================''${RESET}" + console-log "" + } + + finish_cleanup() { + duration=$(( $(date +%s) - start_time )) + if [[ "$cleanup_success" == true ]]; then + echo -e "''${GREEN}''${BOLD} +############################## +# โœ… Nyx Cleanup Complete! # +##############################''${RESET}" + echo -e "''${CYAN}''${BOLD}๐Ÿ“‹ Stats:''${RESET}" + echo " ๐Ÿ•’ Started: $start_human" + echo " โฑ๏ธ Duration: ''${duration} sec" + else + echo -e "''${RED}''${BOLD} +############################## +# โŒ Nyx Cleanup Failed! # +##############################''${RESET}" + echo " ๐Ÿ•’ Started: $start_human" + echo " โฑ๏ธ Duration: ''${duration} sec" + fi + } + + trap finish_cleanup EXIT + + print_line + console-log "''${BLUE}''${BOLD}๐Ÿงน Starting cleanup...''${RESET}" + + # === REMOVE OLD LOGS === + console-log "''${CYAN}''${BOLD}๐Ÿ—‘๏ธ Removing logs older than 30 days...''${RESET}" + find "$log_dir" -type f -mtime +30 -print -delete + + # === REMOVE HOME MANAGER BACKUPS === + print_line + console-log "''${CYAN}''${BOLD}๐Ÿ“ Deleting Home Manager backup files...''${RESET}" + find ~ -type f -name '*delme-HMbackup' -print -delete + + # === GARBAGE COLLECTION === + print_line + console-log "''${MAGENTA}''${BOLD}๐Ÿงผ Running Nix garbage collection...''${RESET}" + sudo nix-collect-garbage -d | tee -a "$cleanup_log" + + # === GIT SETUP === + print_line + if [[ ! -d "$repo_dir/.git" ]]; then + console-log "''${YELLOW}โš ๏ธ No git repo in: $repo_dir. Initializing...''${RESET}" + "$git_bin" -C "$repo_dir" init | tee -a "$cleanup_log" + fi + + # === GIT AUTO PUSH === + if [[ "$auto_push" == "true" ]]; then + print_line + console-log "''${BLUE}''${BOLD}๐Ÿš€ Auto-pushing git commits in $repo_dir...''${RESET}" + cd "$repo_dir" + + if "$git_bin" remote | grep -q .; then + "$git_bin" add . + "$git_bin" commit -m "chore(cleanup): auto cleanup $(date)" || true + "$git_bin" push + else + console-log "''${YELLOW}โš ๏ธ No git remote configured. Skipping push.''${RESET}" + console-log "''${YELLOW}๐Ÿ“‚ Check logs in: $log_dir''${RESET}" + fi + fi + + cleanup_success=true + exit_code=0 + + print_line + console-log "''${GREEN}๐ŸŽ‰ Cleanup finished successfully!''${RESET}" + print_line + } + nyx-cleanup + + + '') + ]; + + home.shellAliases = lib.mkIf cfg.enableAlias { + nc = "nyx-cleanup"; + }; + }; +} diff --git a/nyx/nyx-rebuild.nix b/nyx/nyx-rebuild.nix new file mode 100644 index 0000000..758ea4e --- /dev/null +++ b/nyx/nyx-rebuild.nix @@ -0,0 +1,295 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.nyx.nyx-rebuild; + nixDirStr = toString cfg.nixDirectory; + logDirDefault = "/home/${cfg.username}/.nyx/nyx-rebuild/logs"; +in +{ + options.nyx.nyx-rebuild = { + enable = lib.mkEnableOption "Enable nyx-rebuild script"; + + username = lib.mkOption { + type = lib.types.str; + description = "User this module applies to."; + }; + + nixDirectory = lib.mkOption { + type = lib.types.path; + description = "Path to NixOS flake configuration."; + }; + + logDir = lib.mkOption { + type = lib.types.str; + default = logDirDefault; + description = "Directory for storing cleanup logs."; + }; + + editor = lib.mkOption { + type = lib.types.str; + default = "nvim"; + description = "Editor for manual editing step."; + }; + + formatter = lib.mkOption { + type = lib.types.str; + default = "alejandra"; + description = "Formatter to use before rebuild."; + }; + + startEditor = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Start editor before rebuild."; + }; + + enableFormatting = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Format Nix files before rebuild."; + }; + + autoPushLog = lib.mkOption { + type = lib.types.bool; + default = false; + description = "If true, automatically push $git_bin commits containing rebuild logs."; + }; + + autoPushNixDir = lib.mkOption { + type = lib.types.bool; + default = false; + description = "If true, push $git_bin commits in nixDirectory (configuration repo) after rebuild."; + }; + + enableAlias = lib.mkOption { + type = lib.types.bool; + default = true; + description = "Add 'nr' alias for nyx-rebuild."; + }; + }; + + config = lib.mkIf cfg.enable { + programs.zsh.enable = lib.mkDefault true; + + home.packages = [ + # Add formatter if selected + ] ++ lib.optional (cfg.enableFormatting && cfg.formatter == "alejandra") pkgs.alejandra + ++ [ + # Main script + (pkgs.writeShellScriptBin "nyx-rebuild" '' +#!/usr/bin/env bash +nyx-rebuild () { +set -euo pipefail + +# === CONFIGURATION === +nix_dir="${nixDirStr}" +log_dir="${toString cfg.logDir}" +start_editor="${if cfg.startEditor then "true" else "false"}" +enable_formatting="${if cfg.enableFormatting then "true" else "false"}" +editor_cmd="${cfg.editor}" +formatter_cmd="${cfg.formatter}" +auto_push_log="${if cfg.autoPushLog then "true" else "false"}" +auto_push_nixdir="${if cfg.autoPushNixDir then "true" else "false"}" +git_bin="${pkgs.git}/bin/git" +nom_bin="${pkgs.nix-output-monitor}/bin/nom" + +# === INITIAL SETUP === +version="beta-2.0.0" +start_time=$(date +%s) +start_human=$(date '+%Y-%m-%d %H:%M:%S') +stats_duration=0 +stats_gen="?" +stats_errors=0 +stats_last_error_lines="" +rebuild_success=false +exit_code=1 + +# === COLORS === +if [[ -t 1 ]]; then + RED=$'\e[31m'; GREEN=$'\e[32m'; YELLOW=$'\e[33m' + BLUE=$'\e[34m'; MAGENTA=$'\e[35m'; CYAN=$'\e[36m' + BOLD=$'\e[1m'; RESET=$'\e[0m' +else + RED=""; GREEN=""; YELLOW="" + BLUE=""; MAGENTA=""; CYAN="" + BOLD=""; RESET="" +fi + +# === LOGGING SETUP === +hostname=$(hostname) +mkdir -p "$log_dir" +timestamp=$(date '+%Y-%m-%d_%H-%M-%S') +build_log="$log_dir/build-''${timestamp}.log" +error_log="$log_dir/Current-Error-''${timestamp}.txt" + +# === HELPERS === +console-log() { + echo -e "$@" | tee -a "$build_log" +} + +print_line() { + console-log "" + console-log "''${BOLD}==================================================''${RESET}" + console-log "" +} + +run_with_log() { + local cmd_output + cmd_output=$(mktemp) + ( + "$@" 2>&1 + echo $? > "$cmd_output" + ) | tee -a "$build_log" + local status + status=$(<"$cmd_output") + rm "$cmd_output" + return "$status" +} + +run_with_log_rebuild() { + local cmd_output + cmd_output=$(mktemp) + ( + "$@" 2>&1 + echo $? > "$cmd_output" + ) | tee -a "$build_log" | $nom_bin + local status + status=$(<"$cmd_output") + rm "$cmd_output" + return "$status" +} + +finish_nyx_rebuild() { + stats_duration=$(( $(date +%s) - start_time )) + echo + if [[ "$rebuild_success" == true ]]; then + echo "''${GREEN}''${BOLD} +############################## +# โœ… NixOS Rebuild Complete! # +##############################''${RESET}" + echo "''${BOLD}''${CYAN}๐ŸŽฏ Success Stats:''${RESET}" + echo " ๐Ÿ•’ Started: $start_human" + echo " โฑ๏ธ Duration: ''${stats_duration} sec" + echo " ๐Ÿ“ฆ Gen: $stats_gen" + else + echo "''${RED}''${BOLD} +############################## +# โŒ NixOS Rebuild Failed! # +##############################''${RESET}" + echo "''${BOLD}''${RED}๐Ÿšจ Error Stats:''${RESET}" + echo " ๐Ÿ•’ Started: $start_human" + echo " โฑ๏ธ Duration: ''${stats_duration} sec" + echo " โŒ Error lines: ''${stats_errors}" + [[ -n "$stats_last_error_lines" ]] && echo -e "\n''${YELLOW}๐Ÿงพ Last few errors:''${RESET}\n$stats_last_error_lines" + fi +} + +trap finish_nyx_rebuild EXIT + +# === TOOL INFO === +echo +nyx-tool "Nyx" "nyx-rebuild" "$version" \ + "Smart NixOS configuration rebuilder" \ + "by Peritia-System" \ + "https://github.com/Peritia-System/Nyx-Tools" \ + "https://github.com/Peritia-System/Nyx-Tools/issues" \ + "Always up to date for you!" +echo + +# === PROJECT PREP === +cd "$nix_dir" || { exit_code=1; return $exit_code; } + +# === CHECK FOR UNCOMMITTED CHANGES === +console-log "\n''${BOLD}''${BLUE}๐Ÿ“ Checking $git_bin status...''${RESET}" +if [[ -n $($git_bin status --porcelain) ]]; then + echo "''${YELLOW}โš ๏ธ Uncommitted changes detected!''${RESET}" + echo "''${RED}โณ 5s to cancel...''${RESET}" + sleep 5 +fi + +# === SCRIPT START === +print_line +console-log "''${BLUE}''${BOLD}๐Ÿš€ Starting Nyx Rebuild...''${RESET}" + +# === GIT PULL === +console-log "\n''${BOLD}''${BLUE}โฌ‡๏ธ Pulling latest changes...''${RESET}" +run_with_log $git_bin pull --rebase || return 1 + +# === OPTIONAL: OPEN EDITOR === +if [[ "$start_editor" == "true" ]]; then + console-log "\n''${BOLD}''${BLUE}๐Ÿ“ Editing configuration...''${RESET}" + run_with_log "$editor_cmd" +fi + +# === OPTIONAL: FORMAT FILES === +if [[ "$enable_formatting" == "true" ]]; then + console-log "\n''${BOLD}''${MAGENTA}๐ŸŽจ Running formatter...''${RESET}" + run_with_log "$formatter_cmd" . +fi + +# === GIT DIFF === +console-log "\n''${BOLD}''${CYAN}๐Ÿ” Changes summary:''${RESET}" +run_with_log $git_bin diff --compact-summary + +# === SYSTEM REBUILD === +print_line +console-log "''${BLUE}''${BOLD}๐Ÿ”ง Starting system rebuild...''${RESET}" +console-log "๐Ÿ› ๏ธ Removing old HM conf" +run_with_log find ~ -type f -name '*delme-HMbackup' -exec rm -v {} + +print_line +console-log "Getting sudo ticket" +run_with_log sudo whoami > /dev/null +print_line +console-log "๐Ÿ› ๏ธ Rebuild started: $(date)" + + +run_with_log_rebuild sudo nixos-rebuild switch --flake "$nix_dir" +rebuild_status=$? + +if [[ $rebuild_status -ne 0 ]]; then + echo "''${RED}โŒ Rebuild failed at $(date).''${RESET}" > "$error_log" + stats_errors=$(grep -Ei -A 1 'error|failed' "$build_log" | tee -a "$error_log" | wc -l) + stats_last_error_lines=$(tail -n 10 "$error_log") + cd "$log_dir" + $git_bin add "$log_dir" + $git_bin commit -m "chore(rebuild): failed rebuild on $(date)" || true + [[ "$auto_push_nixdir" == "true" ]] && (cd "$nix_dir" && $git_bin push || true) + cd "$nix_dir" + return 1 +fi + +# === SUCCESS FLOW === +rebuild_success=true +gen=$(nixos-rebuild list-generations | grep True | awk '{$1=$1};1') +stats_gen=$(echo "$gen" | awk '{printf "%04d\n", $1}') +finish_nyx_rebuild >> "$build_log" + +$git_bin add -u +$git_bin commit -m "Rebuild: $gen" || true + +cd "$log_dir" +final_log="$log_dir/nixos-gen_''${stats_gen}-switch-''${timestamp}.log" +mv "$build_log" "$final_log" +$git_bin add "$final_log" +$git_bin commit -m "log for $gen" || true + +# === FINAL PUSH LOGS === +$git_bin add "$final_log" +$git_bin commit -m "chore(rebuild): successful rebuild on $(date)" || true + +if [[ "$auto_push_log" == "true" ]]; then + (cd "$repo_dir" && $git_bin push || true) +fi +cd "$nix_dir" + +echo -e "\n''${GREEN}๐ŸŽ‰ Nyx rebuild completed successfully!''${RESET}" +} +nyx-rebuild + '') + ]; + + home.shellAliases = lib.mkIf cfg.enableAlias { + nr = "nyx-rebuild"; + }; + }; +} diff --git a/nyx/nyx-tool.nix b/nyx/nyx-tool.nix new file mode 100644 index 0000000..d4fa58d --- /dev/null +++ b/nyx/nyx-tool.nix @@ -0,0 +1,79 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.nyx.nyx-tool; +in +{ + options.nyx.nyx-tool = { + enable = lib.mkEnableOption "Enable nyx-tool Script for Banner display."; + + nixDirectory = lib.mkOption { + type = lib.types.str; + description = "Path to the main Nix directory used for scripts."; + }; + }; + + config = lib.mkIf cfg.enable { + programs.zsh.enable = lib.mkDefault true; + + home.packages = + [ pkgs.figlet ] + ++ [ + (pkgs.writeShellScriptBin "nyx-tool" '' +#!/usr/bin/env bash +nyx-tool() { +# nyx-tool: reusable metadata banner printer with Base16 theme + local logo="''${1:-Nyx}" + local name="''${2:-nix-script}" + local version="''${3:-Version Unknown - Please Open Issue}" + local description="''${4:-A Nix utility}" + local credit="''${5:-Peritia-System}" + local github="''${6:-https://github.com/example/repo}" + local issues="''${7:-''${github}/issues}" + local message="''${8:-Use responsibly}" + + # Base16 color palette (ANSI escape codes) + local RESET="\033[0m" + local BOLD="\033[1m" + local HEADER="\033[38;5;33m" # blue + local LABEL="\033[38;5;70m" # green + local VALUE="\033[38;5;250m" # gray + local EMPHASIS="\033[38;5;196m" # red + local CYAN="\033[38;5;51m" + local GREEN="\033[38;5;82m" + + local line + line=$(printf '=%.0s' $(seq 1 35)) + + echo "" + echo -e "''${HEADER}''${line}''${RESET}" + echo -e "''${HEADER}=====[ ''${BOLD}Peritia System Tools''${RESET}''${HEADER} ]=====''${RESET}" + echo -e "''${VALUE}''${BOLD}" + + # Figlet logo rendering + if command -v figlet &>/dev/null; then + figlet -f banner3 "$logo" | sed 's/#/โ–ˆ/g' + else + echo "$logo" + fi + + echo -e "''${RESET}''${HEADER}by Peritia-System''${RESET}" + echo -e "''${HEADER}''${line}''${RESET}" + echo "" + + echo -e "''${LABEL}๐Ÿ› ๏ธ Name: ''${VALUE}''${name}''${RESET}" + echo -e "''${LABEL}๐Ÿท๏ธ Version: ''${VALUE}''${version}''${RESET}" + echo -e "''${LABEL}๐Ÿ“ Description: ''${VALUE}''${description}''${RESET}" + echo -e "''${LABEL}๐Ÿ‘ค Credit: ''${VALUE}''${credit}''${RESET}" + echo -e "''${LABEL}๐ŸŒ GitHub: ''${VALUE}''${github}''${RESET}" + echo -e "''${LABEL}๐Ÿ› Issues: ''${VALUE}''${issues}''${RESET}" + echo "" + echo -e "''${LABEL}๐Ÿ“Œ Message: ''${BOLD}''${message}''${RESET}" + echo "" + + } + nyx-tool "$@" + '') + ]; + }; +} diff --git a/other/bash/nyx-rebuild.sh b/other/bash/nyx-rebuild.sh new file mode 100644 index 0000000..d118926 --- /dev/null +++ b/other/bash/nyx-rebuild.sh @@ -0,0 +1,304 @@ +#!/usr/bin/env bash +nyx-rebuild () { +set -euo pipefail + +# === CONFIGURATION === +nix_dir="${nixDirStr}" +log_dir="${toString cfg.logDir}" +start_editor="${if cfg.startEditor then "true" else "false"}" +enable_formatting="${if cfg.enableFormatting then "true" else "false"}" +editor_cmd="${cfg.editor}" +formatter_cmd="${cfg.formatter}" +auto_push_log="${if cfg.autoPushLog then "true" else "false"}" +auto_push_nixdir="${if cfg.autoPushNixDir then "true" else "false"}" +git_bin="${pkgs.git}/bin/git" + +# === INITIAL SETUP === +start_time=$(date +%s) +start_human=$(date '+%Y-%m-%d %H:%M:%S') +stats_duration=0 +stats_gen="?" +stats_errors=0 +stats_last_error_lines="" +rebuild_success=false +exit_code=1 + +# === COLORS === +if [[ -t 1 ]]; then + RED=$'\e[31m'; GREEN=$'\e[32m'; YELLOW=$'\e[33m' + BLUE=$'\e[34m'; MAGENTA=$'\e[35m'; CYAN=$'\e[36m' + BOLD=$'\e[1m'; RESET=$'\e[0m' +else + RED=""; GREEN=""; YELLOW="" + BLUE=""; MAGENTA=""; CYAN="" + BOLD=""; RESET="" +fi + +# === LOGGING SETUP === +hostname=$(hostname) +log_dir="$nix_dir/Misc/nyx/logs/$hostname" +mkdir -p "$log_dir" +timestamp=$(date '+%Y-%m-%d_%H-%M-%S') +build_log="$log_dir/build-''${timestamp}.log" +error_log="$log_dir/Current-Error-''${timestamp}.txt" + +# === HELPERS === +console-log() { + echo -e "$@" | tee -a "$build_log" +} + + +# === LOGGING === +console-log() { + echo -e "$@" | tee -a "$build_log" +} + +print_line() { + console-log "" + console-log "''${BOLD}==================================================''${RESET}" + console-log "" +} + + +run_with_log() { + local cmd_output + cmd_output=$(mktemp) + ( + "$@" 2>&1 + echo $? > "$cmd_output" + ) | tee -a "$build_log" + local status + status=$(<"$cmd_output") + rm "$cmd_output" + return "$status" +} + +run_with_log_rebuild() { + local cmd_output + cmd_output=$(mktemp) + ( + "$@" 2>&1 + echo $? > "$cmd_output" + ) | tee -a "$build_log" | nom + local status + status=$(<"$cmd_output") + rm "$cmd_output" + return "$status" +} + +finish_nyx_rebuild() { + stats_duration=$(( $(date +%s) - start_time )) + echo + if [[ "$rebuild_success" == true ]]; then + echo "''${GREEN}''${BOLD} +############################## +# โœ… NixOS Rebuild Complete! # +##############################''${RESET}" + echo "''${BOLD}''${CYAN}๐ŸŽฏ Success Stats:''${RESET}" + echo " ๐Ÿ•’ Started: $start_human" + echo " โฑ๏ธ Duration: ''${stats_duration} sec" + echo " ๐Ÿ“ฆ Gen: $stats_gen" + else + echo "''${RED}''${BOLD} +############################## +# โŒ NixOS Rebuild Failed! # +##############################''${RESET}" + echo "''${BOLD}''${RED}๐Ÿšจ Error Stats:''${RESET}" + echo " ๐Ÿ•’ Started: $start_human" + echo " โฑ๏ธ Duration: ''${stats_duration} sec" + echo " โŒ Error lines: ''${stats_errors}" + [[ -n "$stats_last_error_lines" ]] && echo -e "\n''${YELLOW}๐Ÿงพ Last few errors:''${RESET}\n$stats_last_error_lines" + fi +} + +trap finish_nyx_rebuild EXIT + +# === TOOL INFO === + +echo +nyx-tool "Nyx" "nyx-rebuild" "$version" \ + "Smart NixOS configuration rebuilder" \ + "by Peritia-System" \ + "https://github.com/Peritia-System/Nyx-Tools" \ + "https://github.com/Peritia-System/Nyx-Tools/issues" \ + "Always up to date for you!" +echo + +# === INITIAL SETUP === +mkdir -p "$log_dir" +timestamp=$(date '+%Y-%m-%d_%H-%M-%S') +build_log="$log_dir/rebuild-''${timestamp}.log" +repo_dir="$(dirname "$(dirname "$log_dir")")" + + +# === PROJECT PREP === +cd "$nix_dir" || { exit_code=1; return $exit_code; } + + +console-log "\n''${BOLD}''${BLUE}๐Ÿ“ Checking Git status...''${RESET}" +if [[ -n $(git status --porcelain) ]]; then + echo "''${YELLOW}โš ๏ธ Uncommitted changes detected!''${RESET}" + echo "''${RED}โณ 5s to cancel...''${RESET}" + sleep 5 +fi + +# === SCRIPT START === +print_line +console-log "''${BLUE}''${BOLD}๐Ÿš€ Starting Nyx Rebuild...''${RESET}" + +# === GIT PULL === +console-log "\n''${BOLD}''${BLUE}โฌ‡๏ธ Pulling latest changes...''${RESET}" +if ! run_with_log $git_bin --rebase; then + exit_code=1; return $exit_code +fi + +# === OPTIONAL: OPEN EDITOR === +if [[ "$start_editor" == "true" ]]; then + console-log "\n''${BOLD}''${BLUE}๐Ÿ“ Editing configuration...''${RESET}" + console-log "Started editing: $(date)" + run_with_log "$editor_cmd" + console-log "Finished editing: $(date)" +fi + +# === OPTIONAL: FORMAT FILES === +if [[ "$enable_formatting" == "true" ]]; then + console-log "\n''${BOLD}''${MAGENTA}๐ŸŽจ Running formatter...''${RESET}" + run_with_log "$formatter_cmd" . +fi + +# === GIT DIFF === +console-log "\n''${BOLD}''${CYAN}๐Ÿ” Changes summary:''${RESET}" +run_with_log git diff --compact-summary + +# === SYSTEM REBUILD === +console-log "\n''${BOLD}''${BLUE}๐Ÿ”ง Starting system rebuild...''${RESET}" +print_line +console-log "๐Ÿ› ๏ธ Removing old HM conf" +run_with_log find ~ -type f -name '*delme-HMbackup' -exec rm -v {} + +print_line +console-log "Getting sudo ticket (please enter your password)" +run_with_log sudo whoami > /dev/null +print_line +console-log "๐Ÿ› ๏ธ Rebuild started: $(date)" +print_line + +run_with_log_rebuild sudo nixos-rebuild switch --flake "$nix_dir" +rebuild_status=$? + + + + + + + + +if [[ $rebuild_status -ne 0 ]]; then + echo "''${RED}โŒ Rebuild failed at $(date).''${RESET}" > "$error_log" + stats_errors=$(grep -Ei -A 1 'error|failed' "$build_log" | tee -a "$error_log" | wc -l) + stats_last_error_lines=$(tail -n 10 "$error_log") + git add "$log_dir" + git commit -m "Rebuild failed: errors logged" + if [[ "$auto_push" == "true" ]]; then + run_with_log git push && console-log "''${GREEN}โœ… Error log pushed to remote.''${RESET}" + fi + exit_code=1 + return $exit_code +fi + +# === SUCCESS FLOW === +rebuild_success=true +exit_code=0 + +gen=$(nixos-rebuild list-generations | grep True | awk '{$1=$1};1') +stats_gen=$(echo "$gen" | awk '{printf "%04d\n", $1}') +finish_nyx_rebuild >> "$build_log" + +git add -u +if ! git diff --cached --quiet; then + git commit -m "Rebuild: $gen" + console-log "''${BLUE}๐Ÿ”ง Commit message:''${RESET}\n''${GREEN}Rebuild: $gen''${RESET}" +fi + +final_log="$log_dir/nixos-gen_''${stats_gen}-switch-''${timestamp}.log" +mv "$build_log" "$final_log" +git add "$final_log" + +if ! git diff --cached --quiet; then + git commit -m "log for $gen" + echo "''${YELLOW}โ„น๏ธ Added changes to git''${RESET}" +else + echo "''${YELLOW}โ„น๏ธ No changes in logs to commit.''${RESET}" +fi + +if [[ "$auto_push" == "true" ]]; then + git push && echo "''${GREEN}โœ… Changes pushed to remote.''${RESET}" +fi + +echo -e "\n''${GREEN}๐ŸŽ‰ Nyx rebuild completed successfully!''${RESET}" + finish_nyx_rebuild + #return $exit_code +} +nyx-rebuild + + + + + + + + + + + + + +# === SUCCESS FLOW === +rebuild_success=true +exit_code=0 + +gen=$(nixos-rebuild list-generations | grep True | awk '{$1=$1};1') +stats_gen=$(echo "$gen" | awk '{printf "%04d\n", $1}') +finish_nyx_rebuild >> "$build_log" + +git add -u +if ! git diff --cached --quiet; then + git commit -m "Rebuild: $gen" + console-log "''${BLUE}๐Ÿ”ง Commit message:''${RESET}\n''${GREEN}Rebuild: $gen''${RESET}" +fi + +final_log="$log_dir/nixos-gen_''${stats_gen}-switch-''${timestamp}.log" +mv "$build_log" "$final_log" +git add "$final_log" + +if ! git diff --cached --quiet; then + git commit -m "log for $gen" + echo "''${YELLOW}โ„น๏ธ Added changes to git''${RESET}" +else + echo "''${YELLOW}โ„น๏ธ No changes in logs to commit.''${RESET}" +fi + +echo -e "\n''${GREEN}๐ŸŽ‰ Nyx rebuild completed successfully!''${RESET}" + finish_nyx_rebuild + + + +if [[ $? -ne 0 ]]; then + console-log "''${RED}''${BOLD}โŒ Rebuild failed. See log: $build_log''${RESET}" + $git_bin add "$build_log" + $git_bin commit -m "chore(rebuild): failed rebuild on $(date)" || true + if [[ "$auto_push_nixdir" == "true" ]]; then + ( + cd "$nix_dir" + if $git_bin remote | grep -q .; then + $git_bin push && console-log "''${GREEN}โœ… Nix config pushed to remote.''${RESET}" + else + console-log "''${YELLOW}โš ๏ธ No Git remote configured in nixDirectory.''${RESET}" + fi + ) + fi + exit 1 +fi + +print_line +console-log "''${GREEN}''${BOLD}โœ… NixOS rebuild complete!''${RESET}" + diff --git a/other/bash/nyx-tool.sh b/other/bash/nyx-tool.sh new file mode 100644 index 0000000..b9d4c13 --- /dev/null +++ b/other/bash/nyx-tool.sh @@ -0,0 +1,101 @@ +#!/usr/bin/env bash + +# nyx-tool: reusable metadata banner printer with Base16 theme +nyx-tool() { + local logo="${1:-Nyx}" + local name="${2:-nix-script}" + local version="${3:-Version Unknown - Please Open Issue}" + local description="${4:-A Nix utility}" + local credit="${5:-Peritia-System}" + local github="${6:-https://github.com/example/repo}" + local issues="${7:-${github}/issues}" + local message="${8:-Use responsibly}" + + # Base16 color palette (ANSI escape codes) + local RESET="\033[0m" + local BOLD="\033[1m" + local HEADER="\033[38;5;33m" # blue + local LABEL="\033[38;5;70m" # green + local VALUE="\033[38;5;250m" # gray + local EMPHASIS="\033[38;5;196m" # red + local CYAN="\033[38;5;51m" + local GREEN="\033[38;5;82m" + + local line + line=$(printf '=%.0s' $(seq 1 35)) + + echo "" + echo -e "${HEADER}${line}${RESET}" + echo -e "${HEADER}=====[ ${BOLD}Peritia System Tools${RESET}${HEADER} ]=====${RESET}" + echo -e "${VALUE}${BOLD}" + + # Figlet logo rendering + if command -v figlet &>/dev/null; then + figlet -f banner3 "$logo" | sed 's/#/โ–ˆ/g' + else + echo "$logo" + fi + + echo -e "${RESET}${HEADER}by Peritia-System${RESET}" + echo -e "${HEADER}${line}${RESET}" + echo "" + + echo -e "${LABEL}๐Ÿ› ๏ธ Name: ${VALUE}${name}${RESET}" + echo -e "${LABEL}๐Ÿท๏ธ Version: ${VALUE}${version}${RESET}" + echo -e "${LABEL}๐Ÿ“ Description: ${VALUE}${description}${RESET}" + echo -e "${LABEL}๐Ÿ‘ค Credit: ${VALUE}${credit}${RESET}" + echo -e "${LABEL}๐ŸŒ GitHub: ${VALUE}${github}${RESET}" + echo -e "${LABEL}๐Ÿ› Issues: ${VALUE}${issues}${RESET}" + echo "" + echo -e "${LABEL}๐Ÿ“Œ Message: ${BOLD}${message}${RESET}" + echo "" +} + +# Spinner with timing +nyx-show_spinner() { + local pid=$1 + local spinner_delay=0.1 + local spinstr='|/-\' + local start_time + start_time=$(date +%s%3N) + + local CYAN="\033[38;5;51m" + local GREEN="\033[38;5;82m" + local RESET="\033[0m" + + echo -ne "${CYAN}โณ Starting rebuild...${RESET} " + + ( + while kill -0 "$pid" 2>/dev/null; do + local now elapsed seconds milliseconds clock_time + now=$(date +%s%3N) + elapsed=$((now - start_time)) + seconds=$((elapsed / 1000)) + milliseconds=$((elapsed % 1000)) + clock_time=$(date +%T) + + for i in $(seq 0 3); do + printf "\r${CYAN}โณ [%s] %s [%d.%03ds] ${RESET}" "$clock_time" "${spinstr:$i:1}" "$seconds" "$milliseconds" + sleep "$spinner_delay" + done + done + ) & + local spinner_pid=$! + + wait "$pid" + local exit_status=$? + + kill "$spinner_pid" 2>/dev/null + wait "$spinner_pid" 2>/dev/null + + local end_time total_elapsed total_sec total_ms end_clock_time + end_time=$(date +%s%3N) + total_elapsed=$((end_time - start_time)) + total_sec=$((total_elapsed / 1000)) + total_ms=$((total_elapsed % 1000)) + end_clock_time=$(date +%T) + + echo -e "\r${GREEN}โœ… Completed at ${end_clock_time}, total: ${total_sec}.${total_ms}s${RESET} " + + return $exit_status +} diff --git a/other/example/configuration.nix b/other/example/configuration.nix new file mode 100644 index 0000000..ad897b8 --- /dev/null +++ b/other/example/configuration.nix @@ -0,0 +1,37 @@ +{ config, pkgs, host, lib, inputs, userconf, ... }: + +let + username = "YOUR_USER"; + nixDirectory = "/home/${username}/NixOS"; +in { + ################################################################ + # Module Imports + ################################################################ + + imports = [ + # Home Manager integration + inputs.home-manager.nixosModules.home-manager + ]; + + ################################################################ + # Home Manager Configuration + ################################################################ + +home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + backupFileExtension = "delme-HMbackup"; + users.${username} = import ./home.nix; + + extraSpecialArgs = { + inherit inputs nixDirectory username; + }; +}; + ################################################################ + # System Version + ################################################################ + + system.stateVersion = "25.05"; + + # ... Add more +} diff --git a/other/example/flake.nix b/other/example/flake.nix new file mode 100644 index 0000000..7b57c9a --- /dev/null +++ b/other/example/flake.nix @@ -0,0 +1,30 @@ +{ + description = "EXAMPLE-flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + nyx.url = "github:Peritia-System/Nyx-Tools"; + }; + outputs = inputs @ { + nixpkgs, + home-manager, + nyx, + ... + }: { + nixosConfigurations = { + default = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = { + inherit inputs self; + host = "default"; + }; + modules = [ + ./Configurations/Hosts/Default/configuration.nix + # No need to include nyx here + ]; + }; + }; + }; +} diff --git a/EXAMPLE_home.nix b/other/example/home.nix similarity index 51% rename from EXAMPLE_home.nix rename to other/example/home.nix index 15fa400..f648b86 100644 --- a/EXAMPLE_home.nix +++ b/other/example/home.nix @@ -1,11 +1,5 @@ -```nix +{ config, nixDirectory, username, pkgs, inputs, ... }: -{ config, nixDirectory, pkgs, ... }: - -let - nixDirectory = "/home/${username}/NixOS"; - -in { ################################################################ @@ -13,42 +7,47 @@ in ################################################################ imports = [ - # Nyx Tools - /home/${username}/NixOS/Nyx-Tools - + # Other Home Manager Modules + # ...... + inputs.nyx.homeManagerModules.default ]; - ################################################################ # Nyx Tools Configuration ################################################################ - modules.nyx-rebuild = { + nyx.nyx-rebuild = { enable = true; inherit username nixDirectory; editor = "nvim"; formatter = "alejandra"; enableAlias = false; - autoPush = false; - enableFormatting = false; + autoPushLog = false; + autoPushNixDir = false; startEditor = false; + logDir = "/home/${username}/.nyx/nyx-rebuild/logs"; }; - - modules.nyx-cleanup = { + + nyx.nyx-cleanup = { enable = true; inherit username nixDirectory; autoPush = false; keepGenerations = 5; enableAlias = false; + logDir = "/home/${username}/.nyx/nyx-rebuild/logs"; }; - - - modules.nix-tool = { + + nyx.nyx-tool = { enable = true; inherit nixDirectory; }; + + ################################################################ + # Basic Home Manager Setup + ################################################################ + + home.username = username; + home.homeDirectory = "/home/${username}"; + home.stateVersion = "25.05"; } - - -``` \ No newline at end of file diff --git a/zsh/nyx-cleanup.zsh b/other/zsh/nyx-cleanup.zsh similarity index 89% rename from zsh/nyx-cleanup.zsh rename to other/zsh/nyx-cleanup.zsh index d95de89..0afb4d8 100644 --- a/zsh/nyx-cleanup.zsh +++ b/other/zsh/nyx-cleanup.zsh @@ -1,3 +1,12 @@ + # Extract cfg values into local variables + nix_dir="${cfg.nixDirectory}" + start_editor="${toString cfg.startEditor}" + enable_formatting="${toString cfg.enableFormatting}" + editor_cmd="${cfg.editor}" + formatter_cmd="${cfg.formatter}" + auto_push="${toString cfg.autoPush}" + source "${scriptTargetPath}" + function nyx-cleanup() { ##### ๐Ÿ› ๏ธ CONFIGURATION ##### local version="1.3.1" @@ -39,7 +48,7 @@ function nyx-cleanup() { ##### ๐Ÿ“˜ TOOL INFO ##### print_line - nix-tool "Nyx" "nyx-cleanup" "$version" \ + nyx-tool "Nyx" "nyx-cleanup" "$version" \ "Smart NixOS configuration cleanup" \ "by Peritia-System" \ "https://github.com/Peritia-System/Nyx-Tools" \ diff --git a/zsh/nyx-rebuild.zsh b/other/zsh/nyx-rebuild.zsh similarity index 99% rename from zsh/nyx-rebuild.zsh rename to other/zsh/nyx-rebuild.zsh index 076e9fa..5a74f3a 100644 --- a/zsh/nyx-rebuild.zsh +++ b/other/zsh/nyx-rebuild.zsh @@ -91,7 +91,7 @@ function nyx-rebuild() { #################### ๐Ÿ“˜ TOOL INFO #################### echo - nix-tool "Nyx" "nyx-rebuild" "$version" \ + nyx-tool "Nyx" "nyx-rebuild" "$version" \ "Smart NixOS configuration rebuilder" \ "by Peritia-System" \ "https://github.com/Peritia-System/Nyx-Tools" \ diff --git a/zsh/nyx-tool.zsh b/other/zsh/nyx-tool.zsh similarity index 97% rename from zsh/nyx-tool.zsh rename to other/zsh/nyx-tool.zsh index 7b97b5a..577dae0 100644 --- a/zsh/nyx-tool.zsh +++ b/other/zsh/nyx-tool.zsh @@ -1,7 +1,7 @@ #!/usr/bin/env zsh -# nix-tool: reusable metadata banner printer with Base16 theme -function nix-tool() { +# nyx-tool: reusable metadata banner printer with Base16 theme +function nyx-tool() { local logo="${1:-Nyx}" local name="${2:-nix-script}" local version="${3:-Version Unknown - Please Open Issue}" From 45588e12478ace2818e0159a73c77116cffa6a16 Mon Sep 17 00:00:00 2001 From: Peritia Date: Wed, 6 Aug 2025 09:38:59 +0200 Subject: [PATCH 2/2] update Readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 442a15d..66d3da7 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,11 @@ Nyx-Tools ```nix # home.nix +{ + config, + inputs, + ... +}: { imports = [ inputs.nyx.homeManagerModules.default