From e5842370066067b9234e54bb97cd8caeeaa8550b Mon Sep 17 00:00:00 2001 From: Peritia Date: Tue, 16 Sep 2025 15:59:17 +0200 Subject: [PATCH] feat: add new options for a new Script --- nyx/default.nix | 12 +++++++ nyx/nyx-rebuild.nix | 88 ++++++++++++++++++++++++++++++--------------- 2 files changed, 72 insertions(+), 28 deletions(-) diff --git a/nyx/default.nix b/nyx/default.nix index b4391b8..a29d1ed 100644 --- a/nyx/default.nix +++ b/nyx/default.nix @@ -25,6 +25,18 @@ with lib; description = "Directory for Nyx logs"; }; + autoStage = mkOption { + type = types.bool; + default = false; + description = "Automatically stage changes after rebuild/cleanup"; + }; + + autoCommit = mkOption { + type = types.bool; + default = false; + description = "Automatically commit changes after rebuild/cleanup"; + }; + autoPush = mkOption { type = types.bool; default = false; diff --git a/nyx/nyx-rebuild.nix b/nyx/nyx-rebuild.nix index 6967326..00cb0c5 100644 --- a/nyx/nyx-rebuild.nix +++ b/nyx/nyx-rebuild.nix @@ -4,46 +4,78 @@ let nyxCfg = config.nyx; cfg = nyxCfg."nyx-rebuild"; + # Function to put a file from lib/ into the Nix store + libFile = file: + builtins.toFile + (builtins.baseNameOf file) + (builtins.readFile ./bash/lib/${file}); + + # List of files you want to source + filesToSource = [ + "git.sh" + "logging.sh" + "sudo.sh" +# "nyx-rebuild-logic.sh" + ]; + + # Build sourcing lines dynamically + sourcingLines = + builtins.concatStringsSep "\n" + (map (f: "source ${libFile f}") filesToSource); + # Read template and inject values rebuiltScript = let - src = builtins.readFile ./bash/nyx-rebuild.sh; # uses @TOKENS@, not ${...} + src = builtins.readFile ./bash/nyx-rebuild.sh; in - builtins.replaceStrings - [ - "@NIX_DIR@" "@LOG_DIR@" "@START_EDITOR@" "@ENABLE_FORMATTING@" - "@EDITOR@" "@FORMATTER@" "@GIT_BIN@" "@NOM_BIN@" "@AUTO_PUSH@" "@VERSION@" - ] - [ - (toString nyxCfg.nixDirectory) - (toString nyxCfg.logDir) - (if cfg.startEditor then "true" else "false") - (if cfg.enableFormatting then "true" else "false") - cfg.editor - cfg.formatter - "${pkgs.git}/bin/git" - "${pkgs.nix-output-monitor}/bin/nom" - (if nyxCfg.autoPush then "true" else "false") - "1.2.0" - ] - src; + builtins.replaceStrings + [ + "@FLAKE_DIRECTORY@" + "@LOG_DIR@" + "@ENABLE_FORMATTING@" + "@FORMATTER@" + "@GIT_BIN@" + "@NOM_BIN@" + "@AUTO_STAGE@" + "@AUTO_COMMIT@" + "@AUTO_PUSH@" + "@VERSION@" + ] + [ + (toString nyxCfg.nixDirectory) + (toString nyxCfg.logDir) + (if cfg.enableFormatting then "true" else "false") + cfg.formatter + "${pkgs.git}/bin/git" + "${pkgs.nix-output-monitor}/bin/nom" + (if nyxCfg.autoStage then "true" else "false") + (if nyxCfg.autoCommit then "true" else "false") + (if nyxCfg.autoPush then "true" else "false") + "1.2.0" + ] + ( + "#!/usr/bin/env bash\n" + + "source_all () {\n" + + sourcingLines + + "\n}\n" + + src + ); + in { options.nyx."nyx-rebuild" = { - enable = lib.mkEnableOption "Enable nyx-rebuild script"; - - editor = lib.mkOption { type = lib.types.str; default = "nvim"; }; - formatter = lib.mkOption { type = lib.types.str; default = "alejandra"; }; - startEditor = lib.mkOption { type = lib.types.bool; default = false; }; - enableFormatting = lib.mkOption { type = lib.types.bool; default = false; }; - enableAlias = lib.mkOption { type = lib.types.bool; default = true; }; + enable = lib.mkEnableOption "Enable nyx-rebuild script"; + formatter = lib.mkOption { type = lib.types.str; default = "alejandra"; }; + enableFormatting = lib.mkOption { type = lib.types.bool; default = false; }; + enableAlias = lib.mkOption { type = lib.types.bool; default = true; }; }; config = lib.mkIf (nyxCfg.enable && cfg.enable) { environment.systemPackages = - lib.optionals (cfg.enableFormatting && cfg.formatter == "alejandra") [ pkgs.alejandra ] + lib.optionals (cfg.enableFormatting && cfg.formatter == "alejandra") [ + pkgs.alejandra + ] ++ [ - # Ensure nyx-tool exists if you call it in the script (pkgs.writeShellScriptBin "nyx-rebuild" rebuiltScript) ];